MM-20681 Fix custom post types not marking channel unread when using Mark as Unread (#13247)

* MM-20681 Fix custom post types not marking channel unread when using Mark as Unread

* Fix inverted if statements
Этот коммит содержится в:
Harrison Healey
2019-12-03 14:51:50 -05:00
коммит произвёл GitHub
родитель df95748e86
Коммит 4a23d4b282
7 изменённых файлов: 192 добавлений и 25 удалений

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

@@ -1759,31 +1759,44 @@ func (s SqlChannelStore) UpdateLastViewedAt(channelIds []string, userId string)
}
// 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 := `
func (s SqlChannelStore) CountPostsAfter(channelId string, timestamp int64, userId string) (int, *model.AppError) {
joinLeavePostTypes, params := MapStringsToQueryParams([]string{
// These types correspond to the ones checked by Post.IsJoinLeaveMessage
model.POST_JOIN_LEAVE,
model.POST_ADD_REMOVE,
model.POST_JOIN_CHANNEL,
model.POST_LEAVE_CHANNEL,
model.POST_JOIN_TEAM,
model.POST_LEAVE_TEAM,
model.POST_ADD_TO_CHANNEL,
model.POST_REMOVE_FROM_CHANNEL,
model.POST_ADD_TO_TEAM,
model.POST_REMOVE_FROM_TEAM,
}, "PostType")
query := `
SELECT count(*)
FROM Posts
WHERE
ChannelId = :ChannelId
AND CreateAt > :CreateAt
AND Type = '' -- This line causes MM-20681
AND Type NOT IN ` + joinLeavePostTypes + `
AND DeleteAt = 0
`
countParams := map[string]interface{}{
"ChannelId": channelId,
"CreateAt": timestamp,
}
params["ChannelId"] = channelId
params["CreateAt"] = timestamp
if userId != "" {
countUnreadQuery += " AND UserId = :UserId"
countParams["UserId"] = userId
query += " AND UserId = :UserId"
params["UserId"] = userId
}
unread, err := s.GetReplica().SelectInt(countUnreadQuery, countParams)
unread, err := s.GetReplica().SelectInt(query, params)
if err != nil {
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 0, model.NewAppError("SqlChannelStore.CountPostsAfter", "store.sql_channel.count_posts_since.app_error", nil, fmt.Sprintf("channel_id=%s, timestamp=%d, err=%s", channelId, timestamp, err), http.StatusInternalServerError)
}
return unread, nil
return int(unread), nil
}
// UpdateLastViewedAtPost updates a ChannelMember as if the user last read the channel at the time of the given post.

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

@@ -102,11 +102,7 @@ func (s *SqlPostStore) Save(post *model.Post) (*model.Post, *model.AppError) {
time := post.UpdateAt
if post.Type != model.POST_JOIN_LEAVE && post.Type != model.POST_ADD_REMOVE &&
post.Type != model.POST_JOIN_CHANNEL && post.Type != model.POST_LEAVE_CHANNEL &&
post.Type != model.POST_JOIN_TEAM && post.Type != model.POST_LEAVE_TEAM &&
post.Type != model.POST_ADD_TO_CHANNEL && post.Type != model.POST_REMOVE_FROM_CHANNEL &&
post.Type != model.POST_ADD_TO_TEAM && post.Type != model.POST_REMOVE_FROM_TEAM {
if !post.IsJoinLeaveMessage() {
if _, err := s.GetMaster().Exec("UPDATE Channels SET LastPostAt = GREATEST(:LastPostAt, LastPostAt), TotalMsgCount = TotalMsgCount + 1 WHERE Id = :ChannelId", map[string]interface{}{"LastPostAt": time, "ChannelId": post.ChannelId}); err != nil {
mlog.Error("Error updating Channel LastPostAt.", mlog.Err(err))
}
@@ -203,7 +199,7 @@ func (s *SqlPostStore) GetFlaggedPostsForTeam(userId, teamId string, offset int,
query := `
SELECT
A.*, (SELECT count(Posts.Id) FROM Posts WHERE Posts.RootId = A.Id AND Posts.DeleteAt = 0) as ReplyCount
A.*, (SELECT count(Posts.Id) FROM Posts WHERE Posts.RootId = A.Id AND Posts.DeleteAt = 0) as ReplyCount
FROM
(SELECT
*
@@ -245,7 +241,7 @@ func (s *SqlPostStore) GetFlaggedPostsForChannel(userId, channelId string, offse
var posts []*model.Post
query := `
SELECT
*, (SELECT count(Posts.Id) FROM Posts WHERE Posts.RootId = p.Id AND Posts.DeleteAt = 0) as ReplyCount
*, (SELECT count(Posts.Id) FROM Posts WHERE Posts.RootId = p.Id AND Posts.DeleteAt = 0) as ReplyCount
FROM Posts p
WHERE
Id IN (SELECT Name FROM Preferences WHERE UserId = :UserId AND Category = :Category)