diff options
author | Giteabot <teabot@gitea.io> | 2024-06-24 00:08:37 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-24 00:08:37 +0800 |
commit | eaeb4d1b9659265bb2a17dc4291543bf47ff8419 (patch) | |
tree | 86991e935e98abd59777615a6330a46565a20dc2 /models | |
parent | 688085c15efcc37859b059034ca23b9eb536d193 (diff) | |
download | gitea-eaeb4d1b9659265bb2a17dc4291543bf47ff8419.tar.gz gitea-eaeb4d1b9659265bb2a17dc4291543bf47ff8419.zip |
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 <40639725+kiatt210@users.noreply.github.com>
Co-authored-by: kiatt210 <kiatt210@github.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'models')
-rw-r--r-- | models/activities/notification.go | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/models/activities/notification.go b/models/activities/notification.go index dc1b8c6fae..b888adeb60 100644 --- a/models/activities/notification.go +++ b/models/activities/notification.go @@ -286,13 +286,14 @@ type UserIDCount struct { Count int64 } -// GetUIDsAndNotificationCounts between the two provided times +// GetUIDsAndNotificationCounts returns the unread counts for every user between the two provided times. +// It must return all user IDs which appear during the period, including count=0 for users who have read all. func GetUIDsAndNotificationCounts(ctx context.Context, since, until timeutil.TimeStamp) ([]UserIDCount, error) { - sql := `SELECT user_id, count(*) AS count FROM notification ` + + sql := `SELECT user_id, sum(case when status= ? then 1 else 0 end) AS count FROM notification ` + `WHERE user_id IN (SELECT user_id FROM notification WHERE updated_unix >= ? AND ` + - `updated_unix < ?) AND status = ? GROUP BY user_id` + `updated_unix < ?) GROUP BY user_id` var res []UserIDCount - return res, db.GetEngine(ctx).SQL(sql, since, until, NotificationStatusUnread).Find(&res) + return res, db.GetEngine(ctx).SQL(sql, NotificationStatusUnread, since, until).Find(&res) } // SetIssueReadBy sets issue to be read by given user. |