2017-08-16 21:37:37 +00:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
2020-08-09 22:29:54 +00:00
|
|
|
// See LICENSE.txt for license information.
|
2017-03-25 20:04:10 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-10-16 22:47:22 +00:00
|
|
|
func (pr *PushResponse) ToJson() string {
|
|
|
|
b, _ := json.Marshal(pr)
|
2018-11-18 17:55:05 +00:00
|
|
|
return string(b)
|
2017-03-25 20:04:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2021-10-16 22:47:22 +00:00
|
|
|
return objmap
|
2017-03-25 20:04:10 +00:00
|
|
|
}
|