Clear all threads when marking channel as read
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user