MM-20649 Fix incorrect mention count when marking a DM channel as unread (#13245)
* MM-20649 Fix incorrect mention count when marking a DM channel as unread * Satisfy govet * Update missed test
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
4e5369e759
Коммит
a0130b86d7
@@ -1132,12 +1132,12 @@ func TestMarkChannelAsUnreadFromPost(t *testing.T) {
|
||||
th.CreatePost(dc)
|
||||
th.CreatePost(dc)
|
||||
|
||||
response, err := th.App.MarkChannelAsUnreadFromPost(dm1.Id, u1.Id)
|
||||
response, err := th.App.MarkChannelAsUnreadFromPost(dm1.Id, u2.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)
|
||||
unread, err := th.App.GetChannelUnread(dc.Id, u2.Id)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, int64(3), unread.MsgCount)
|
||||
assert.Equal(t, int64(3), unread.MentionCount)
|
||||
|
||||
10
app/post.go
10
app/post.go
@@ -1180,7 +1180,7 @@ func (a *App) MaxPostSize() int {
|
||||
}
|
||||
|
||||
// countMentionsFromPost returns the number of posts in the post's channel that mention the user after and including the
|
||||
// given post. Returns the number of mentions or store.MentionAllPosts if the post is in a direct message channel.
|
||||
// given post.
|
||||
func (a *App) countMentionsFromPost(user *model.User, post *model.Post) (int, *model.AppError) {
|
||||
channel, err := a.GetChannel(post.ChannelId)
|
||||
if err != nil {
|
||||
@@ -1188,7 +1188,13 @@ func (a *App) countMentionsFromPost(user *model.User, post *model.Post) (int, *m
|
||||
}
|
||||
|
||||
if channel.Type == model.CHANNEL_DIRECT {
|
||||
return store.MentionAllPosts, nil
|
||||
// In a DM channel, every post made by the other user is a mention
|
||||
count, countErr := a.Srv.Store.Channel().CountPostsAfter(post.ChannelId, post.CreateAt-1, channel.GetOtherUserIdForDM(user.Id))
|
||||
if countErr != nil {
|
||||
return 0, countErr
|
||||
}
|
||||
|
||||
return int(count), countErr
|
||||
}
|
||||
|
||||
channelMember, err := a.GetChannelMember(channel.Id, user.Id)
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
"github.com/mattermost/mattermost-server/v5/einterfaces/mocks"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/plugin/plugintest/mock"
|
||||
"github.com/mattermost/mattermost-server/v5/store"
|
||||
"github.com/mattermost/mattermost-server/v5/store/storetest"
|
||||
)
|
||||
|
||||
@@ -1261,7 +1260,7 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
assert.Equal(t, 2, count)
|
||||
})
|
||||
|
||||
t.Run("should return store.MentionAllPosts for a direct channel", func(t *testing.T) {
|
||||
t.Run("should return the number of posts made by the other user for a direct channel", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
@@ -1278,10 +1277,22 @@ func TestCountMentionsFromPost(t *testing.T) {
|
||||
}, channel, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = th.App.CreatePost(&model.Post{
|
||||
UserId: user1.Id,
|
||||
ChannelId: channel.Id,
|
||||
Message: "test2",
|
||||
}, channel, false)
|
||||
require.Nil(t, err)
|
||||
|
||||
count, err := th.App.countMentionsFromPost(user2, post1)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, store.MentionAllPosts, count)
|
||||
assert.Equal(t, 2, count)
|
||||
|
||||
count, err = th.App.countMentionsFromPost(user1, post1)
|
||||
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 0, count)
|
||||
})
|
||||
|
||||
t.Run("should not count mentions from the before the given post", func(t *testing.T) {
|
||||
|
||||
Ссылка в новой задаче
Block a user