mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
MM-34895 CRT: Replying to a root post with an at-mention triggers an unread mention (#17474)
* don't count your own replies as unread * corrected totalUnreadThreads query
This commit is contained in:
@@ -5675,8 +5675,8 @@ func checkThreadListReplies(t *testing.T, th *TestHelper, client *model.Client4,
|
||||
}
|
||||
sum += thr.UnreadReplies
|
||||
}
|
||||
require.EqualValues(t, expectedReplies, sum)
|
||||
require.Equal(t, count, u.TotalUnreadThreads)
|
||||
require.EqualValues(t, expectedReplies, sum, "expectedReplies don't match")
|
||||
require.Equal(t, count, u.TotalUnreadThreads, "TotalUnreadThreads don't match")
|
||||
|
||||
return u, r
|
||||
}
|
||||
|
||||
@@ -142,11 +142,12 @@ func (s *SqlThreadStore) GetThreadsForUser(userId, teamId string, opts model.Get
|
||||
threadsChan := make(chan store.StoreResult, 1)
|
||||
go func() {
|
||||
repliesQuery, repliesQueryArgs, _ := s.getQueryBuilder().
|
||||
Select("COUNT(Posts.Id)").
|
||||
Select("COUNT(DISTINCT(Posts.RootId))").
|
||||
From("Posts").
|
||||
LeftJoin("ThreadMemberships ON Posts.Id = ThreadMemberships.PostId").
|
||||
LeftJoin("ThreadMemberships ON Posts.RootId = ThreadMemberships.PostId").
|
||||
LeftJoin("Channels ON Posts.ChannelId = Channels.Id").
|
||||
Where(fetchConditions).
|
||||
Where(sq.NotEq{"Posts.UserId": userId}).
|
||||
Where("Posts.UpdateAt >= ThreadMemberships.LastViewed").ToSql()
|
||||
|
||||
totalUnreadThreads, err := s.GetMaster().SelectInt(repliesQuery, repliesQueryArgs...)
|
||||
@@ -319,7 +320,7 @@ func (s *SqlThreadStore) GetThreadForUser(userId, teamId, threadId string, exten
|
||||
model.Post
|
||||
}
|
||||
|
||||
unreadRepliesQuery := "SELECT COUNT(Posts.Id) From Posts Where Posts.RootId=ThreadMemberships.PostId AND Posts.UpdateAt >= ThreadMemberships.LastViewed AND Posts.DeleteAt=0"
|
||||
unreadRepliesQuery := "SELECT COUNT(Posts.Id) From Posts Where Posts.RootId=ThreadMemberships.PostId AND Posts.UpdateAt >= ThreadMemberships.LastViewed AND Posts.DeleteAt=0 AND Posts.UserId != ?"
|
||||
fetchConditions := sq.And{
|
||||
sq.Or{sq.Eq{"Channels.TeamId": teamId}, sq.Eq{"Channels.TeamId": ""}},
|
||||
sq.Eq{"ThreadMemberships.UserId": userId},
|
||||
@@ -330,7 +331,7 @@ func (s *SqlThreadStore) GetThreadForUser(userId, teamId, threadId string, exten
|
||||
query, args, _ := s.getQueryBuilder().
|
||||
Select("Threads.*, Posts.*, ThreadMemberships.LastViewed as LastViewedAt, ThreadMemberships.UnreadMentions as UnreadMentions, ThreadMemberships.Following").
|
||||
From("Threads").
|
||||
Column(sq.Alias(sq.Expr(unreadRepliesQuery), "UnreadReplies")).
|
||||
Column(sq.Alias(sq.Expr(unreadRepliesQuery, userId), "UnreadReplies")).
|
||||
LeftJoin("Posts ON Posts.Id = Threads.PostId").
|
||||
LeftJoin("Channels ON Posts.ChannelId = Channels.Id").
|
||||
LeftJoin("ThreadMemberships ON ThreadMemberships.PostId = Threads.PostId").
|
||||
|
||||
Reference in New Issue
Block a user