firebase / firebase/firebase-js-sdk

FR: Differentiate Click vs Receive Notification in Window Messaging Controller

Open
#294 0 comments 0 reactions 0 assignees View on GitHub
api: messaging feature request
Dominant language
TypeScript
Stars
5.1k
Forks
1k
Avg merge
2d 21h
Merged PRs (30d)
37

Description

### [REQUIRED] Describe your environment

* Operating System version: _____Angular 4.4.4
* Firebase SDK version: _____Firebase 4.5.0
* Firebase Product: _____ messaging

### [REQUIRED] Describe the problem
I have a use case that I want to refresh the content on the page if the user is not currently using the page. If they are on the page I don't want to interrupt their workflow. The problem is that both the notification click and received go through the same onMessage subscriber.

Looking at the code, I don't see how I can achieve that without abandoning a good portion of Firebase messaging. If we could add some indicator in the onMessage() callback to indicate the source of the message, it would be help in handling the events separately.

#### Steps to reproduce:
Add callback to Firebase.messaging().onMessage().

Notice that the same code 'attemptToMessageClient_' gets called for both the 'onNotificationClick_' and 'onPush_' in sw-controller.ts. From there, the messaged is handled by the event listener registered in 'setupSWMessageListener_' in window-controller.ts. You can see that the two events call the same messageObserver_ which routes the same to onMessage that the client registers.

#### Relevant Code:

Contributor guide

Open the contributing guide

Research direction

Start in sw-controller.ts at attemptToMessageClient_, comparing the onNotificationClick_ and onPush_ paths. Then trace setupSWMessageListener_ and messageObserver_ in window-controller.ts to understand how both events reach onMessage. Done means the onMessage callback can distinguish notification clicks from received messages without losing the existing messaging flow.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.