Skip to content

Commit

Permalink
Expose 'icon' field from the Firebase Messaging SDK (#6722)
Browse files Browse the repository at this point in the history
* Expose 'icon' field from the Firebase Messaging SDK as part of the 'notification' payload.

Fixes for b/241885017

* Update API reports

* Update lovely-swans-shake.md

* Ran Format.ts
  • Loading branch information
zwu52 committed Oct 25, 2022
1 parent 8f031b4 commit 4b9da74
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 4b9da74

Please sign in to comment.