Skip to content

Commit cc8b9e4

Browse files
authored
feat: implement gRPC support sound field for FCM (#794)
- Add `IsGRPC` field to `PushNotification` struct - Add logic to handle sound configuration for gRPC notifications in `GetAndroidNotification` - Set `IsGRPC` to `true` in the `Send` function of the `Server` struct Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent 1f48853 commit cc8b9e4

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

notify/notification.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ 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"`
118119
}
119120

120121
// Bytes for queue message

notify/notification_fcm.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,22 @@ func GetAndroidNotification(req *PushNotification) []*messaging.Message {
7373
}
7474
}
7575

76+
// 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),
82+
},
83+
},
84+
}
85+
req.Android = &messaging.AndroidConfig{
86+
Notification: &messaging.AndroidNotification{
87+
Sound: req.Sound.(string),
88+
},
89+
}
90+
}
91+
7692
// Check if the notification is a topic
7793
if req.IsTopic() {
7894
message := &messaging.Message{

rpc/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ 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,
8283
}
8384

8485
if badge > 0 {

0 commit comments

Comments
 (0)