diff options
Diffstat (limited to 'routers/user/notification.go')
-rw-r--r-- | routers/user/notification.go | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/routers/user/notification.go b/routers/user/notification.go index 7e556ae2ea..4ab93de27f 100644 --- a/routers/user/notification.go +++ b/routers/user/notification.go @@ -1,7 +1,9 @@ package user import ( + "errors" "fmt" + "strconv" "strings" "github.com/Unknwon/paginater" @@ -9,6 +11,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/setting" ) const ( @@ -56,7 +59,8 @@ func Notifications(c *context.Context) { status = models.NotificationStatusUnread } - notifications, err := models.NotificationsForUser(c.User, status, page, perPage) + statuses := []models.NotificationStatus{status, models.NotificationStatusPinned} + notifications, err := models.NotificationsForUser(c.User, statuses, page, perPage) if err != nil { c.Handle(500, "ErrNotificationsForUser", err) return @@ -79,3 +83,32 @@ func Notifications(c *context.Context) { c.Data["Page"] = paginater.New(int(total), perPage, page, 5) c.HTML(200, tplNotification) } + +// NotificationStatusPost is a route for changing the status of a notification +func NotificationStatusPost(c *context.Context) { + var ( + notificationID, _ = strconv.ParseInt(c.Req.PostFormValue("notification_id"), 10, 64) + statusStr = c.Req.PostFormValue("status") + status models.NotificationStatus + ) + + switch statusStr { + case "read": + status = models.NotificationStatusRead + case "unread": + status = models.NotificationStatusUnread + case "pinned": + status = models.NotificationStatusPinned + default: + c.Handle(500, "InvalidNotificationStatus", errors.New("Invalid notification status")) + return + } + + if err := models.SetNotificationStatus(notificationID, c.User, status); err != nil { + c.Handle(500, "SetNotificationStatus", err) + return + } + + url := fmt.Sprintf("%s/notifications", setting.AppSubURL) + c.Redirect(url, 303) +} |