From cbab088ed4109d568ff196d6e97ae760ffc6ff39 Mon Sep 17 00:00:00 2001 From: Romanenko Alexey Date: Thu, 27 Feb 2020 12:40:21 +0700 Subject: [PATCH] fix fcm notification (#474) * fix fcm notification * fix fcm notification for unit test Co-authored-by: Bo-Yi Wu --- gorush/notification_fcm.go | 40 ++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/gorush/notification_fcm.go b/gorush/notification_fcm.go index 927518d..3f17115 100644 --- a/gorush/notification_fcm.go +++ b/gorush/notification_fcm.go @@ -60,25 +60,35 @@ func GetAndroidNotification(req PushNotification) *fcm.Message { } } - notification.Notification = req.Notification - + n := &fcm.Notification{} + isNotificationSet := false if req.Notification != nil { - // Set request message if body is empty - if len(req.Message) > 0 { - notification.Notification.Body = req.Message - } + isNotificationSet = true + n = req.Notification + } - if len(req.Title) > 0 { - notification.Notification.Title = req.Title - } + if len(req.Message) > 0 { + isNotificationSet = true + n.Body = req.Message + } - if len(req.Image) > 0 { - notification.Notification.Image = req.Image - } + if len(req.Title) > 0 { + isNotificationSet = true + n.Title = req.Title + } - if v, ok := req.Sound.(string); ok && len(v) > 0 { - notification.Notification.Sound = v - } + if len(req.Image) > 0 { + 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