Skip to content

Commit 9d41b96

Browse files
authored
Do nothing for action clicks (#702)
* Do nothing for action clicks * [AUTOMATED]: Prettier Code Styling * Address comment
1 parent bfa8a5e commit 9d41b96

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

packages/messaging/src/controllers/sw-controller.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,15 @@ export class SWController extends ControllerInterface {
159159
) {
160160
// Not an FCM notification, do nothing.
161161
return;
162+
} else if (event.action) {
163+
// User clicked on an action button.
164+
// This will allow devs to act on action button clicks by using a custom
165+
// onNotificationClick listener that they define.
166+
return;
162167
}
163168

164169
// Prevent other listeners from receiving the event
165170
event.stopImmediatePropagation();
166-
167171
event.notification.close();
168172

169173
const msgPayload: MessagePayload = event.notification.data[FCM_MSG];

packages/messaging/test/sw-controller.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,28 @@ describe('Firebase Messaging > *SWController', () => {
517517
expect(event.stopImmediatePropagation.callCount).to.equal(0);
518518
});
519519

520+
it('should do nothing for action clicks', async () => {
521+
const waitUntilSpy = sandbox.spy();
522+
const event: any = {
523+
notification: {
524+
data: {
525+
FCM_MSG: {
526+
notification: {}
527+
}
528+
},
529+
close: sandbox.spy()
530+
},
531+
waitUntil: waitUntilSpy,
532+
stopImmediatePropagation: sandbox.spy(),
533+
action: 'action1'
534+
};
535+
const swController = new SWController(app);
536+
537+
swController.onNotificationClick(event);
538+
539+
expect(event.stopImmediatePropagation.callCount).to.equal(0);
540+
});
541+
520542
it('should handle FCM notification without a notification data field', async () => {
521543
const waitUntilSpy = sandbox.spy();
522544
const event: any = {

0 commit comments

Comments
 (0)