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
Этот коммит содержится в:
Harrison Healey
2019-09-19 10:10:10 -04:00
коммит произвёл GitHub
родитель 5f28ce9de0
Коммит e6f67c664c
11 изменённых файлов: 1457 добавлений и 415 удалений

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

@@ -1678,7 +1678,7 @@ func (s SqlChannelStore) GetPinnedPostCount(channelId string, allowFromCache boo
FROM Posts
WHERE
IsPinned = true
AND ChannelId = :ChannelId
AND ChannelId = :ChannelId
AND DeleteAt = 0`, map[string]interface{}{"ChannelId": channelId})
if err != nil {
@@ -1880,8 +1880,8 @@ func (s SqlChannelStore) UpdateLastViewedAt(channelIds []string, userId string)
return times, nil
}
// CountPostsSince gives the number of posts in a channel created since a given date.
func (s SqlChannelStore) CountPostsSince(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.
func (s SqlChannelStore) countPostsAfter(channelID string, since int64) (int64, *model.AppError) {
countUnreadQuery := `
SELECT count(*)
FROM Posts
@@ -1898,22 +1898,27 @@ func (s SqlChannelStore) CountPostsSince(channelID string, since int64) (int64,
unread, err := s.GetReplica().SelectInt(countUnreadQuery, countParams)
if err != nil {
return 0, model.NewAppError("SqlChannelStore.CountPostsSince", "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, since=%d, err=%s", channelID, since, err), http.StatusInternalServerError)
}
return unread, nil
}
// UpdateLastViewedAtPost sets a channel as unread for a user at the time of the post selected and update the MentionCount
// it returns a channelunread so redux can update the apps easily.
// UpdateLastViewedAtPost updates a ChannelMember as if the user last read the channel at the time of the given post.
// If the provided mentionCount is -1, the given post and all posts after it are considered to be mentions. Returns
// an updated model.ChannelUnreadAt that can be returned to the client.
func (s SqlChannelStore) UpdateLastViewedAtPost(unreadPost *model.Post, userID string, mentionCount int) (*model.ChannelUnreadAt, *model.AppError) {
unreadDate := unreadPost.CreateAt - 1
unread, appErr := s.CountPostsSince(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,
@@ -1943,7 +1948,7 @@ func (s SqlChannelStore) UpdateLastViewedAtPost(unreadPost *model.Post, userID s
}
chanUnreadQuery := `
SELECT
SELECT
c.TeamId TeamId,
cm.UserId UserId,
cm.ChannelId ChannelId,
@@ -1951,11 +1956,11 @@ func (s SqlChannelStore) UpdateLastViewedAtPost(unreadPost *model.Post, userID s
cm.MentionCount MentionCount,
cm.LastViewedAt LastViewedAt,
cm.NotifyProps NotifyProps
FROM
FROM
ChannelMembers cm
LEFT JOIN Channels c ON c.Id=cm.ChannelId
WHERE
cm.UserId = :userId
cm.UserId = :userId
AND cm.channelId = :channelId
AND c.DeleteAt = 0
`