From ca8aea9a06a5aebdbc73991c5c8d065e57f68f95 Mon Sep 17 00:00:00 2001 From: Michel Engelen <32863416+michelengelen@users.noreply.github.com> Date: Mon, 11 Apr 2022 18:43:14 +0200 Subject: [PATCH] [MM-41993]: fixed counting thread mentions in unread root post (#19874) * removed appending the root post to the posts list also changed `UpdateAt` to `CreateAt` in thread_store.go in accordance with kyriakos * fixed failing test after latest change Co-authored-by: Mattermod --- api4/user_test.go | 11 ++++++++--- app/post.go | 1 - store/sqlstore/thread_store.go | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/api4/user_test.go b/api4/user_test.go index e8485217ae..fc5affd365 100644 --- a/api4/user_test.go +++ b/api4/user_test.go @@ -6522,8 +6522,8 @@ func TestMarkThreadUnreadMentionCount(t *testing.T) { require.Nil(t, appErr) rpost, _ := postAndCheck(t, client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsg @" + th.BasicUser2.Username}) - reply, _ := postAndCheck(t, client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testReply1", RootId: rpost.Id}) - postAndCheck(t, client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testReply2", RootId: rpost.Id}) + reply1, _ := postAndCheck(t, client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testReply1 @" + th.BasicUser2.Username, RootId: rpost.Id}) + reply2, _ := postAndCheck(t, client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testReply2", RootId: rpost.Id}) th.SystemAdminClient.UpdateThreadReadForUser(th.BasicUser2.Id, th.BasicTeam.Id, rpost.Id, model.GetMillis()) @@ -6535,7 +6535,12 @@ func TestMarkThreadUnreadMentionCount(t *testing.T) { u, _, _ = th.SystemAdminClient.GetUserThreads(th.BasicUser2.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{}) require.EqualValues(t, 1, u.TotalUnreadMentions) - th.SystemAdminClient.UpdateThreadReadForUser(th.BasicUser2.Id, th.BasicTeam.Id, rpost.Id, reply.CreateAt) + th.SystemAdminClient.UpdateThreadReadForUser(th.BasicUser2.Id, th.BasicTeam.Id, rpost.Id, reply1.CreateAt) + + u, _, _ = th.SystemAdminClient.GetUserThreads(th.BasicUser2.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{}) + require.EqualValues(t, 1, u.TotalUnreadMentions) + + th.SystemAdminClient.UpdateThreadReadForUser(th.BasicUser2.Id, th.BasicTeam.Id, rpost.Id, reply2.CreateAt) u, _, _ = th.SystemAdminClient.GetUserThreads(th.BasicUser2.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{}) require.EqualValues(t, 0, u.TotalUnreadMentions) diff --git a/app/post.go b/app/post.go index 508ca43548..3aedc95953 100644 --- a/app/post.go +++ b/app/post.go @@ -1502,7 +1502,6 @@ func (a *App) countThreadMentions(user *model.User, post *model.Post, teamID str if nErr != nil { return 0, model.NewAppError("countMentionsFromPost", "app.channel.count_posts_since.app_error", nil, nErr.Error(), http.StatusInternalServerError) } - posts = append(posts, post) for _, p := range posts { if p.CreateAt >= timestamp { diff --git a/store/sqlstore/thread_store.go b/store/sqlstore/thread_store.go index 44066fed85..bd6511cfea 100644 --- a/store/sqlstore/thread_store.go +++ b/store/sqlstore/thread_store.go @@ -890,7 +890,7 @@ func (s *SqlThreadStore) GetPosts(threadId string, since int64) ([]*model.Post, From("Posts"). Where(sq.Eq{"RootId": threadId}). Where(sq.Eq{"DeleteAt": 0}). - Where(sq.GtOrEq{"UpdateAt": since}).ToSql() + Where(sq.GtOrEq{"CreateAt": since}).ToSql() if err != nil { return nil, errors.Wrap(err, "failed to build query to fetch thread posts") }