Clear all threads when marking channel as read

This commit is contained in:
Denis Arh
2019-07-19 23:13:15 +02:00
parent f86d3eb4d7
commit 8a5ca66fce
2 changed files with 18 additions and 0 deletions
+10
View File
@@ -21,6 +21,7 @@ type (
Record(userID, channelID, threadID, lastReadMessageID uint64, count uint32) error
Inc(channelID, replyTo, userID uint64) error
Dec(channelID, replyTo, userID uint64) error
ClearThreads(channelID, userID uint64) (err error)
CountOwned(userID uint64) (c int, err error)
ChangeOwner(userID, target uint64) error
@@ -32,6 +33,10 @@ type (
)
const (
sqlResetThreads = `UPDATE messaging_unread
SET count = 0
WHERE rel_reply_to > 0 AND rel_channel = ? AND rel_user = ?`
sqlUnreadIncCount = `UPDATE messaging_unread
SET count = count + 1
WHERE rel_channel = ? AND rel_reply_to = ? AND rel_user <> ?`
@@ -150,6 +155,11 @@ func (r unread) CountThreads(userID, channelID uint64) (types.UnreadSet, error)
return uu, nil
}
func (r unread) ClearThreads(channelID, userID uint64) (err error) {
_, err = r.db().Exec(sqlResetThreads, channelID, userID)
return
}
// Preset channel unread records for all users (and threads in that channel)
//
// Whenever channel member is added or a new thread is created
+8
View File
@@ -506,6 +506,14 @@ func (svc message) MarkAsRead(channelID, threadID, lastReadMessageID uint64) (ui
return errors.Wrap(err, "unable to record unread messages")
}
// Remove unread counts from all threads when doing mark-channel-as-read
if threadID == 0 {
err = svc.unread.ClearThreads(channelID, currentUserID)
if err != nil {
return errors.Wrap(err, "unable to clear channel threads")
}
}
// Re-count unreads and send updates to this user
svc.countUnreads(ch, nil, currentUserID)