From b03dac945b66c987297c118365d087c2037f6718 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Wed, 17 Jul 2024 19:30:47 +0800 Subject: [PATCH] refactor: refactor sound request handling and validation - Change `req.Sound` type check from string to interface - Add type assertion for `req.Sound` to string - Ensure `req.APNS` and `req.Android` are only set if `req.Sound` is a string Signed-off-by: Bo-Yi Wu --- notify/notification_fcm.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/notify/notification_fcm.go b/notify/notification_fcm.go index a34e94e7..58dff083 100644 --- a/notify/notification_fcm.go +++ b/notify/notification_fcm.go @@ -74,21 +74,23 @@ func GetAndroidNotification(req *PushNotification) []*messaging.Message { } // Check if the notification has a sound - if req.Sound != "" { - if req.APNS == nil { + if req.Sound != nil { + sound, ok := req.Sound.(string) + + if req.APNS == nil && ok { req.APNS = &messaging.APNSConfig{ Payload: &messaging.APNSPayload{ Aps: &messaging.Aps{ - Sound: req.Sound.(string), + Sound: sound, }, }, } } - if req.Android == nil { + if req.Android == nil && ok { req.Android = &messaging.AndroidConfig{ Notification: &messaging.AndroidNotification{ - Sound: req.Sound.(string), + Sound: sound, }, } }