Skip to content

feat(fcm): Add FcmOptions on MulticastMessage #439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class MulticastMessage {
private final AndroidConfig androidConfig;
private final WebpushConfig webpushConfig;
private final ApnsConfig apnsConfig;
private final FcmOptions fcmOptions;

private MulticastMessage(Builder builder) {
this.tokens = builder.tokens.build();
Expand All @@ -64,14 +65,16 @@ private MulticastMessage(Builder builder) {
this.androidConfig = builder.androidConfig;
this.webpushConfig = builder.webpushConfig;
this.apnsConfig = builder.apnsConfig;
this.fcmOptions = builder.fcmOptions;
}

List<Message> getMessageList() {
Message.Builder builder = Message.builder()
.setNotification(this.notification)
.setAndroidConfig(this.androidConfig)
.setApnsConfig(this.apnsConfig)
.setWebpushConfig(this.webpushConfig);
.setWebpushConfig(this.webpushConfig)
.setFcmOptions(this.fcmOptions);
if (this.data != null) {
builder.putAllData(this.data);
}
Expand Down Expand Up @@ -99,6 +102,7 @@ public static class Builder {
private AndroidConfig androidConfig;
private WebpushConfig webpushConfig;
private ApnsConfig apnsConfig;
private FcmOptions fcmOptions;

private Builder() {}

Expand Down Expand Up @@ -170,6 +174,15 @@ public Builder setApnsConfig(ApnsConfig apnsConfig) {
return this;
}

/**
* Sets the {@link FcmOptions}, which can be overridden by the platform-specific {@code
* fcm_options} fields.
*/
public Builder setFcmOptions(FcmOptions fcmOptions) {
this.fcmOptions = fcmOptions;
return this;
}

/**
* Adds the given key-value pair to the message as a data field. Key or the value may not be
* null.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class MulticastMessageTest {
.putData("key", "value")
.build();
private static final Notification NOTIFICATION = new Notification("title", "body");
private static final FcmOptions FCM_OPTIONS = FcmOptions.withAnalyticsLabel("analytics_label");

@Test
public void testMulticastMessage() {
Expand All @@ -47,6 +48,7 @@ public void testMulticastMessage() {
.setApnsConfig(APNS)
.setWebpushConfig(WEBPUSH)
.setNotification(NOTIFICATION)
.setFcmOptions(FCM_OPTIONS)
.putData("key1", "value1")
.putAllData(ImmutableMap.of("key2", "value2"))
.addToken("token1")
Expand Down Expand Up @@ -96,7 +98,8 @@ private void assertMessage(Message message, String expectedToken) {
assertSame(APNS, message.getApnsConfig());
assertSame(WEBPUSH, message.getWebpushConfig());
assertSame(NOTIFICATION, message.getNotification());
assertSame(FCM_OPTIONS, message.getFcmOptions());
assertEquals(ImmutableMap.of("key1", "value1", "key2", "value2"), message.getData());
assertEquals(expectedToken, message.getToken());
}
}
}