From a82bebefa64f1b3d781ad3c930ad836d37f5c174 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Wed, 17 Jul 2024 20:33:08 +0800 Subject: [PATCH] chore(fcm): notification handling logic for sound field (#797) * chore(fcm): notification handling logic for sound field - Remove `IsGRPC` field from `PushNotification` struct - Simplify condition by removing `IsGRPC` check in `GetAndroidNotification` - Add checks for `APNS` and `Android` fields in `GetAndroidNotification` - Remove `IsGRPC` initialization in `Send` method of `Server` Signed-off-by: Bo-Yi Wu * 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 --------- Signed-off-by: Bo-Yi Wu --- notify/notification.go | 1 - notify/notification_fcm.go | 27 +++++++++++++++++---------- rpc/server.go | 1 - 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/notify/notification.go b/notify/notification.go index 41a03f1d0..fcd9dfdad 100644 --- a/notify/notification.go +++ b/notify/notification.go @@ -115,7 +115,6 @@ type PushNotification struct { // ref: https://github.com/sideshow/apns2/blob/54928d6193dfe300b6b88dad72b7e2ae138d4f0a/payload/builder.go#L7-L24 InterruptionLevel string `json:"interruption_level,omitempty"` - IsGRPC bool `json:"is_grpc,omitempty"` } // Bytes for queue message diff --git a/notify/notification_fcm.go b/notify/notification_fcm.go index ab253de34..58dff0839 100644 --- a/notify/notification_fcm.go +++ b/notify/notification_fcm.go @@ -74,18 +74,25 @@ func GetAndroidNotification(req *PushNotification) []*messaging.Message { } // Check if the notification has a sound - if req.Sound != "" && req.IsGRPC { - req.APNS = &messaging.APNSConfig{ - Payload: &messaging.APNSPayload{ - Aps: &messaging.Aps{ - Sound: req.Sound.(string), + 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: sound, + }, }, - }, + } } - req.Android = &messaging.AndroidConfig{ - Notification: &messaging.AndroidNotification{ - Sound: req.Sound.(string), - }, + + if req.Android == nil && ok { + req.Android = &messaging.AndroidConfig{ + Notification: &messaging.AndroidNotification{ + Sound: sound, + }, + } } } diff --git a/rpc/server.go b/rpc/server.go index c108e0843..9c371ec4a 100644 --- a/rpc/server.go +++ b/rpc/server.go @@ -79,7 +79,6 @@ func (s *Server) Send(ctx context.Context, in *proto.NotificationRequest) (*prot Priority: strings.ToLower(in.GetPriority().String()), PushType: in.PushType, Development: in.Development, - IsGRPC: true, } if badge > 0 {