Skip to content

Commit

Permalink
refactor: refactor sound request handling and validation
Browse files Browse the repository at this point in the history
- 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 <appleboy.tw@gmail.com>
  • Loading branch information
appleboy committed Jul 17, 2024
1 parent 29e6ee8 commit b03dac9
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions notify/notification_fcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
}
Expand Down

0 comments on commit b03dac9

Please sign in to comment.