-
-
Notifications
You must be signed in to change notification settings - Fork 815
Expand file tree
/
Copy pathnotification.go
More file actions
87 lines (81 loc) · 2.82 KB
/
Copy pathnotification.go
File metadata and controls
87 lines (81 loc) · 2.82 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package enum
import (
"strconv"
)
// NotificationChannel represents the medium that the notification is sent
type NotificationChannel int
var (
//NotificationChannelWeb is an in-app notification
NotificationChannelWeb NotificationChannel = 1
//NotificationChannelEmail is an email notification
NotificationChannelEmail NotificationChannel = 2
)
// NotificationEvent represents all possible notification events
type NotificationEvent struct {
UserSettingsKeyName string
DefaultSettingValue string
RequiresSubscriptionUserRoles []Role
DefaultEnabledUserRoles []Role
Validate func(string) bool
}
func notificationEventValidation(v string) bool {
return v == "0" || v == "1" || v == "2" || v == "3"
}
var (
//NotificationEventNewPost is triggered when a new post is posted
NotificationEventNewPost = NotificationEvent{
UserSettingsKeyName: "event_notification_new_post",
DefaultSettingValue: strconv.Itoa(int(NotificationChannelWeb | NotificationChannelEmail)),
RequiresSubscriptionUserRoles: []Role{},
DefaultEnabledUserRoles: []Role{
RoleAdministrator,
RoleCollaborator,
},
Validate: notificationEventValidation,
}
//NotificationEventNewComment is triggered when a new comment is posted
NotificationEventNewComment = NotificationEvent{
UserSettingsKeyName: "event_notification_new_comment",
DefaultSettingValue: strconv.Itoa(int(NotificationChannelWeb | NotificationChannelEmail)),
RequiresSubscriptionUserRoles: []Role{
RoleVisitor,
},
DefaultEnabledUserRoles: []Role{
RoleAdministrator,
RoleCollaborator,
},
Validate: notificationEventValidation,
}
//NotificationEventMention is triggered when a new comment is posted with the user @-mentioned
NotificationEventMention = NotificationEvent{
UserSettingsKeyName: "event_notification_mention",
DefaultSettingValue: strconv.Itoa(int(NotificationChannelWeb | NotificationChannelEmail)),
RequiresSubscriptionUserRoles: []Role{},
DefaultEnabledUserRoles: []Role{
RoleAdministrator,
RoleCollaborator,
},
Validate: notificationEventValidation,
}
//NotificationEventChangeStatus is triggered when a new post has its status changed
NotificationEventChangeStatus = NotificationEvent{
UserSettingsKeyName: "event_notification_change_status",
DefaultSettingValue: strconv.Itoa(int(NotificationChannelWeb | NotificationChannelEmail)),
RequiresSubscriptionUserRoles: []Role{
RoleVisitor,
},
DefaultEnabledUserRoles: []Role{
RoleAdministrator,
RoleCollaborator,
RoleVisitor,
},
Validate: notificationEventValidation,
}
//AllNotificationEvents contains all possible notification events
AllNotificationEvents = []NotificationEvent{
NotificationEventNewPost,
NotificationEventNewComment,
NotificationEventMention,
NotificationEventChangeStatus,
}
)