Refactor: func StringInSlice to slices.Contains (#24262)
* Refactor: Use generic to change func StringInSlice to Contains * Refactor: Use generic to change func stringNotInSlice to Contains Make utils.go (dir server/public/utils) and func Contains * Refactor: Move func Contains from channels/utils to public/utils Move func Contains from channels/utils to public/utils Fix import declarations line * Docs: Add a description of the Contains function * Test: add TestContains Add a test code for a Contain function
Этот коммит содержится в:
@@ -13,8 +13,9 @@ 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/store"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/utils"
|
||||
)
|
||||
|
||||
func getLicWithSkuShortName(skuShortName string) *model.License {
|
||||
@@ -49,7 +50,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, utils.StringInSlice(th.BasicUser2.Id, mentions), "mentions", mentions)
|
||||
require.True(t, pUtils.Contains(mentions, th.BasicUser2.Id), "mentions", mentions)
|
||||
|
||||
t.Run("license is required for group mention", func(t *testing.T) {
|
||||
group := th.CreateGroup()
|
||||
@@ -145,7 +146,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, utils.StringInSlice(user.Id, mentions))
|
||||
require.False(t, pUtils.Contains(mentions, user.Id))
|
||||
}
|
||||
|
||||
th.BasicUser.NotifyProps[model.CommentsNotifyProp] = model.CommentsNotifyAny
|
||||
@@ -2815,7 +2816,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, utils.StringInSlice(user.Id, mentions))
|
||||
assert.False(t, pUtils.Contains(mentions, user.Id))
|
||||
|
||||
membership, err := th.App.GetThreadMembershipForUser(user.Id, rootPost.Id)
|
||||
assert.Error(t, err)
|
||||
|
||||
Ссылка в новой задаче
Block a user