-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Setup push notifications #424
Conversation
# Conflicts: # ios/Podfile.lock # ios/ReactNativeChat.xcodeproj/project.pbxproj # src/Expensify.js # src/lib/Notification/BrowserNotifications.js
Regarding your discussion: I'd suggest we just follow what the API currently does which triggers native (iOS/Android) notifications from our Expensify API to the Urban Airship API. Then keep the web browser the same using local notifications via pusher. The only difference I'd suggest is let's create a new project in Airship and send these pushes separately from our main Expensify app/Airship keys. |
So today has been pretty successful in that I've been able to get test push notifications showing up on the device. I've also set up notifications to appear in the foreground by default, but we will likely not want to show push notifications for chat reports which are already visible. I've also laid the groundwork by which the currently signed-in user registers for Airship notifications. We probably don't need to worry about edge cases where a copilot logs in, right? I'm unsure how to reconcile differences between pusher and Airship, because they serve similar purposes in our united codebase. For example, if a chat is sent, our API would send a notification via pusher and Airship, and the app needs to be able to determine which notification to respond to/display. Here are some ideas:
|
I think |
I think we might also experience a lot of latency since all data would be arriving via Airship on mobile which I'd guess is "less real-time" than Pusher (but open to being proved wrong on that). |
Agreed, I don't think co-pilot is on the road map.
This feels like the better option to me (and it sounds like others agree on this being better as well) |
How do we handle 2 on the current Expensify app? We have both Airship and Pusher co-exist. |
Actually, I don't really even think this is an option. Local notifications are only relevant if the app is not in the foreground. If it is then we don't want to show them. At least last time we looked into this Pusher doesn't seem to work at all once an app is backgrounded. |
IIRC here's what we do on mobile today:
|
I was able to get remote push notifications displaying in the foreground earlier today (although I read it's only possible on iOS 10+). I think we could get this working with local notifications too. |
android/build.gradle
Outdated
@@ -14,6 +14,8 @@ buildscript { | |||
} | |||
dependencies { | |||
classpath("com.android.tools.build:gradle:3.5.3") | |||
classpath("com.google.gms:google-services:4.2.0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to use 4.3.4 here? Just asking b/c I'm also adding this in this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no opinion here - again, I didn't write any of this config stuff manually.
# Conflicts: # ios/ReactNativeChat.xcodeproj/project.pbxproj # src/lib/API.js # src/lib/actions/Report.js
Went through and fixed a few more bugs, retested on all platforms, and then merged master. Ready for more reviews 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM, found an issue during tests:
- Push notifications are showing up on my physical iPhone even when I have the chat open. If I am on Account A on mobile, viewing a chat with Account B, and I type a message on web from Account B, the message shows up on mobile and then a few seconds later a push notification appears for that message.
- If I am on Account A viewing a chat with Account B, and Account C sends me a message, I see a push notification. Tapping on that push notification doesn't bring me to the chat w/ Account C. I'm assuming there just shouldn't be a notification shown in this case, and if so the fix for 1 will remove this case
Hmmm that's pretty strange: at one point I had to intentionally write code to make notifications appear in the foreground, and since removing it I haven't seen any appear in the foreground. I'll have to look into that. #2 is feature, not a bug haha (if we receive a push notification while the app is in the foreground, we assume we're connected to pusher so we don't execute any callbacks) |
Okay, so I'm seeing the same thing on my end, but I'm not sure how to resolve it. This is controlled by the OS, and I think it is a problem with UrbanAirship's React Native SDK. So I opened a GH issue to hopefully get a solution. You can read up on the issue for steps I took to attempt to resolve this, and if you have any other ideas for things I could try I'm all ears. In the meantime, maybe what we should do is allow callbacks to execute for notifications received in the foreground so that tapping on the notification will open the correct report, then merge this PR and create a separate issue to disable foreground notifications. In my opinion, the benefits of having functional push notifications probably outweigh the potential inconveniences of having them display in the foreground while I investigate and try to resolve it. |
Does this mean that when you are chatting with someone each new message from them will trigger a notification in the foreground? |
Yes, on iOS |
4a1e56c
to
60865d7
Compare
if (AppState.currentState === 'active' && eventType === EventType.PushReceived) { | ||
console.debug('[PUSH_NOTIFICATION] Push received while app is in foreground, not executing any callback.'); | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm understanding this problem correctly... I think we could handle this before calling pushNotificationEventCallback(EventType.PushReceived, notification)
.
There's a lot of explanation going on here and I think at the end of the day all that needs to be said is what was there already. The selected event should always do the callback. Said another way, whether or not notifications show in the foreground wouldn't make a difference - they just happen to be showing and they should not show.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scaled back this comment because you're right, we should only repress the callback for PushReceived
events because those are the only ones that will be duplicates with pusher
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify I was suggesting we do something like this...
UrbanAirship.addListener(EventType.PushReceived, (notification) => {
// If a push notification is received while the app is in foreground,
// we'll assume pusher is connected so we'll ignore is and not fetch the same data twice.
if (AppState.currentState === 'active') {
console.debug('[PUSH_NOTIFICATION] Push received while app is in foreground, not executing any callback.');
return;
}
pushNotificationEventCallback(EventType.PushReceived, notification);
});
and remove everything from this method.
Following this discussion I've set up push notification callbacks so that NotificationResponse event callbacks can be triggered when the app is in the foreground. So if you have chat A open and you get a foreground notification for chat B, then tapping it will open chat B. If you have chat A open and you get a foreground notification for chat A, then tapping it has no effect. We still do not allow callbacks to execute on a PushReceived event when the app is in the foreground, because we are operating under the assumption that pusher is also connected so we don't need to fetch the same data twice. All this is to say, this is ready for another round of reviews. After a big merge, I retested all platforms and aside from the known issue with foreground notifications everything is working as expected. |
Actually putting this on HOLD because it sounds like a fix for this should be pretty imminent, according to this comment |
FYI don't mind where this landed and would merge as is. Once the lib is patched I'm pretty sure the solution will be to just "update" it. |
Okay, sure. Let's do it 👍 |
this.animationTranslateX = new Animated.Value(!this.state.hamburgerShown ? -300 : 0); | ||
|
||
// Note: This null check is only necessary because withIon passes null for bound props | ||
// that are null-initialized initialized in Ion, and defaultProps only replaces for `undefined` values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make a follow up issue for this and discuss. This keeps popping up.
Fixes: #288
Details
urbanairship-react-native
)If user has already granted or denied permissions for user notifications, this code not affect the user at all.
From the Airship docs:
Even if the user denies permission for 'user notifications', we will still be able to send push notifications to trigger update actions in the background.
IONKEYS.SESSION.accountID
. When the user signs in, theSESSION.accountID
is assigned, and the registration is triggered. When the user signs out, we clear Ion, theSESSION.accountID
is nullified, and the deregistration is triggered. However, we weren't executing the callbacks for Ion subscribers when we calledIon.clear()
, so this PR implements that as well.Tests / QA
expensify.com.dev
as a different user, and submit an expense report to the account you used in step 2.npm run desktop
, and use the desktop UI to sign into another account.$EXPENSIDEV/script/clitools push:reportComment
, follow the prompts, and verify that you see the push notification show up.