[MM-37933] Channel preference to auto-follow all threads in the channel (#21430)
* Add auto-follow feature --------- Co-authored-by: Mattermod <mattermod@users.noreply.github.com> Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost-server/server/v8/channels/store"
|
||||
"github.com/mattermost/mattermost-server/server/v8/channels/utils"
|
||||
"github.com/mattermost/mattermost-server/server/v8/model"
|
||||
"github.com/mattermost/mattermost-server/server/v8/platform/shared/i18n"
|
||||
@@ -2819,3 +2820,66 @@ func TestReplyPostNotificationsWithCRT(t *testing.T) {
|
||||
assert.Nil(t, membership)
|
||||
})
|
||||
}
|
||||
|
||||
func TestChannelAutoFollowThreads(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
u1 := th.BasicUser
|
||||
u2 := th.BasicUser2
|
||||
u3 := th.CreateUser()
|
||||
th.LinkUserToTeam(u3, th.BasicTeam)
|
||||
c1 := th.BasicChannel
|
||||
th.AddUserToChannel(u2, c1)
|
||||
th.AddUserToChannel(u3, c1)
|
||||
|
||||
// Set auto-follow for user 2
|
||||
member, appErr := th.App.UpdateChannelMemberNotifyProps(th.Context, map[string]string{model.ChannelAutoFollowThreads: model.ChannelAutoFollowThreadsOn}, c1.Id, u2.Id)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, model.ChannelAutoFollowThreadsOn, member.NotifyProps[model.ChannelAutoFollowThreads])
|
||||
|
||||
rootPost := &model.Post{
|
||||
ChannelId: c1.Id,
|
||||
Message: "root post by user3",
|
||||
UserId: u3.Id,
|
||||
}
|
||||
rpost, appErr := th.App.CreatePost(th.Context, rootPost, c1, false, true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
replyPost1 := &model.Post{
|
||||
ChannelId: c1.Id,
|
||||
Message: "reply post by user1",
|
||||
UserId: u1.Id,
|
||||
RootId: rpost.Id,
|
||||
}
|
||||
_, appErr = th.App.CreatePost(th.Context, replyPost1, c1, false, true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// user-2 starts auto-following thread
|
||||
threadMembership, appErr := th.App.GetThreadMembershipForUser(u2.Id, rpost.Id)
|
||||
require.Nil(t, appErr)
|
||||
require.NotNil(t, threadMembership)
|
||||
assert.True(t, threadMembership.Following)
|
||||
|
||||
// Set "following" to false
|
||||
_, err := th.App.Srv().Store().Thread().MaintainMembership(u2.Id, rpost.Id, store.ThreadMembershipOpts{
|
||||
Following: false,
|
||||
UpdateFollowing: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
replyPost2 := &model.Post{
|
||||
ChannelId: c1.Id,
|
||||
Message: "reply post 2 by user1",
|
||||
UserId: u1.Id,
|
||||
RootId: rpost.Id,
|
||||
}
|
||||
_, appErr = th.App.CreatePost(th.Context, replyPost2, c1, false, true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// Do NOT start auto-following thread, once "un-followed"
|
||||
threadMembership, appErr = th.App.GetThreadMembershipForUser(u2.Id, rpost.Id)
|
||||
require.Nil(t, appErr)
|
||||
require.NotNil(t, threadMembership)
|
||||
assert.False(t, threadMembership.Following)
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user