summaryrefslogtreecommitdiffstats
path: root/models/notification.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-05-07 22:49:00 +0100
committerGitHub <noreply@github.com>2020-05-07 22:49:00 +0100
commit791353c03ba81d1c67393a04256a77293307ecad (patch)
treeb0771f7e1683db318c5e5606a312319578392dcd /models/notification.go
parent486e4c8087746ca91c05a693cadd563ac061a913 (diff)
downloadgitea-791353c03ba81d1c67393a04256a77293307ecad.tar.gz
gitea-791353c03ba81d1c67393a04256a77293307ecad.zip
Add EventSource support (#11235)
If the browser supports EventSource switch to use this instead of polling notifications. Signed-off-by: Andrew Thornton art27@cantab.net
Diffstat (limited to 'models/notification.go')
-rw-r--r--models/notification.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/models/notification.go b/models/notification.go
index d0315ab051..1c378a1350 100644
--- a/models/notification.go
+++ b/models/notification.go
@@ -718,6 +718,21 @@ func getNotificationCount(e Engine, user *User, status NotificationStatus) (coun
return
}
+// UserIDCount is a simple coalition of UserID and Count
+type UserIDCount struct {
+ UserID int64
+ Count int64
+}
+
+// GetUIDsAndNotificationCounts between the two provided times
+func GetUIDsAndNotificationCounts(since, until timeutil.TimeStamp) ([]UserIDCount, error) {
+ sql := `SELECT user_id, count(*) 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`
+ var res []UserIDCount
+ return res, x.SQL(sql, since, until, NotificationStatusUnread).Find(&res)
+}
+
func setNotificationStatusReadIfUnread(e Engine, userID, issueID int64) error {
notification, err := getIssueNotification(e, userID, issueID)
// ignore if not exists