aboutsummaryrefslogtreecommitdiffstats
path: root/models/notification.go
diff options
context:
space:
mode:
authorAndrey Nering <andrey.nering@gmail.com>2017-01-03 17:09:36 -0200
committerAndrey Nering <andrey.nering@gmail.com>2017-01-03 17:09:36 -0200
commitb354cf362ec432533da4384d4ee0c32283b7089f (patch)
tree5cc33eb5c21edd3724a88af3f3068ebd48507678 /models/notification.go
parent545ba2e2e62123fc4c9b7f780ccff3ee1b4888ff (diff)
downloadgitea-b354cf362ec432533da4384d4ee0c32283b7089f.tar.gz
gitea-b354cf362ec432533da4384d4ee0c32283b7089f.zip
Add pagination for notifications
Diffstat (limited to 'models/notification.go')
-rw-r--r--models/notification.go16
1 files changed, 11 insertions, 5 deletions
diff --git a/models/notification.go b/models/notification.go
index 46d63b4823..188c987536 100644
--- a/models/notification.go
+++ b/models/notification.go
@@ -182,14 +182,20 @@ func getIssueNotification(e Engine, userID, issueID int64) (*Notification, error
}
// NotificationsForUser returns notifications for a given user and status
-func NotificationsForUser(user *User, status NotificationStatus) ([]*Notification, error) {
- return notificationsForUser(x, user, status)
+func NotificationsForUser(user *User, status NotificationStatus, page, perPage int) ([]*Notification, error) {
+ return notificationsForUser(x, user, status, page, perPage)
}
-func notificationsForUser(e Engine, user *User, status NotificationStatus) (notifications []*Notification, err error) {
- err = e.
+func notificationsForUser(e Engine, user *User, status NotificationStatus, page, perPage int) (notifications []*Notification, err error) {
+ sess := e.
Where("user_id = ?", user.ID).
And("status = ?", status).
- OrderBy("updated_unix DESC").
+ OrderBy("updated_unix DESC")
+
+ if page > 0 && perPage > 0 {
+ sess.Limit(perPage, (page-1)*perPage)
+ }
+
+ err = sess.
Find(&notifications)
return
}