diff options
-rw-r--r-- | app/notification.go | 14 | ||||
-rw-r--r-- | model/push_response.go | 57 |
2 files changed, 65 insertions, 6 deletions
diff --git a/app/notification.go b/app/notification.go index ae365b417..56b5ec336 100644 --- a/app/notification.go +++ b/app/notification.go @@ -552,7 +552,7 @@ func ClearPushNotification(userId string, channelId string) *model.AppError { return nil } -func sendToPushProxy(msg model.PushNotification, session *model.Session) *model.AppError { +func sendToPushProxy(msg model.PushNotification, session *model.Session) { msg.ServerId = utils.CfgDiagnosticId tr := &http.Transport{ @@ -563,22 +563,24 @@ func sendToPushProxy(msg model.PushNotification, session *model.Session) *model. request, _ := http.NewRequest("POST", *utils.Cfg.EmailSettings.PushNotificationServer+model.API_URL_SUFFIX_V1+"/send_push", strings.NewReader(msg.ToJson())) if resp, err := httpClient.Do(request); err != nil { - return model.NewLocAppError("sendToPushProxy", "api.post.send_notifications_and_forget.push_notification.error", map[string]interface{}{"DeviceId": msg.DeviceId, "Error": err.Error()}, "") + l4g.Error("Device push reported as error for UserId=%v SessionId=%v message=%v", session.UserId, session.Id, err.Error()) } else { - m := model.MapFromJson(resp.Body) + pushResponse := model.PushResponseFromJson(resp.Body) if resp.Body != nil { ioutil.ReadAll(resp.Body) resp.Body.Close() } - if m[model.STATUS] == model.STATUS_REMOVE { + if pushResponse[model.PUSH_STATUS] == model.PUSH_STATUS_REMOVE { l4g.Info("Device was reported as removed for UserId=%v SessionId=%v removing push for this session", session.UserId, session.Id) AttachDeviceId(session.Id, "", session.ExpiresAt) ClearSessionCacheForUser(session.UserId) } - } - return nil + if pushResponse[model.PUSH_STATUS] == model.PUSH_STATUS_FAIL { + l4g.Error("Device push reported as error for UserId=%v SessionId=%v message=%v", session.UserId, session.Id, pushResponse[model.PUSH_STATUS_ERROR_MSG]) + } + } } func getMobileAppSessions(userId string) ([]*model.Session, *model.AppError) { 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 + } +} |