github.com/rajatvaryani/mattermost-server@v5.11.1+incompatible/model/push_notification.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package model 5 6 import ( 7 "encoding/json" 8 "io" 9 "strings" 10 ) 11 12 const ( 13 PUSH_NOTIFY_APPLE = "apple" 14 PUSH_NOTIFY_ANDROID = "android" 15 PUSH_NOTIFY_APPLE_REACT_NATIVE = "apple_rn" 16 PUSH_NOTIFY_ANDROID_REACT_NATIVE = "android_rn" 17 18 PUSH_TYPE_MESSAGE = "message" 19 PUSH_TYPE_CLEAR = "clear" 20 PUSH_MESSAGE_V2 = "v2" 21 22 // The category is set to handle a set of interactive Actions 23 // with the push notifications 24 CATEGORY_CAN_REPLY = "CAN_REPLY" 25 26 MHPNS = "https://push.mattermost.com" 27 ) 28 29 type PushNotification struct { 30 Platform string `json:"platform"` 31 ServerId string `json:"server_id"` 32 DeviceId string `json:"device_id"` 33 Category string `json:"category"` 34 Sound string `json:"sound"` 35 Message string `json:"message"` 36 Badge int `json:"badge"` 37 ContentAvailable int `json:"cont_ava"` 38 TeamId string `json:"team_id"` 39 ChannelId string `json:"channel_id"` 40 PostId string `json:"post_id"` 41 RootId string `json:"root_id"` 42 ChannelName string `json:"channel_name"` 43 Type string `json:"type"` 44 SenderId string `json:"sender_id"` 45 OverrideUsername string `json:"override_username"` 46 OverrideIconUrl string `json:"override_icon_url"` 47 FromWebhook string `json:"from_webhook"` 48 Version string `json:"version"` 49 } 50 51 func (me *PushNotification) ToJson() string { 52 b, _ := json.Marshal(me) 53 return string(b) 54 } 55 56 func (me *PushNotification) SetDeviceIdAndPlatform(deviceId string) { 57 58 index := strings.Index(deviceId, ":") 59 60 if index > -1 { 61 me.Platform = deviceId[:index] 62 me.DeviceId = deviceId[index+1:] 63 } 64 } 65 66 func PushNotificationFromJson(data io.Reader) *PushNotification { 67 var me *PushNotification 68 json.NewDecoder(data).Decode(&me) 69 return me 70 }