-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnotification.go
45 lines (37 loc) · 1.11 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
package notificationhubs
import (
"encoding/json"
"fmt"
)
type (
// Notification is a message that can be sent through the hub
Notification struct {
Format NotificationFormat
Payload []byte
}
// IosBackgroundNotificationPayload is the payload required for a background notification
IosBackgroundNotificationPayload struct {
Aps struct {
ContentAvailable int `json:"content-available"`
} `json:"aps"`
}
)
// newNotification initializes and returns a Notification pointer
func newNotification(format NotificationFormat, payload []byte) (*Notification, error) {
if !format.IsValid() {
return nil, fmt.Errorf("unknown format '%s'", format)
}
return &Notification{format, payload}, nil
}
// String returns Notification string representation
func (n *Notification) String() string {
return fmt.Sprintf("&{%s %s}", n.Format, string(n.Payload))
}
func isIosBackgroundNotification(payload []byte) bool {
var backgroundNotification IosBackgroundNotificationPayload
err := json.Unmarshal(payload, &backgroundNotification)
if err != nil {
return false
}
return backgroundNotification.Aps.ContentAvailable == 1
}