enhance(notifications): mark current notification page as read (#39294)

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Mitrahsoft
2026-09-16 00:31:16 +00:00
committed by GitHub
co-authored by wxiaoguang
parent f9d3268dbe
commit a583a30d4a
5 changed files with 42 additions and 16 deletions
+7 -10
View File
@@ -326,16 +326,6 @@ type UserIDCount struct {
Count int64
}
// 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, 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 < ?) GROUP BY user_id`
var res []UserIDCount
return res, db.GetEngine(ctx).SQL(sql, NotificationStatusUnread, since, until).Find(&res)
}
// SetIssueReadBy sets issue to be read by given user. The bool result is true
// when the unread count actually decreased, so callers can skip a push on no-op.
func SetIssueReadBy(ctx context.Context, issueID, userID int64) (bool, error) {
@@ -410,6 +400,13 @@ func GetNotificationByID(ctx context.Context, notificationID int64) (*Notificati
return notification, nil
}
func GetNotificationsByIDs(ctx context.Context, ids []int64, userID int64) (ret NotificationList, _ error) {
err := db.GetEngine(ctx).
Where("user_id = ?", userID).And(builder.In("id", ids)).
Find(&ret)
return ret, err
}
// UpdateNotificationStatuses updates the statuses of all of a user's notifications
// that are of the currentStatus type to the desiredStatus. Returns the number of
// rows actually changed so callers can skip downstream work on a no-op.