Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose 'icon' field from the Firebase Messaging SDK #6722

Merged
merged 4 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
zwu52 marked this conversation as resolved.
Show resolved Hide resolved
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