MM-17071 Add mention counting when marking a post as unread (#11966)
* Add different types for different mentions * Remove redundant THREAD_ANY and THREAD_ROOT constants * Make PostStore.Get return thread in order * MM-17071 Add initial version of countMentionsFromPost * MM-17071 Refactor comment mention counting * MM-17071 Use mention counting when marking post as unread * Fix shadowing in tests * Remove repeated check of user count * Refactor code using MentionType * Update comments around -1 return value * Move inner functions out of countMentionsFromPost * Remove preconditions check as separate test case * Update comments * Add User.GetMentionKeys * Revert "Make PostStore.Get return thread in order" This reverts commit 22aa010cee359655fe75e1dc899cf0ffb0943c2a. * Fix tests * Fix merge conflict * Add store.MentionAllPosts
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
5f28ce9de0
Коммит
e6f67c664c
@@ -1128,7 +1128,6 @@ func TestMarkChannelAsUnreadFromPost(t *testing.T) {
|
||||
unread, err := th.App.GetChannelUnread(c1.Id, u2.Id)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, int64(0), unread.MsgCount)
|
||||
|
||||
})
|
||||
|
||||
t.Run("Unread on a private channel", func(t *testing.T) {
|
||||
@@ -1150,6 +1149,48 @@ func TestMarkChannelAsUnreadFromPost(t *testing.T) {
|
||||
assert.Equal(t, pp2.CreateAt-1, response.LastViewedAt)
|
||||
})
|
||||
|
||||
t.Run("Unread with mentions", func(t *testing.T) {
|
||||
c2 := th.CreateChannel(th.BasicTeam)
|
||||
_, err := th.App.AddUserToChannel(u2, c2)
|
||||
require.Nil(t, err)
|
||||
|
||||
p4, err := th.App.CreatePost(&model.Post{
|
||||
UserId: u2.Id,
|
||||
ChannelId: c2.Id,
|
||||
Message: "@" + u1.Username,
|
||||
}, c2, false)
|
||||
require.Nil(t, err)
|
||||
th.CreatePost(c2)
|
||||
|
||||
response, err := th.App.MarkChannelAsUnreadFromPost(p4.Id, u1.Id)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, int64(1), response.MsgCount)
|
||||
assert.Equal(t, int64(1), response.MentionCount)
|
||||
|
||||
unread, err := th.App.GetChannelUnread(c2.Id, u1.Id)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, int64(1), unread.MsgCount)
|
||||
assert.Equal(t, int64(1), unread.MentionCount)
|
||||
})
|
||||
|
||||
t.Run("Unread on a DM channel", func(t *testing.T) {
|
||||
dc := th.CreateDmChannel(u2)
|
||||
|
||||
dm1 := th.CreatePost(dc)
|
||||
th.CreatePost(dc)
|
||||
th.CreatePost(dc)
|
||||
|
||||
response, err := th.App.MarkChannelAsUnreadFromPost(dm1.Id, u1.Id)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, int64(0), response.MsgCount)
|
||||
assert.Equal(t, int64(3), response.MentionCount)
|
||||
|
||||
unread, err := th.App.GetChannelUnread(dc.Id, u1.Id)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, int64(3), unread.MsgCount)
|
||||
assert.Equal(t, int64(3), unread.MentionCount)
|
||||
})
|
||||
|
||||
t.Run("Can't unread an imaginary post", func(t *testing.T) {
|
||||
response, err := th.App.MarkChannelAsUnreadFromPost("invalid4ofngungryquinj976y", u1.Id)
|
||||
assert.NotNil(t, err)
|
||||
|
||||
Ссылка в новой задаче
Block a user