Skip to content

Commit eaeb4d1

Browse files
GiteaBotkiatt210kiatt210wxiaoguang
authored
Fix web notification icon not updated once you read all notifications (#31447) (#31466)
Backport #31447 by kiatt210 Fix #29065 Remove status filtering from GetUIDsAndNotificationCounts sql. Co-authored-by: kiatt210 <[email protected]> Co-authored-by: kiatt210 <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent 688085c commit eaeb4d1

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

models/activities/notification.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,14 @@ type UserIDCount struct {
286286
Count int64
287287
}
288288

289-
// GetUIDsAndNotificationCounts between the two provided times
289+
// GetUIDsAndNotificationCounts returns the unread counts for every user between the two provided times.
290+
// It must return all user IDs which appear during the period, including count=0 for users who have read all.
290291
func GetUIDsAndNotificationCounts(ctx context.Context, since, until timeutil.TimeStamp) ([]UserIDCount, error) {
291-
sql := `SELECT user_id, count(*) AS count FROM notification ` +
292+
sql := `SELECT user_id, sum(case when status= ? then 1 else 0 end) AS count FROM notification ` +
292293
`WHERE user_id IN (SELECT user_id FROM notification WHERE updated_unix >= ? AND ` +
293-
`updated_unix < ?) AND status = ? GROUP BY user_id`
294+
`updated_unix < ?) GROUP BY user_id`
294295
var res []UserIDCount
295-
return res, db.GetEngine(ctx).SQL(sql, since, until, NotificationStatusUnread).Find(&res)
296+
return res, db.GetEngine(ctx).SQL(sql, NotificationStatusUnread, since, until).Find(&res)
296297
}
297298

298299
// SetIssueReadBy sets issue to be read by given user.

0 commit comments

Comments
 (0)