-
Notifications
You must be signed in to change notification settings - Fork 17
/
notification.go
39 lines (34 loc) 路 1.42 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
// Package model contains structs used in the PushBits API and across the application.
package model
import (
"strings"
"time"
)
// Notification holds information like the message, the title, and the priority of a notification.
type Notification struct {
ID string `json:"id"`
URLEncodedID string `json:"id_url_encoded"`
ApplicationID uint `json:"appid"`
Message string `json:"message" form:"message" query:"message" binding:"required"`
Title string `json:"title" form:"title" query:"title"`
Priority int `json:"priority" form:"priority" query:"priority"`
Extras map[string]interface{} `json:"extras,omitempty" form:"-" query:"-"`
Date time.Time `json:"date"`
}
// Sanitize sets explicit defaults for a notification.
func (n *Notification) Sanitize(application *Application) {
n.ID = ""
n.URLEncodedID = ""
n.ApplicationID = application.ID
if strings.TrimSpace(n.Title) == "" {
n.Title = application.Name
}
n.Date = time.Now()
}
// DeleteNotification holds information like the message ID of a deletion notification.
type DeleteNotification struct {
ID string `json:"id" form:"id"`
Date time.Time `json:"date"`
}
// NotificationExtras is need to document Notification.Extras in a format that the tool can read.
type NotificationExtras map[string]interface{}