Skip to content

Commit 2110a91

Browse files
committed
Expose 'icon' field from the Firebase Messaging SDK as part of the 'notification' payload.
Fixes for b/241885017
1 parent 8f031b4 commit 2110a91

File tree

5 files changed

+23
-3
lines changed

5 files changed

+23
-3
lines changed

.changeset/lovely-swans-shake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/messaging': minor
3+
---
4+
5+
Expose 'icon' field from the Firebase Messaging SDK as part of the 'notification' payload.

packages/messaging/src/helpers/externalizePayload.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe('externalizePayload', () => {
2727
title: 'title',
2828
body: 'body',
2929
image: 'image',
30+
icon: 'icon',
3031
// eslint-disable-next-line camelcase
3132
click_action: 'https://www.self_orgin.com'
3233
},
@@ -38,7 +39,7 @@ describe('externalizePayload', () => {
3839
};
3940

4041
const payload: MessagePayload = {
41-
notification: { title: 'title', body: 'body', image: 'image' },
42+
notification: { title: 'title', body: 'body', image: 'image', icon: 'icon' },
4243
from: 'from',
4344
collapseKey: 'collapse',
4445
messageId: 'mid',
@@ -77,7 +78,8 @@ describe('externalizePayload', () => {
7778
notification: {
7879
title: 'title',
7980
body: 'body',
80-
image: 'image'
81+
image: 'image',
82+
icon: 'icon'
8183
},
8284
data: {
8385
foo: 'foo',
@@ -100,7 +102,8 @@ describe('externalizePayload', () => {
100102
notification: {
101103
title: 'title',
102104
body: 'body',
103-
image: 'image'
105+
image: 'image',
106+
icon: 'icon'
104107
},
105108
data: {
106109
foo: 'foo',

packages/messaging/src/helpers/externalizePayload.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ function propagateNotificationPayload(
6060
if (!!image) {
6161
payload.notification!.image = image;
6262
}
63+
64+
const icon = messagePayloadInternal.notification!.icon;
65+
if (!!icon) {
66+
payload.notification!.icon = icon;
67+
}
6368
}
6469

6570
function propagateDataPayload(

packages/messaging/src/interfaces/internal-message-payload.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export interface NotificationPayloadInternal extends NotificationOptions {
3838
// See:https://firebase.google.com/docs/cloud-messaging/xmpp-server-ref.
3939
// eslint-disable-next-line camelcase
4040
click_action?: string;
41+
icon?: string;
4142
}
4243

4344
// Defined in

packages/messaging/src/interfaces/public-types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ export interface NotificationPayload {
3838
* The URL of an image that is downloaded on the device and displayed in the notification.
3939
*/
4040
image?: string;
41+
42+
/**
43+
* The URL to use for the notification's icon. If you don't send this key in the request,
44+
* FCM displays the launcher icon specified in your app manifest.
45+
*/
46+
icon?: string;
4147
}
4248

4349
/**

0 commit comments

Comments
 (0)