MM-42581: fixes unread threads on user channel add (#20181)
* MM-42581: fixes unread threads on user channel add Currently when we are adding a user to a channel we don't send previous values for unread replies and mentions. This is resulting the thread to not be marked as unread in the UI, since we rely on the previous values for that. This commit fixes the issue by returning previous unread values of 0. * Adds test Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
@@ -3077,9 +3077,14 @@ func TestAddChannelMemberFromThread(t *testing.T) {
|
||||
_, _, err := th.SystemAdminClient.AddTeamMember(team.Id, user3.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
wsClient, err2 := th.CreateWebSocketClient()
|
||||
require.NoError(t, err2)
|
||||
defer wsClient.Close()
|
||||
wsClient.Listen()
|
||||
|
||||
publicChannel := th.CreatePublicChannel()
|
||||
|
||||
_, resp, err := th.Client.AddChannelMember(publicChannel.Id, user.Id)
|
||||
_, resp, err := th.Client.AddChannelMember(publicChannel.Id, user3.Id)
|
||||
require.NoError(t, err)
|
||||
CheckCreatedStatus(t, resp)
|
||||
_, resp, err = th.Client.AddChannelMember(publicChannel.Id, user2.Id)
|
||||
@@ -3089,7 +3094,7 @@ func TestAddChannelMemberFromThread(t *testing.T) {
|
||||
post := &model.Post{
|
||||
ChannelId: publicChannel.Id,
|
||||
Message: "A root post",
|
||||
UserId: user.Id,
|
||||
UserId: user3.Id,
|
||||
}
|
||||
rpost, _, err := th.SystemAdminClient.CreatePost(post)
|
||||
require.NoError(t, err)
|
||||
@@ -3097,7 +3102,7 @@ func TestAddChannelMemberFromThread(t *testing.T) {
|
||||
_, _, err = th.SystemAdminClient.CreatePost(
|
||||
&model.Post{
|
||||
ChannelId: publicChannel.Id,
|
||||
Message: "A reply post with mention @" + user3.Username,
|
||||
Message: "A reply post with mention @" + user.Username,
|
||||
UserId: user2.Id,
|
||||
RootId: rpost.Id,
|
||||
})
|
||||
@@ -3106,22 +3111,46 @@ func TestAddChannelMemberFromThread(t *testing.T) {
|
||||
_, _, err = th.SystemAdminClient.CreatePost(
|
||||
&model.Post{
|
||||
ChannelId: publicChannel.Id,
|
||||
Message: "Another reply post with mention @" + user3.Username,
|
||||
Message: "Another reply post with mention @" + user.Username,
|
||||
UserId: user2.Id,
|
||||
RootId: rpost.Id,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Simulate adding a user to a channel from a thread
|
||||
_, _, err = th.SystemAdminClient.AddChannelMemberWithRootId(publicChannel.Id, user3.Id, rpost.Id)
|
||||
_, _, err = th.SystemAdminClient.AddChannelMemberWithRootId(publicChannel.Id, user.Id, rpost.Id)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Threadmembership should exist for added user
|
||||
ut, _, err := th.SystemAdminClient.GetUserThread(user3.Id, team.Id, rpost.Id, false)
|
||||
ut, _, err := th.Client.GetUserThread(user.Id, team.Id, rpost.Id, false)
|
||||
require.NoError(t, err)
|
||||
// Should have two mentions. There might be a race condition
|
||||
// here between the "added user to the channel" message and the GetUserThread call
|
||||
require.LessOrEqual(t, int64(2), ut.UnreadMentions)
|
||||
|
||||
var caught bool
|
||||
func() {
|
||||
for {
|
||||
select {
|
||||
case ev := <-wsClient.EventChannel:
|
||||
if ev.EventType() == model.WebsocketEventThreadUpdated {
|
||||
caught = true
|
||||
var thread model.ThreadResponse
|
||||
data := ev.GetData()
|
||||
jsonErr := json.Unmarshal([]byte(data["thread"].(string)), &thread)
|
||||
|
||||
require.NoError(t, jsonErr)
|
||||
require.EqualValues(t, int64(2), thread.UnreadReplies)
|
||||
require.EqualValues(t, int64(2), thread.UnreadMentions)
|
||||
require.EqualValues(t, float64(0), data["previous_unread_replies"])
|
||||
require.EqualValues(t, float64(0), data["previous_unread_mentions"])
|
||||
}
|
||||
case <-time.After(1 * time.Second):
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
require.Truef(t, caught, "User should have received %s event", model.WebsocketEventThreadUpdated)
|
||||
}
|
||||
|
||||
func TestAddChannelMemberAddMyself(t *testing.T) {
|
||||
|
||||
@@ -2489,6 +2489,8 @@ func (a *App) UpdateThreadFollowForUserFromChannelAdd(userID, teamID, threadID s
|
||||
mlog.Warn("Failed to encode thread to JSON")
|
||||
}
|
||||
message.Add("thread", string(payload))
|
||||
message.Add("previous_unread_replies", int64(0))
|
||||
message.Add("previous_unread_mentions", int64(0))
|
||||
|
||||
a.Publish(message)
|
||||
return nil
|
||||
|
||||
Ссылка в новой задаче
Block a user