fix fcm notification (#474)

* fix fcm notification

* fix fcm notification for unit test

Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Romanenko Alexey 2020-02-27 12:40:21 +07:00 committed by GitHub
parent cde026d9f9
commit cbab088ed4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 15 deletions

View File

@ -60,25 +60,35 @@ func GetAndroidNotification(req PushNotification) *fcm.Message {
} }
} }
notification.Notification = req.Notification n := &fcm.Notification{}
isNotificationSet := false
if req.Notification != nil { if req.Notification != nil {
// Set request message if body is empty isNotificationSet = true
if len(req.Message) > 0 { n = req.Notification
notification.Notification.Body = req.Message }
}
if len(req.Title) > 0 { if len(req.Message) > 0 {
notification.Notification.Title = req.Title isNotificationSet = true
} n.Body = req.Message
}
if len(req.Image) > 0 { if len(req.Title) > 0 {
notification.Notification.Image = req.Image isNotificationSet = true
} n.Title = req.Title
}
if v, ok := req.Sound.(string); ok && len(v) > 0 { if len(req.Image) > 0 {
notification.Notification.Sound = v isNotificationSet = true
} n.Image = req.Image
}
if v, ok := req.Sound.(string); ok && len(v) > 0 {
isNotificationSet = true
n.Sound = v
}
if isNotificationSet {
notification.Notification = n
} }
// handle iOS apns in fcm // handle iOS apns in fcm