From e66b985816fa65d8db0fb82029fae87000ac9aa5 Mon Sep 17 00:00:00 2001 From: iAbbos <50768679+iAbbos@users.noreply.github.com> Date: Thu, 12 Dec 2024 12:14:23 +0500 Subject: [PATCH] fix(android): sending data to topic (#821) fix https://github.com/appleboy/gorush/issues/816 --- notify/notification_fcm.go | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/notify/notification_fcm.go b/notify/notification_fcm.go index 054ab64d..3598858d 100644 --- a/notify/notification_fcm.go +++ b/notify/notification_fcm.go @@ -140,21 +140,6 @@ func GetAndroidNotification(req *PushNotification) []*messaging.Message { } } - // Check if the notification is a topic - if req.IsTopic() { - message := &messaging.Message{ - Notification: req.Notification, - Android: req.Android, - Webpush: req.Webpush, - APNS: req.APNS, - FCMOptions: req.FCMOptions, - Topic: req.Topic, - Condition: req.Condition, - } - - messages = append(messages, message) - } - var data map[string]string if len(req.Data) > 0 { data = make(map[string]string, len(req.Data)) @@ -170,6 +155,26 @@ func GetAndroidNotification(req *PushNotification) []*messaging.Message { } } + // Check if the notification is a topic + if req.IsTopic() { + message := &messaging.Message{ + Notification: req.Notification, + Android: req.Android, + Webpush: req.Webpush, + APNS: req.APNS, + FCMOptions: req.FCMOptions, + Topic: req.Topic, + Condition: req.Condition, + } + + // Add another field + if len(req.Data) > 0 { + message.Data = data + } + + messages = append(messages, message) + } + // Loop through the tokens and create a message for each one for _, token := range req.Tokens { message := &messaging.Message{