summaryrefslogtreecommitdiffstats
path: root/model/push_response.go
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2017-02-28 20:19:19 -0500
committerenahum <nahumhbl@gmail.com>2017-02-28 22:19:19 -0300
commitfc9e5d8510a26d6b4a89b45f5b8b2779d82f62a9 (patch)
treebbe70296b7d2eb2f0705174f09a08346d51f0cc0 /model/push_response.go
parent28c218db3bbdcc0776be1be91ff4acbd0586f590 (diff)
downloadchat-fc9e5d8510a26d6b4a89b45f5b8b2779d82f62a9.tar.gz
chat-fc9e5d8510a26d6b4a89b45f5b8b2779d82f62a9.tar.bz2
chat-fc9e5d8510a26d6b4a89b45f5b8b2779d82f62a9.zip
Fixing removing push tokens and logging error messages (#5551)
Diffstat (limited to 'model/push_response.go')
-rw-r--r--model/push_response.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/model/push_response.go b/model/push_response.go
new file mode 100644
index 000000000..0271bc94b
--- /dev/null
+++ b/model/push_response.go
@@ -0,0 +1,57 @@
+// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package model
+
+import (
+ "encoding/json"
+ "io"
+)
+
+const (
+ PUSH_STATUS = "status"
+ PUSH_STATUS_OK = "OK"
+ PUSH_STATUS_FAIL = "FAIL"
+ PUSH_STATUS_REMOVE = "REMOVE"
+ PUSH_STATUS_ERROR_MSG = "error"
+)
+
+type PushResponse map[string]string
+
+func NewOkPushResponse() PushResponse {
+ m := make(map[string]string)
+ m[PUSH_STATUS] = PUSH_STATUS_OK
+ return m
+}
+
+func NewRemovePushResponse() PushResponse {
+ m := make(map[string]string)
+ m[PUSH_STATUS] = PUSH_STATUS_REMOVE
+ return m
+}
+
+func NewErrorPushResponse(message string) PushResponse {
+ m := make(map[string]string)
+ m[PUSH_STATUS] = PUSH_STATUS_FAIL
+ m[PUSH_STATUS_ERROR_MSG] = message
+ return m
+}
+
+func (me *PushResponse) ToJson() string {
+ if b, err := json.Marshal(me); err != nil {
+ return ""
+ } else {
+ return string(b)
+ }
+}
+
+func PushResponseFromJson(data io.Reader) PushResponse {
+ decoder := json.NewDecoder(data)
+
+ var objmap PushResponse
+ if err := decoder.Decode(&objmap); err != nil {
+ return make(map[string]string)
+ } else {
+ return objmap
+ }
+}