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
@@ -1019,7 +1019,7 @@ func (s SqlChannelStore) GetPublicChannelsForTeam(teamId string, offset int, lim
|
||||
PublicChannels pc ON (pc.Id = Channels.Id)
|
||||
WHERE
|
||||
pc.TeamId = :TeamId
|
||||
AND pc.DeleteAt = 0
|
||||
AND pc.DeleteAt = 0
|
||||
ORDER BY pc.DisplayName
|
||||
LIMIT :Limit
|
||||
OFFSET :Offset
|
||||
@@ -1229,15 +1229,15 @@ func (s SqlChannelStore) GetDeleted(teamId string, offset int, limit int, userId
|
||||
channels := &model.ChannelList{}
|
||||
|
||||
query := `
|
||||
SELECT * FROM Channels
|
||||
WHERE (TeamId = :TeamId OR TeamId = '')
|
||||
AND DeleteAt != 0
|
||||
SELECT * FROM Channels
|
||||
WHERE (TeamId = :TeamId OR TeamId = '')
|
||||
AND DeleteAt != 0
|
||||
AND Type != 'P'
|
||||
UNION
|
||||
SELECT * FROM Channels
|
||||
WHERE (TeamId = :TeamId OR TeamId = '')
|
||||
AND DeleteAt != 0
|
||||
AND Type = 'P'
|
||||
SELECT * FROM Channels
|
||||
WHERE (TeamId = :TeamId OR TeamId = '')
|
||||
AND DeleteAt != 0
|
||||
AND Type = 'P'
|
||||
AND Id IN (SELECT ChannelId FROM ChannelMembers WHERE UserId = :UserId)
|
||||
ORDER BY DisplayName LIMIT :Limit OFFSET :Offset
|
||||
`
|
||||
@@ -1758,25 +1758,30 @@ func (s SqlChannelStore) UpdateLastViewedAt(channelIds []string, userId string)
|
||||
return times, nil
|
||||
}
|
||||
|
||||
// countPostsAfter returns the number of posts in the given channel created after but not including the given timestamp.
|
||||
func (s SqlChannelStore) countPostsAfter(channelID string, since int64) (int64, *model.AppError) {
|
||||
// CountPostsAfter returns the number of posts in the given channel created after but not including the given timestamp. If given a non-empty user ID, only counts posts made by that user.
|
||||
func (s SqlChannelStore) CountPostsAfter(channelId string, timestamp int64, userId string) (int64, *model.AppError) {
|
||||
countUnreadQuery := `
|
||||
SELECT count(*)
|
||||
FROM Posts
|
||||
WHERE
|
||||
ChannelId = :channelId
|
||||
AND CreateAt > :createAt
|
||||
AND Type = ''
|
||||
ChannelId = :ChannelId
|
||||
AND CreateAt > :CreateAt
|
||||
AND Type = '' -- This line causes MM-20681
|
||||
AND DeleteAt = 0
|
||||
`
|
||||
countParams := map[string]interface{}{
|
||||
"channelId": channelID,
|
||||
"createAt": since,
|
||||
"ChannelId": channelId,
|
||||
"CreateAt": timestamp,
|
||||
}
|
||||
|
||||
if userId != "" {
|
||||
countUnreadQuery += " AND UserId = :UserId"
|
||||
countParams["UserId"] = userId
|
||||
}
|
||||
|
||||
unread, err := s.GetReplica().SelectInt(countUnreadQuery, countParams)
|
||||
if err != nil {
|
||||
return 0, model.NewAppError("SqlChannelStore.countPostsAfter", "store.sql_channel.count_posts_since.app_error", countParams, fmt.Sprintf("channel_id=%s, since=%d, err=%s", channelID, since, err), http.StatusInternalServerError)
|
||||
return 0, model.NewAppError("SqlChannelStore.CountPostsAfter", "store.sql_channel.count_posts_since.app_error", countParams, fmt.Sprintf("channel_id=%s, timestamp=%d, err=%s", channelId, timestamp, err), http.StatusInternalServerError)
|
||||
}
|
||||
return unread, nil
|
||||
}
|
||||
@@ -1787,16 +1792,11 @@ func (s SqlChannelStore) countPostsAfter(channelID string, since int64) (int64,
|
||||
func (s SqlChannelStore) UpdateLastViewedAtPost(unreadPost *model.Post, userID string, mentionCount int) (*model.ChannelUnreadAt, *model.AppError) {
|
||||
unreadDate := unreadPost.CreateAt - 1
|
||||
|
||||
unread, appErr := s.countPostsAfter(unreadPost.ChannelId, unreadDate)
|
||||
unread, appErr := s.CountPostsAfter(unreadPost.ChannelId, unreadDate, "")
|
||||
if appErr != nil {
|
||||
return nil, appErr
|
||||
}
|
||||
|
||||
if mentionCount == store.MentionAllPosts {
|
||||
// Treat every unread post as a mention (like in a DM channel)
|
||||
mentionCount = int(unread)
|
||||
}
|
||||
|
||||
params := map[string]interface{}{
|
||||
"mentions": mentionCount,
|
||||
"unreadCount": unread,
|
||||
|
||||
Ссылка в новой задаче
Block a user