/
push_notification.go
84 lines (75 loc) · 2.05 KB
/
push_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package server
import (
"encoding/json"
"io"
)
const (
PUSH_NOTIFY_APPLE = "apple"
PUSH_NOTIFY_ANDROID = "android"
PUSH_TYPE_MESSAGE = "message"
PUSH_TYPE_CLEAR = "clear"
)
type PushNotificationAck struct {
Id string `json:"id"`
Platform string `json:"platform"`
Type string `json:"type"`
}
type PushNotification struct {
Id string `json:"id"`
AckId string `json:"ack_id"`
Platform string `json:"platform"`
ServerId string `json:"server_id"`
DeviceId string `json:"device_id"`
Category string `json:"category"`
Sound string `json:"sound"`
Message string `json:"message"`
Badge int `json:"badge"`
ContentAvailable int `json:"cont_ava"`
TeamId string `json:"team_id"`
ChannelId string `json:"channel_id"`
PostId string `json:"post_id"`
RootId string `json:"root_id"`
ChannelName string `json:"channel_name"`
Type string `json:"type"`
SenderName string `json:"sender_name"`
SenderId string `json:"sender_id"`
OverrideUsername string `json:"override_username"`
OverrideIconUrl string `json:"override_icon_url"`
FromWebhook string `json:"from_webhook"`
Version string `json:"version"`
}
func (me *PushNotification) ToJson() string {
b, err := json.Marshal(me)
if err != nil {
return ""
}
return string(b)
}
func PushNotificationFromJson(data io.Reader) *PushNotification {
decoder := json.NewDecoder(data)
var me PushNotification
err := decoder.Decode(&me)
if err == nil {
return &me
} else {
return nil
}
}
func (me *PushNotificationAck) ToJson() string {
b, err := json.Marshal(me)
if err != nil {
return ""
}
return string(b)
}
func PushNotificationAckFromJson(data io.Reader) *PushNotificationAck {
var me PushNotificationAck
decoder := json.NewDecoder(data)
err := decoder.Decode(&me)
if err == nil {
return &me
}
return nil
}