Skip to content

Commit

Permalink
Merge aa8356e into 8f031b4
Browse files Browse the repository at this point in the history
  • Loading branch information
zwu52 authored Oct 25, 2022
2 parents 8f031b4 + aa8356e commit e0fabfd
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-swans-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/messaging': minor
---

Expose 'icon' field from the Firebase Messaging SDK as part of the 'notification' payload
1 change: 1 addition & 0 deletions common/api-review/messaging-sw.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export { NextFn }
// @public
export interface NotificationPayload {
body?: string;
icon?: string;
image?: string;
title?: string;
}
Expand Down
1 change: 1 addition & 0 deletions common/api-review/messaging.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export { NextFn }
// @public
export interface NotificationPayload {
body?: string;
icon?: string;
image?: string;
title?: string;
}
Expand Down
14 changes: 11 additions & 3 deletions packages/messaging/src/helpers/externalizePayload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('externalizePayload', () => {
title: 'title',
body: 'body',
image: 'image',
icon: 'icon',
// eslint-disable-next-line camelcase
click_action: 'https://www.self_orgin.com'
},
Expand All @@ -38,7 +39,12 @@ describe('externalizePayload', () => {
};

const payload: MessagePayload = {
notification: { title: 'title', body: 'body', image: 'image' },
notification: {
title: 'title',
body: 'body',
image: 'image',
icon: 'icon'
},
from: 'from',
collapseKey: 'collapse',
messageId: 'mid',
Expand Down Expand Up @@ -77,7 +83,8 @@ describe('externalizePayload', () => {
notification: {
title: 'title',
body: 'body',
image: 'image'
image: 'image',
icon: 'icon'
},
data: {
foo: 'foo',
Expand All @@ -100,7 +107,8 @@ describe('externalizePayload', () => {
notification: {
title: 'title',
body: 'body',
image: 'image'
image: 'image',
icon: 'icon'
},
data: {
foo: 'foo',
Expand Down
5 changes: 5 additions & 0 deletions packages/messaging/src/helpers/externalizePayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ function propagateNotificationPayload(
if (!!image) {
payload.notification!.image = image;
}

const icon = messagePayloadInternal.notification!.icon;
if (!!icon) {
payload.notification!.icon = icon;
}
}

function propagateDataPayload(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface NotificationPayloadInternal extends NotificationOptions {
// See:https://firebase.google.com/docs/cloud-messaging/xmpp-server-ref.
// eslint-disable-next-line camelcase
click_action?: string;
icon?: string;
}

// Defined in
Expand Down
6 changes: 6 additions & 0 deletions packages/messaging/src/interfaces/public-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ export interface NotificationPayload {
* The URL of an image that is downloaded on the device and displayed in the notification.
*/
image?: string;

/**
* The URL to use for the notification's icon. If you don't send this key in the request,
* FCM displays the launcher icon specified in your app manifest.
*/
icon?: string;
}

/**
Expand Down

0 comments on commit e0fabfd

Please sign in to comment.