MM-35127 CRT: Marking thread as unread doesn't set the timestamp correctly (#17507)

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Eli Yukelzon
2021-04-27 15:48:43 +03:00
коммит произвёл GitHub
родитель f73c77611f
Коммит 89281c00b1
2 изменённых файлов: 47 добавлений и 10 удалений

Просмотреть файл

@@ -5964,6 +5964,47 @@ func TestReadThreads(t *testing.T) {
})
}
func TestMarkThreadUnreadMentionCount(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
os.Setenv("MM_FEATUREFLAGS_COLLAPSEDTHREADS", "true")
defer os.Unsetenv("MM_FEATUREFLAGS_COLLAPSEDTHREADS")
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.ThreadAutoFollow = true
*cfg.ServiceSettings.CollapsedThreads = model.COLLAPSED_THREADS_DEFAULT_ON
})
Client := th.Client
channel := th.BasicChannel
user := th.BasicUser
user2 := th.BasicUser2
appErr := th.App.JoinChannel(channel, user.Id)
require.Nil(t, appErr)
appErr = th.App.JoinChannel(channel, user2.Id)
require.Nil(t, appErr)
rpost, _ := postAndCheck(t, Client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsg @" + th.BasicUser2.Username})
time.Sleep(1)
reply, _ := postAndCheck(t, Client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testReply1", RootId: rpost.Id})
time.Sleep(1)
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())
u, _ := th.SystemAdminClient.GetUserThreads(th.BasicUser2.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{})
require.EqualValues(t, 0, u.TotalUnreadMentions)
th.SystemAdminClient.UpdateThreadReadForUser(th.BasicUser2.Id, th.BasicTeam.Id, rpost.Id, rpost.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, reply.CreateAt)
u, _ = th.SystemAdminClient.GetUserThreads(th.BasicUser2.Id, th.BasicTeam.Id, model.GetUserThreadsOpts{})
require.EqualValues(t, 0, u.TotalUnreadMentions)
}
func TestPatchAndUpdateWithProviderAttributes(t *testing.T) {
t.Run("LDAP user", func(t *testing.T) {
th := SetupEnterprise(t).InitBasic()

Просмотреть файл

@@ -1387,18 +1387,14 @@ 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)
}
mentions := getExplicitMentions(post, keywords, groups)
if post.UpdateAt >= timestamp {
if _, ok := mentions.Mentions[user.Id]; ok {
count += 1
}
}
posts = append(posts, post)
for _, p := range posts {
mentions = getExplicitMentions(p, keywords, groups)
if _, ok := mentions.Mentions[user.Id]; ok {
count += 1
if p.CreateAt >= timestamp {
mentions := getExplicitMentions(p, keywords, groups)
if _, ok := mentions.Mentions[user.Id]; ok {
count += 1
}
}
}