mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-01 04:12:10 +00:00
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
This commit is contained in:
parent
cbf2a967c5
commit
769e0a3ea6
8 changed files with 169 additions and 32 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue