blob: 9196a44dd8f1dd547dad1fcda986046802a19322 (
plain) (
blame)
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
|
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package model
import (
"encoding/json"
"io"
)
const (
PUSH_NOTIFY_APPLE = "apple"
PUSH_NOTIFY_ANDROID = "android"
CATEGORY_DM = "DIRECT_MESSAGE"
)
type PushNotification struct {
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"`
ChannelId string `json:"channel_id"`
ChannelName string `json:"channel_name"`
}
func (me *PushNotification) ToJson() string {
b, err := json.Marshal(me)
if err != nil {
return ""
} else {
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
}
}
|