Skip to content

Commit a82bebe

Browse files
authored
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 <appleboy.tw@gmail.com> * 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 <appleboy.tw@gmail.com> --------- Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
1 parent 0199ac4 commit a82bebe

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

notify/notification.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ type PushNotification struct {
115115

116116
// ref: https://github.com/sideshow/apns2/blob/54928d6193dfe300b6b88dad72b7e2ae138d4f0a/payload/builder.go#L7-L24
117117
InterruptionLevel string `json:"interruption_level,omitempty"`
118-
IsGRPC bool `json:"is_grpc,omitempty"`
119118
}
120119

121120
// Bytes for queue message

notify/notification_fcm.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,25 @@ func GetAndroidNotification(req *PushNotification) []*messaging.Message {
7474
}
7575

7676
// Check if the notification has a sound
77-
if req.Sound != "" && req.IsGRPC {
78-
req.APNS = &messaging.APNSConfig{
79-
Payload: &messaging.APNSPayload{
80-
Aps: &messaging.Aps{
81-
Sound: req.Sound.(string),
77+
if req.Sound != nil {
78+
sound, ok := req.Sound.(string)
79+
80+
if req.APNS == nil && ok {
81+
req.APNS = &messaging.APNSConfig{
82+
Payload: &messaging.APNSPayload{
83+
Aps: &messaging.Aps{
84+
Sound: sound,
85+
},
8286
},
83-
},
87+
}
8488
}
85-
req.Android = &messaging.AndroidConfig{
86-
Notification: &messaging.AndroidNotification{
87-
Sound: req.Sound.(string),
88-
},
89+
90+
if req.Android == nil && ok {
91+
req.Android = &messaging.AndroidConfig{
92+
Notification: &messaging.AndroidNotification{
93+
Sound: sound,
94+
},
95+
}
8996
}
9097
}
9198

rpc/server.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ func (s *Server) Send(ctx context.Context, in *proto.NotificationRequest) (*prot
7979
Priority: strings.ToLower(in.GetPriority().String()),
8080
PushType: in.PushType,
8181
Development: in.Development,
82-
IsGRPC: true,
8382
}
8483

8584
if badge > 0 {

0 commit comments

Comments
 (0)