Skip to content

Commit 4b9da74

Browse files
authored
Expose 'icon' field from the Firebase Messaging SDK (#6722)
* 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
1 parent 8f031b4 commit 4b9da74

File tree

7 files changed

+30
-3
lines changed

7 files changed

+30
-3
lines changed

.changeset/lovely-swans-shake.md

+5
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

common/api-review/messaging-sw.api.md

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export { NextFn }
5252
// @public
5353
export interface NotificationPayload {
5454
body?: string;
55+
icon?: string;
5556
image?: string;
5657
title?: string;
5758
}

common/api-review/messaging.api.md

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export { NextFn }
5555
// @public
5656
export interface NotificationPayload {
5757
body?: string;
58+
icon?: string;
5859
image?: string;
5960
title?: string;
6061
}

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

+11-3
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,12 @@ describe('externalizePayload', () => {
3839
};
3940

4041
const payload: MessagePayload = {
41-
notification: { title: 'title', body: 'body', image: 'image' },
42+
notification: {
43+
title: 'title',
44+
body: 'body',
45+
image: 'image',
46+
icon: 'icon'
47+
},
4248
from: 'from',
4349
collapseKey: 'collapse',
4450
messageId: 'mid',
@@ -77,7 +83,8 @@ describe('externalizePayload', () => {
7783
notification: {
7884
title: 'title',
7985
body: 'body',
80-
image: 'image'
86+
image: 'image',
87+
icon: 'icon'
8188
},
8289
data: {
8390
foo: 'foo',
@@ -100,7 +107,8 @@ describe('externalizePayload', () => {
100107
notification: {
101108
title: 'title',
102109
body: 'body',
103-
image: 'image'
110+
image: 'image',
111+
icon: 'icon'
104112
},
105113
data: {
106114
foo: 'foo',

packages/messaging/src/helpers/externalizePayload.ts

+5
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

+1
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

+6
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)