forked from qor/notification
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage.go
58 lines (50 loc) · 1.24 KB
/
message.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
package notification
import (
"time"
"github.com/jinzhu/gorm"
"github.com/qor/admin"
)
type Message struct {
From interface{}
To interface{}
Title string
Body string
MessageType string
Data []byte
ResolvedAt *time.Time
}
type QorNotification struct {
gorm.Model
From string
To string
Title string
Body string `sql:"size:65532"`
MessageType string
Data []byte `sql:"size:65532"`
ResolvedAt *time.Time
}
func (qorNotification QorNotification) IsResolved() bool {
return qorNotification.ResolvedAt != nil
}
func (qorNotification *QorNotification) Actions(context *admin.Context) (actions []*Action) {
var globalActions []*Action
if n := context.Get("Notification"); n != nil {
if notification, ok := n.(*Notification); ok {
for _, action := range notification.Actions {
if action.HasMessageType(qorNotification.MessageType) {
if action.Visible != nil {
if !action.Visible(qorNotification, context) {
continue
}
}
if len(action.MessageTypes) == 0 {
globalActions = append(globalActions, action)
} else {
actions = append(actions, action)
}
}
}
}
}
return append(actions, globalActions...)
}