diff options
author | Andrey Nering <andrey.nering@gmail.com> | 2017-01-12 02:27:09 -0200 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-01-12 12:27:09 +0800 |
commit | 769e0a3ea6455cb908cd7167d651024ce5c7eee3 (patch) | |
tree | 55db340bdd5aa03cd5455df6d045007e7afdb5be /routers/user/notification.go | |
parent | cbf2a967c58780ee23ff66fff1b6699f9f765294 (diff) | |
download | gitea-769e0a3ea6455cb908cd7167d651024ce5c7eee3.tar.gz gitea-769e0a3ea6455cb908cd7167d651024ce5c7eee3.zip |
Notifications: mark as read/unread and pin (#629)
* Use relative URLs
* Notifications - Mark as read/unread
* Feature of pinning a notification
* On view issue, do not mark as read a pinned notification
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) +} |