firebase / firebase-admin-go

Firebase Admin Go SDK

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

sauceman40 opened this issue · comments

Describe your environment

  • Operating System version: Multiple (Amazon Linux, Mac OS Ventura 13.0.1 (22A400))
  • Firebase SDK version: Firebase Admin SDK v4
  • Library version: v4.8.0
  • Go version: 1.18
  • Firebase Product: Firebase Cloud Messaging

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.

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

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