[MM-57356] Make use of go1.21 features (#26620)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3c45c44cb1
Коммит
1e0de8f559
@@ -8,13 +8,13 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
pUtils "github.com/mattermost/mattermost/server/public/utils"
|
||||
|
||||
"github.com/mattermost/mattermost/server/v8/channels/app"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/audit"
|
||||
@@ -726,7 +726,7 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.SetInvalidParam("role")
|
||||
return
|
||||
}
|
||||
roleValid := pUtils.Contains(roleNamesAll, role)
|
||||
roleValid := slices.Contains(roleNamesAll, role)
|
||||
if !roleValid {
|
||||
c.SetInvalidParam("role")
|
||||
return
|
||||
|
||||
@@ -6,12 +6,12 @@ package api4
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
pUtils "github.com/mattermost/mattermost/server/public/utils"
|
||||
|
||||
"github.com/mattermost/mattermost/server/v8/channels/audit"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
@@ -87,7 +87,7 @@ func localGetUsers(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.SetInvalidParam("role")
|
||||
return
|
||||
}
|
||||
roleValid := pUtils.Contains(roleNamesAll, role)
|
||||
roleValid := slices.Contains(roleNamesAll, role)
|
||||
if !roleValid {
|
||||
c.SetInvalidParam("role")
|
||||
return
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost/server/v8/channels/utils"
|
||||
@@ -18,7 +19,6 @@ import (
|
||||
"github.com/mattermost/mattermost/server/public/shared/i18n"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
pUtils "github.com/mattermost/mattermost/server/public/utils"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store/sqlstore"
|
||||
)
|
||||
@@ -1036,7 +1036,7 @@ func (a *App) PatchChannelModerationsForChannel(c request.CTX, channel *model.Ch
|
||||
|
||||
for _, channelModerationPatch := range channelModerationsPatch {
|
||||
permissionModified := *channelModerationPatch.Name
|
||||
if channelModerationPatch.Roles.Guests != nil && pUtils.Contains(model.ChannelModeratedPermissionsChangedByPatch(guestRole, guestRolePatch), permissionModified) {
|
||||
if channelModerationPatch.Roles.Guests != nil && slices.Contains(model.ChannelModeratedPermissionsChangedByPatch(guestRole, guestRolePatch), permissionModified) {
|
||||
if *channelModerationPatch.Roles.Guests {
|
||||
c.Logger().Info("Permission enabled for guests.", mlog.String("permission", permissionModified), mlog.String("channel_id", channel.Id), mlog.String("channel_name", channel.Name))
|
||||
} else {
|
||||
@@ -1044,7 +1044,7 @@ func (a *App) PatchChannelModerationsForChannel(c request.CTX, channel *model.Ch
|
||||
}
|
||||
}
|
||||
|
||||
if channelModerationPatch.Roles.Members != nil && pUtils.Contains(model.ChannelModeratedPermissionsChangedByPatch(memberRole, memberRolePatch), permissionModified) {
|
||||
if channelModerationPatch.Roles.Members != nil && slices.Contains(model.ChannelModeratedPermissionsChangedByPatch(memberRole, memberRolePatch), permissionModified) {
|
||||
if *channelModerationPatch.Roles.Members {
|
||||
c.Logger().Info("Permission enabled for members.", mlog.String("permission", permissionModified), mlog.String("channel_id", channel.Id), mlog.String("channel_name", channel.Name))
|
||||
} else {
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"slices"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -17,7 +18,6 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/i18n"
|
||||
pUtils "github.com/mattermost/mattermost/server/public/utils"
|
||||
|
||||
"github.com/mattermost/mattermost/server/v8/channels/app/platform"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
@@ -56,7 +56,7 @@ func TestSendNotifications(t *testing.T) {
|
||||
mentions, err := th.App.SendNotifications(th.Context, post1, th.BasicTeam, th.BasicChannel, th.BasicUser, nil, true)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, mentions)
|
||||
require.True(t, pUtils.Contains(mentions, th.BasicUser2.Id), "mentions", mentions)
|
||||
require.True(t, slices.Contains(mentions, th.BasicUser2.Id), "mentions", mentions)
|
||||
})
|
||||
|
||||
t.Run("license is required for group mention", func(t *testing.T) {
|
||||
@@ -197,7 +197,7 @@ func TestSendNotifications(t *testing.T) {
|
||||
}
|
||||
mentions, err := th.App.SendNotifications(th.Context, childPost, th.BasicTeam, th.BasicChannel, th.BasicUser2, &postList, true)
|
||||
require.NoError(t, err)
|
||||
require.False(t, pUtils.Contains(mentions, user.Id))
|
||||
require.False(t, slices.Contains(mentions, user.Id))
|
||||
}
|
||||
|
||||
var appErr *model.AppError
|
||||
@@ -2831,7 +2831,7 @@ func TestReplyPostNotificationsWithCRT(t *testing.T) {
|
||||
}
|
||||
mentions, err := th.App.SendNotifications(th.Context, childPost, th.BasicTeam, th.BasicChannel, th.BasicUser2, &postList, true)
|
||||
require.NoError(t, err)
|
||||
assert.False(t, pUtils.Contains(mentions, user.Id))
|
||||
assert.False(t, slices.Contains(mentions, user.Id))
|
||||
|
||||
membership, err := th.App.GetThreadMembershipForUser(user.Id, rootPost.Id)
|
||||
assert.Error(t, err)
|
||||
|
||||
@@ -6,12 +6,12 @@ package platform
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/public/utils"
|
||||
"github.com/mattermost/mattermost/server/v8/platform/services/sharedchannel"
|
||||
)
|
||||
|
||||
@@ -59,7 +59,7 @@ func (ps *PlatformService) SharedChannelSyncHandler(event *model.WebSocketEvent)
|
||||
func isEligibleForEvents(syncService SharedChannelServiceIFace, event *model.WebSocketEvent, events []model.WebsocketEventType) bool {
|
||||
return syncServiceEnabled(syncService) &&
|
||||
eventHasChannel(event) &&
|
||||
utils.Contains(events, event.EventType())
|
||||
slices.Contains(events, event.EventType())
|
||||
}
|
||||
|
||||
func eventHasChannel(event *model.WebSocketEvent) bool {
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -25,7 +26,6 @@ import (
|
||||
"github.com/mattermost/mattermost/server/public/shared/i18n"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/public/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -877,7 +877,7 @@ func (wc *WebConn) ShouldSendEvent(msg *model.WebSocketEvent) bool {
|
||||
// For typing events, we don't send them to users who don't have
|
||||
// that channel or thread opened.
|
||||
if wc.Platform.Config().FeatureFlags.WebSocketEventScope &&
|
||||
utils.Contains([]model.WebsocketEventType{
|
||||
slices.Contains([]model.WebsocketEventType{
|
||||
model.WebsocketEventTyping,
|
||||
model.WebsocketEventReactionAdded,
|
||||
model.WebsocketEventReactionRemoved,
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/crypto/openpgp" //nolint:staticcheck
|
||||
@@ -15,7 +16,6 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
pUtils "github.com/mattermost/mattermost/server/public/utils"
|
||||
|
||||
"github.com/mattermost/mattermost/server/v8/channels/utils"
|
||||
)
|
||||
@@ -48,7 +48,7 @@ func (a *App) AddPublicKey(name string, key io.Reader) *model.AppError {
|
||||
}
|
||||
|
||||
a.UpdateConfig(func(cfg *model.Config) {
|
||||
if !pUtils.Contains(cfg.PluginSettings.SignaturePublicKeyFiles, name) {
|
||||
if !slices.Contains(cfg.PluginSettings.SignaturePublicKeyFiles, name) {
|
||||
cfg.PluginSettings.SignaturePublicKeyFiles = append(cfg.PluginSettings.SignaturePublicKeyFiles, name)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -9,10 +9,10 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
pUtils "github.com/mattermost/mattermost/server/public/utils"
|
||||
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/utils"
|
||||
@@ -189,13 +189,13 @@ func (a *App) UpdateRole(role *model.Role) (*model.Role, *model.AppError) {
|
||||
|
||||
builtInRolesMinusChannelRoles := append(utils.RemoveStringsFromSlice(model.BuiltInSchemeManagedRoleIDs, builtInChannelRoles...), model.NewSystemRoleIDs...)
|
||||
|
||||
if pUtils.Contains(builtInRolesMinusChannelRoles, savedRole.Name) {
|
||||
if slices.Contains(builtInRolesMinusChannelRoles, savedRole.Name) {
|
||||
return savedRole, nil
|
||||
}
|
||||
|
||||
var roleRetrievalFunc func() ([]*model.Role, *model.AppError)
|
||||
|
||||
if pUtils.Contains(builtInChannelRoles, savedRole.Name) {
|
||||
if slices.Contains(builtInChannelRoles, savedRole.Name) {
|
||||
roleRetrievalFunc = func() ([]*model.Role, *model.AppError) {
|
||||
roles, nErr := a.Srv().Store().Role().AllChannelSchemeRoles()
|
||||
if nErr != nil {
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"encoding/csv"
|
||||
"io"
|
||||
"os"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -15,7 +16,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
pUtils "github.com/mattermost/mattermost/server/public/utils"
|
||||
)
|
||||
|
||||
type permissionInheritanceTestData struct {
|
||||
@@ -37,7 +37,7 @@ func TestGetRolesByNames(t *testing.T) {
|
||||
require.NotNil(t, actualRole)
|
||||
require.Equal(t, testData.channelRole.Name, actualRole.Name)
|
||||
|
||||
require.Equal(t, testData.shouldHavePermission, pUtils.Contains(actualRole.Permissions, testData.permission.Id))
|
||||
require.Equal(t, testData.shouldHavePermission, slices.Contains(actualRole.Permissions, testData.permission.Id))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ func TestGetRoleByName(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, actualRole)
|
||||
require.Equal(t, testData.channelRole.Name, actualRole.Name)
|
||||
require.Equal(t, testData.shouldHavePermission, pUtils.Contains(actualRole.Permissions, testData.permission.Id), "row: %+v", testData.truthTableRow)
|
||||
require.Equal(t, testData.shouldHavePermission, slices.Contains(actualRole.Permissions, testData.permission.Id), "row: %+v", testData.truthTableRow)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func TestGetRoleByID(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, actualRole)
|
||||
require.Equal(t, testData.channelRole.Id, actualRole.Id)
|
||||
require.Equal(t, testData.shouldHavePermission, pUtils.Contains(actualRole.Permissions, testData.permission.Id), "row: %+v", testData.truthTableRow)
|
||||
require.Equal(t, testData.shouldHavePermission, slices.Contains(actualRole.Permissions, testData.permission.Id), "row: %+v", testData.truthTableRow)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ func TestGetAllRoles(t *testing.T) {
|
||||
if actualRole.Id == testData.channelRole.Id {
|
||||
require.NotNil(t, actualRole)
|
||||
require.Equal(t, testData.channelRole.Id, actualRole.Id)
|
||||
require.Equal(t, testData.shouldHavePermission, pUtils.Contains(actualRole.Permissions, testData.permission.Id), "row: %+v", testData.truthTableRow)
|
||||
require.Equal(t, testData.shouldHavePermission, slices.Contains(actualRole.Permissions, testData.permission.Id), "row: %+v", testData.truthTableRow)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"slices"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -419,7 +420,7 @@ func TestSessionsLimit(t *testing.T) {
|
||||
require.Equal(t, maxSessionsLimit, len(gotSessions), "should have maxSessionsLimit number of sessions")
|
||||
|
||||
// Ensure we are retrieving the same sessions.
|
||||
reverse(gotSessions)
|
||||
slices.Reverse(gotSessions)
|
||||
for i, sess := range gotSessions {
|
||||
require.Equal(t, sessions[i].Id, sess.Id)
|
||||
}
|
||||
@@ -440,15 +441,8 @@ func TestSessionsLimit(t *testing.T) {
|
||||
require.Equal(t, maxSessionsLimit, len(gotSessions), "should have maxSessionsLimit number of sessions")
|
||||
|
||||
// Ensure the the oldest sessions were removed first.
|
||||
reverse(gotSessions)
|
||||
slices.Reverse(gotSessions)
|
||||
for i, sess := range gotSessions {
|
||||
require.Equal(t, sessions[i].Id, sess.Id)
|
||||
}
|
||||
}
|
||||
|
||||
// reverse can be replaced by the slices version when we move to 1.21+
|
||||
func reverse[S ~[]E, E any](s S) {
|
||||
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,11 +159,3 @@ func getBrowserName(ua *uasurfer.UserAgent, userAgentString string) string {
|
||||
|
||||
return browserNames[uasurfer.BrowserUnknown]
|
||||
}
|
||||
|
||||
// min should be replaced by to go 1.21 built-in generic function, see MM-57356.
|
||||
func min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ package app
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
pUtils "github.com/mattermost/mattermost/server/public/utils"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/app/platform"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@@ -33,7 +33,7 @@ func (h *addMentionsBroadcastHook) Process(msg *platform.HookedWebSocketEvent, w
|
||||
return errors.Wrap(err, "Invalid mentions value passed to addMentionsBroadcastHook")
|
||||
}
|
||||
|
||||
if len(mentions) > 0 && pUtils.Contains[string](mentions, webConn.UserId) {
|
||||
if len(mentions) > 0 && slices.Contains(mentions, webConn.UserId) {
|
||||
// Note that the client expects this field to be stringified
|
||||
msg.Add("mentions", model.ArrayToJSON([]string{webConn.UserId}))
|
||||
}
|
||||
@@ -55,7 +55,7 @@ func (h *addFollowersBroadcastHook) Process(msg *platform.HookedWebSocketEvent,
|
||||
return errors.Wrap(err, "Invalid followers value passed to addFollowersBroadcastHook")
|
||||
}
|
||||
|
||||
if len(followers) > 0 && pUtils.Contains[string](followers, webConn.UserId) {
|
||||
if len(followers) > 0 && slices.Contains(followers, webConn.UserId) {
|
||||
// Note that the client expects this field to be stringified
|
||||
msg.Add("followers", model.ArrayToJSON([]string{webConn.UserId}))
|
||||
}
|
||||
|
||||
@@ -4,10 +4,9 @@
|
||||
package searchtest
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
pUtils "github.com/mattermost/mattermost/server/public/utils"
|
||||
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
)
|
||||
|
||||
@@ -36,12 +35,12 @@ type searchTest struct {
|
||||
func filterTestsByTag(tests []searchTest, tags ...string) []searchTest {
|
||||
filteredTests := []searchTest{}
|
||||
for _, test := range tests {
|
||||
if pUtils.Contains(test.Tags, EngineAll) {
|
||||
if slices.Contains(test.Tags, EngineAll) {
|
||||
filteredTests = append(filteredTests, test)
|
||||
continue
|
||||
}
|
||||
for _, tag := range tags {
|
||||
if pUtils.Contains(test.Tags, tag) {
|
||||
if slices.Contains(test.Tags, tag) {
|
||||
filteredTests = append(filteredTests, test)
|
||||
break
|
||||
}
|
||||
|
||||
@@ -4,15 +4,15 @@
|
||||
package sqlstore
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"strconv"
|
||||
|
||||
sq "github.com/mattermost/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/utils"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type SqlChannelBookmarkStore struct {
|
||||
@@ -262,7 +262,7 @@ func (s *SqlChannelBookmarkStore) UpdateSortOrder(bookmarkId, channelId string,
|
||||
}
|
||||
|
||||
bookmarks = utils.RemoveElementFromSliceAtIndex(bookmarks, currentIndex)
|
||||
bookmarks = utils.InsertElementToSliceAtIndex(bookmarks, current, int(newIndex))
|
||||
bookmarks = slices.Insert(bookmarks, int(newIndex), current)
|
||||
caseStmt := sq.Case()
|
||||
query := s.getQueryBuilder().
|
||||
Update("ChannelBookmarks")
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -17,7 +18,6 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
pUtils "github.com/mattermost/mattermost/server/public/utils"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
)
|
||||
|
||||
@@ -4826,7 +4826,7 @@ func groupTestpUpdateMembersRoleTeam(t *testing.T, rctx request.CTX, ss store.St
|
||||
require.GreaterOrEqual(t, len(members), 4) // sanity check for team membership
|
||||
|
||||
for _, member := range members {
|
||||
if pUtils.Contains(tt.inUserIDs, member.UserId) {
|
||||
if slices.Contains(tt.inUserIDs, member.UserId) {
|
||||
require.True(t, member.SchemeAdmin)
|
||||
} else {
|
||||
require.False(t, member.SchemeAdmin)
|
||||
@@ -4936,7 +4936,7 @@ func groupTestpUpdateMembersRoleChannel(t *testing.T, rctx request.CTX, ss store
|
||||
require.GreaterOrEqual(t, len(members), 4) // sanity check for channel membership
|
||||
|
||||
for _, member := range members {
|
||||
if pUtils.Contains(tt.inUserIDs, member.UserId) {
|
||||
if slices.Contains(tt.inUserIDs, member.UserId) {
|
||||
require.True(t, member.SchemeAdmin)
|
||||
} else {
|
||||
require.False(t, member.SchemeAdmin)
|
||||
|
||||
@@ -12,11 +12,11 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/i18n"
|
||||
"github.com/mattermost/mattermost/server/public/utils"
|
||||
)
|
||||
|
||||
func CheckOrigin(r *http.Request, allowedOrigins string) bool {
|
||||
@@ -114,7 +114,7 @@ func RenderMobileAuthComplete(w http.ResponseWriter, redirectURL string) {
|
||||
func RenderMobileError(config *model.Config, w http.ResponseWriter, err *model.AppError, redirectURL string) {
|
||||
var link = template.HTMLEscapeString(redirectURL)
|
||||
u, redirectErr := url.Parse(redirectURL)
|
||||
if redirectErr != nil || !utils.Contains(config.NativeAppSettings.AppCustomURLSchemes, u.Scheme) {
|
||||
if redirectErr != nil || !slices.Contains(config.NativeAppSettings.AppCustomURLSchemes, u.Scheme) {
|
||||
link = *config.ServiceSettings.SiteURL
|
||||
}
|
||||
RenderMobileMessage(w, `
|
||||
|
||||
@@ -9,12 +9,12 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
pUtils "github.com/mattermost/mattermost/server/public/utils"
|
||||
)
|
||||
|
||||
// RemoveStringFromSlice removes the first occurrence of a from slice.
|
||||
@@ -32,7 +32,7 @@ func RemoveStringsFromSlice(slice []string, strings ...string) []string {
|
||||
newSlice := []string{}
|
||||
|
||||
for _, item := range slice {
|
||||
if !pUtils.Contains(strings, item) {
|
||||
if !slices.Contains(strings, item) {
|
||||
newSlice = append(newSlice, item)
|
||||
}
|
||||
}
|
||||
@@ -87,17 +87,8 @@ func StringSliceDiff(a, b []string) []string {
|
||||
return result
|
||||
}
|
||||
|
||||
func InsertElementToSliceAtIndex[T comparable](slice []T, element T, index int) []T {
|
||||
if len(slice) == index {
|
||||
return append(slice, element)
|
||||
}
|
||||
slice = append(slice[:index+1], slice[index:]...)
|
||||
slice[index] = element
|
||||
return slice
|
||||
}
|
||||
|
||||
func RemoveElementFromSliceAtIndex[T comparable](slice []T, index int) []T {
|
||||
return append(slice[:index], slice[index+1:]...)
|
||||
func RemoveElementFromSliceAtIndex[S ~[]E, E any](slice S, index int) S {
|
||||
return slices.Delete(slice, index, index+1)
|
||||
}
|
||||
|
||||
func GetIPAddress(r *http.Request, trustedProxyIPHeader []string) string {
|
||||
@@ -252,24 +243,11 @@ func RoundOffToZeroes(n float64) int64 {
|
||||
return firstDigit * tens
|
||||
}
|
||||
|
||||
func MinInt(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
func MaxInt(a, b int) int {
|
||||
if a > b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// RoundOffToZeroesResolution truncates off at most minResolution zero places.
|
||||
// It implicitly sets the lowest minResolution to 0.
|
||||
// e.g. 0 reports 1s, 1 reports 10s, 2 reports 100s, 3 reports 1000s
|
||||
func RoundOffToZeroesResolution(n float64, minResolution int) int64 {
|
||||
resolution := MaxInt(0, minResolution)
|
||||
resolution := max(0, minResolution)
|
||||
if n >= -9 && n <= 9 {
|
||||
if resolution == 0 {
|
||||
return int64(n)
|
||||
@@ -278,7 +256,7 @@ func RoundOffToZeroesResolution(n float64, minResolution int) int64 {
|
||||
}
|
||||
|
||||
zeroes := int(math.Log10(math.Abs(n)))
|
||||
resolution = MinInt(zeroes, resolution)
|
||||
resolution = min(zeroes, resolution)
|
||||
tens := int64(math.Pow10(resolution))
|
||||
significantDigits := int64(n) / tens
|
||||
return significantDigits * tens
|
||||
|
||||
Ссылка в новой задаче
Block a user