firebase / firebase-admin-go

Firebase Admin Go SDK
Apache License 2.0
1.14k stars 247 forks source link

BUG: Firebase Cloud Messaging SendAll() sets same device badge count across different FCM Message objects #527

Open sauceman40 opened 1 year ago

sauceman40 commented 1 year ago

Describe your environment

Describe the problem

When sending a slice of FCM Messages via the messaging.SendAll() method, each device displays the same badge count, not the badge count specified in the device's FCM Message object.

Steps to reproduce:

  1. Create a slice of FCM Message objects, each with their own distinct badge counts.
  2. Send these FCM message objects via the SendAll() method.
  3. Each recipient device displays the same badge count, not the count specified in its corresponding FCM Message object.

Relevant Code:

// 1. Initialize the Messaging Client
ctx := context.Background()
messagingClient, err := fcmClient.firebaseApp.Messaging(ctx)
if err != nil {
    return err
}

// 2. Create slice of FCM Messages, each with their own intended badge count.
fcmMessages := []*messaging.Message{}
for _, notif := range notifications {
    fcmMessage := &messaging.Message{
        Data: map[string]string{
            // ...
            "badge":       notif.BadgeCountString,
        },
        APNS: &messaging.APNSConfig{
            Payload: &messaging.APNSPayload{
                Aps: &messaging.Aps{
                    // ...
                    Badge: &notif.BadgeCount,
                },
            },
        },
        Token: notif.DeviceToken,
    }

    fcmMessages = append(fcmMessages, fcmMessage)
}

// 3. Use the SendAll method to send messages in parallel.
_, err = messagingClient.SendAll(ctx, fcmMessages)

// 4. (BUG) Upon receipt, each device displays the same badge count.
google-oss-bot commented 1 year ago

I found a few problems with this issue:

sauceman40 commented 1 year ago

@chong-shao @lahirumaramba is any more context needed here? Let me know whether you're able to reproduce