Skip to content

Commit

Permalink
refactor: refactor data initialization and notification handling
Browse files Browse the repository at this point in the history
- Initialize and populate `data` map if `req.Data` is not empty
- Replace inline `notification.Data` population with pre-initialized `data` map

Signed-off-by: Bo-Yi Wu <[email protected]>
  • Loading branch information
appleboy committed Jun 8, 2024
1 parent 5a5a417 commit ff9a941
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions notify/notification_fcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ func GetAndroidNotification(req *PushNotification) []*messaging.Message {
messages = append(messages, notification)
}

var data map[string]string
if len(req.Data) > 0 {
data = make(map[string]string, len(req.Data))
for k, v := range req.Data {
data[k] = fmt.Sprintf("%v", v)
}
}

// Loop through the tokens and create a message for each one
for _, token := range req.Tokens {
notification := &messaging.Message{
Expand All @@ -86,10 +94,7 @@ func GetAndroidNotification(req *PushNotification) []*messaging.Message {

// Add another field
if len(req.Data) > 0 {
notification.Data = make(map[string]string, len(req.Data))
for k, v := range req.Data {
notification.Data[k] = fmt.Sprintf("%v", v)
}
notification.Data = data
}

if req.Title != "" || req.Message != "" || req.Image != "" {
Expand Down

0 comments on commit ff9a941

Please sign in to comment.