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

Add 'icon' to '/messaging-types' #6728

Merged
merged 5 commits into from
Nov 1, 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
1 change: 1 addition & 0 deletions packages/messaging-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface NotificationPayload {
title?: string;
body?: string;
image?: string;
icon?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity I looked to see if this package (@firebase/messaging-types) is being used anywhere and it doesn't seem to be? I see it as a dependency in packages/messaging/package.json but I don't see it imported anywhere in the source code. The other instances of [product]-types packages we have are legacy typings that are only used by [product]-compat but messaging-compat doesn't seem to use anything from it, and regular v9 messaging also doesn't. Maybe we could remove it? (in a later PR)

}

export interface FcmOptions {
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