-
-
Notifications
You must be signed in to change notification settings - Fork 617
/
notification.go
68 lines (57 loc) · 1.53 KB
/
notification.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package handlers
import (
"github.com/getfider/fider/app/pkg/web"
)
// TotalUnreadNotifications returns the total number of unread notifications
func TotalUnreadNotifications() web.HandlerFunc {
return func(c web.Context) error {
total, err := c.Services().Notifications.TotalUnread()
if err != nil {
return c.Failure(err)
}
return c.Ok(web.Map{
"total": total,
})
}
}
// Notifications is the home for unread and recent notifications
func Notifications() web.HandlerFunc {
return func(c web.Context) error {
notifications, err := c.Services().Notifications.GetActiveNotifications()
if err != nil {
return c.Failure(err)
}
return c.Page(web.Props{
Title: "Notifications",
Data: web.Map{
"notifications": notifications,
},
})
}
}
// ReadNotification marks it as read and redirect to its content
func ReadNotification() web.HandlerFunc {
return func(c web.Context) error {
id, err := c.ParamAsInt("id")
if err != nil {
return c.Failure(err)
}
notification, err := c.Services().Notifications.GetNotification(id)
if err != nil {
return c.Failure(err)
}
if err = c.Services().Notifications.MarkAsRead(notification.ID); err != nil {
return c.Failure(err)
}
return c.Redirect(c.BaseURL() + notification.Link)
}
}
// ReadAllNotifications marks all unread notifications as read
func ReadAllNotifications() web.HandlerFunc {
return func(c web.Context) error {
if err := c.Services().Notifications.MarkAllAsRead(); err != nil {
return c.Failure(err)
}
return c.Ok(web.Map{})
}
}