Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

Feature request: separate the notification handler into notification-arrived and notification-clicked #428

Open
yoav-zibin opened this issue Dec 15, 2015 · 10 comments
Labels

Comments

@yoav-zibin
Copy link

Hi,
Right now, if I want to use background notifications, then I have to drop the alert/message&title properties:
https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/PAYLOAD.md#background-notifications
So either nothing is shown (background notification, and then the notification handler is called on notification-arrived) or an alert is shown (and the notification handler is called on notification-clicked).

In my use-case (and probably others would want that), I want to both show an alert and handle the notification in the background.
Currently, in order to do that, I need to send two notifications: a background one (without alert property) and another notification with the alert property. It would be great if I can do it in one notification :)

So I propose to decouple the notion of background notification from the existence of an alert property. Instead I propose to have two handlers:

  • on('notification-arrived') handler: when the notification arrives.
  • on('notification-clicked') handler: when the notification is clicked on.
@fredgalvao
Copy link
Collaborator

@fredgalvao
Copy link
Collaborator

This would probably require and benefit from a 2.0 version bump, as the event API would be anew.

@yoav-zibin
Copy link
Author

You can still keep the old
on('notification')
with the same behavior.
Just add two new handlers (notification-arrived and notification-clicked).

This way it's not a breaking change :)

@fredgalvao
Copy link
Collaborator

The notification event would be confusing or redundant, I guess we should actually remove it in favor of the new ones, if we're going that way.

@macdonst
Copy link
Member

@yoav-zibin Take a look at Issue #293. As of release 1.5.0 you'll be able to send a push with an alert/title and still have it call the on('notification') event handler. If this solves your use case please close this issue.

@yoav-zibin
Copy link
Author

Hi, I looked at #293 but it doesn't fit my use-case, because I don't want the notification to be silent.
I need both to get a callback when the notification arrives AND I want to show the notification.

My use-case is a gaming app: the notifications are moves done in different matches (by different opponents). Suppose the app is in the background. Then I want to show ALL notifications, AND also update the app. This way, if the user clicks on one notification, the app shows the right thing for all matches (not just the notification the user clicked on).
The only solution is to have two callbacks (and the only workaround is to send two notifications: a background one to update the state and another one to show the notification).

@macdonst
Copy link
Member

@yoav-zibin but with the code implemented for #293 if content-available is set to 1 with a message/title in your push notification then it shows up in the notification shade and calls the on('notification'). Isn't that exactly the behaviour you want?

@yoav-zibin
Copy link
Author

Thanks for all the help :)
I don't think it will work --- I'll explain why.

First, I didn't realize it will show a notification because the bug said "if the "content-available" property is set to "1" then force it to be a silent notification."

But I still don't think it will work because I need a callback when the user clicks on the notification. See for a given notification I need two callbacks: one when it arrives (to update the state), and one when the user clicks on it (to load the correct match). If you actually call the notification handler twice (when the notification arrives, and when the user clicks on it), then it does work for me :D

E.g., suppose I have two matches with opponent X and opponent Y. And both opponents made a move, so I see two notifications.
Currently, I don't use background notifications, so if I press on the notification of opponent X, then the match with X is loaded, and then if I go back to the main menu of my app then I don't see the correct state with the match with opponent Y.
(Another problematic scenario is if I don't press on any notification and go back to my app, then I don't see the correct state for either match.)
There are actually two workarounds:

  1. When the app goes to foreground (phonegap emits a resume event), then I fetches ALL matches again (which can be expensive, since you may have hundreds of matches). I currently do that if 10 minutes passed since the last "fetch all matches" (so it's not that expensive).
  2. For each update, send two notifications (one for background to update state and one to show the notification).

I looked at your code changes and I wasn't sure whether notification handler will be called twice in this use-case:
First the JSON you send from GCM will need to include "content-available": "1". This will tell the push plugin to call your on('notification') event handler no matter what other data is in the push notification.

 {
    title: "Test Push",
    message: "Push number 1",
+   info: "super secret info",
+   content-available: "1"
 }

@ashah-kaira
Copy link

+1.

I also need to have two callback for notifications. My use-case is a little different but having two callbacks may solve my problem.

I have implemented chat feature in my application. So I only want to show the notification if the user is currently NOT in the chat window.

According to me there should be a "return false" in the on('notification-arrived') handler which will NOT show the notification. If this handler "return true", it should show the notification and when clicked it will trigger on('notification-clicked') handler.

Having "return false" also helps to show the notification according to the settings for the notification. There may be the case when user don't want to see some type of notifications.

Please let me know your thoughts.

@marcelodl
Copy link

Hi, i'm also looking forward for this behaviour on the notification. Any updates? Thank you

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

5 participants