Skip to content

Commit

Permalink
Merge pull request #209 from wcalebgray/fcm-data-upgrade
Browse files Browse the repository at this point in the history
Add passthrough for settings to enable data notification
  • Loading branch information
alex-friedl authored Jun 21, 2024
2 parents 4b3c3f3 + 5c2d937 commit b438728
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/sendFCM.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const sendFCM = (regIds, data, settings) => {

const promises = [];

const fcmMessage = FcmMessage.build(data, regIds);
const fcmMessage = FcmMessage.build(data, settings.fcm);

let chunk = 0;

Expand Down
13 changes: 8 additions & 5 deletions src/utils/fcmMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ class FcmMessage {
}, {});
}

static buildAndroidMessage(params) {
const message = buildGcmMessage(params, {});
static buildAndroidMessage(params, options) {
const message = buildGcmMessage(params, options);

const androidMessage = message.toJson();

androidMessage.ttl = androidMessage.time_to_live * 1000;
androidMessage.data = this.normalizeDataParams(androidMessage.data);

delete androidMessage.content_available;
delete androidMessage.mutable_content;
delete androidMessage.delay_while_idle;
delete androidMessage.time_to_live;
delete androidMessage.dry_run;
delete androidMessage.data;

return androidMessage;
}
Expand All @@ -60,7 +60,7 @@ class FcmMessage {
return { headers: this.normalizeDataParams(headers), payload };
}

static build(params) {
static build(params, options) {
const { providersExclude = [], ...fcmMessageParams } = params;

const data = this.normalizeDataParams(fcmMessageParams.custom);
Expand All @@ -72,7 +72,10 @@ class FcmMessage {
}

if (!providersExclude.includes('android')) {
createParams.android = this.buildAndroidMessage(fcmMessageParams);
createParams.android = this.buildAndroidMessage(
fcmMessageParams,
options
);
}

return new this(createParams);
Expand Down

0 comments on commit b438728

Please sign in to comment.