diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2020-01-18 02:31:26 +0800 |
---|---|---|
committer | Antoine GIRARD <sapk@users.noreply.github.com> | 2020-01-17 19:31:26 +0100 |
commit | b641c68feebaf46c5702c47fe50526cd614450c8 (patch) | |
tree | 587f846e39ffacb65b0a3ac96fd16cd10df6143d /routers/user/notification.go | |
parent | 2f3a602b3cb71f5efbb2ad8c3a0f92581849debd (diff) | |
download | gitea-b641c68feebaf46c5702c47fe50526cd614450c8.tar.gz gitea-b641c68feebaf46c5702c47fe50526cd614450c8.zip |
Improve notification pager (#9821)
Co-authored-by: Antoine GIRARD <sapk@users.noreply.github.com>
Diffstat (limited to 'routers/user/notification.go')
-rw-r--r-- | routers/user/notification.go | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/routers/user/notification.go b/routers/user/notification.go index cd6617a233..d0ab3dbe88 100644 --- a/routers/user/notification.go +++ b/routers/user/notification.go @@ -61,6 +61,19 @@ func Notifications(c *context.Context) { status = models.NotificationStatusUnread } + total, err := models.GetNotificationCount(c.User, status) + if err != nil { + c.ServerError("ErrGetNotificationCount", err) + return + } + + // redirect to last page if request page is more than total pages + pager := context.NewPagination(int(total), perPage, page, 5) + if pager.Paginater.Current() < page { + c.Redirect(fmt.Sprintf("/notifications?q=%s&page=%d", c.Query("q"), pager.Paginater.Current())) + return + } + statuses := []models.NotificationStatus{status, models.NotificationStatusPinned} notifications, err := models.NotificationsForUser(c.User, statuses, page, perPage) if err != nil { @@ -87,12 +100,6 @@ func Notifications(c *context.Context) { return } - total, err := models.GetNotificationCount(c.User, status) - if err != nil { - c.ServerError("ErrGetNotificationCount", err) - return - } - title := c.Tr("notifications") if status == models.NotificationStatusUnread && total > 0 { title = fmt.Sprintf("(%d) %s", total, title) @@ -102,7 +109,6 @@ func Notifications(c *context.Context) { c.Data["Status"] = status c.Data["Notifications"] = notifications - pager := context.NewPagination(int(total), perPage, page, 5) pager.SetDefaultParams(c) c.Data["Page"] = pager @@ -134,7 +140,7 @@ func NotificationStatusPost(c *context.Context) { return } - url := fmt.Sprintf("%s/notifications", setting.AppSubURL) + url := fmt.Sprintf("%s/notifications?page=%s", setting.AppSubURL, c.Query("page")) c.Redirect(url, 303) } |