-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Background push notification processing #3877
Conversation
Going to need to HOLD on a Web-E PR to make sure that we're passing |
@roryabraham did you want an early review on this or should I wait until the HOLD comes off? |
@nickmurray47 Feel free to review when you're ready! Just holding on the deployment of the API changes. |
Not sure why PullerBear got a bit trigger-happy there @Luke9389, feel free to ignore. |
Hooray, I was able to observe the iOS app being awoken and updating Onyx when the app was completely closed 🎉. It certainly does not happen consistently, even when the app is only backgrounded and not closed, but there is nothing we can do to side-step the OS limitations on |
Going through the testing steps now |
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.
Had a couple questions, but the code LGTM as far as I can tell. Still running through the testing steps.
@nickmurray47 Let me know if you have any more questions here |
@nickmurray47 If you are running through the testing steps, you'll need to checkout this PR on Web-E for it to work. |
Also, @nickmurray47 I added some testing steps for iOS, since this fixes some push notification issues on iOS as well. |
Figured I was missing something like this! Will test the new iOS steps today |
cc @AndrewGable if you're interested |
# Conflicts: # ios/Podfile.lock
Sorry to muddy up the git history, those last changes were meant to go to another PR. They've been removed from this one. |
Sorry to hold up this PR -- I would like to review and test this properly but have just not had the time to get to additional reviews today. |
Re-ran through all the test steps and now navigating to the exact chat from a notification works great! One thing I just noticed (and not sure if this is by design) but it seems like the notification only pops up when I've fully closed the app. If I just switch to a different chat, background it, and receive a new message then no notification comes up. |
I experienced something similar but it was more like... a lag or something where it just took several seconds for the notification to appear. |
Cool, wanted to make a note of that. The code looks good to me, very nicely done. |
Thanks for retesting @nickmurray47! This sounds like it could be a separate issue ... unless you change some of the code, Web-Expensify will send a silent push notification if it still thinks you're connected via pusher. Might be addressed over here. |
Yeah, that will be solved by this issue Rory linked. |
globals: { | ||
__DEV__: 'readonly', | ||
}, |
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.
What is this for?
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.
__DEV__
is a global variable in RN, and this tells ESLint that so that we can remove some unnecessary ESLint suppressions. Not too closely related to this PR, just a bit of housekeeping.
@@ -26,6 +26,7 @@ | |||
<key>CFBundleURLSchemes</key> | |||
<array> | |||
<string>expensify-cash</string> |
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.
Do we still need the old URLScheme? Are you aware of any code that still uses this?
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'm not aware of any code that still uses this, but I know we have some code that links back-and-forth between OldDot and NewDot and I don't want to break anything in this PR by removing it.
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 can create a FP follow-up to remove this and any usages across all our repos (probably just E/App and Web-Expensify).
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.
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.
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.
Cool, this is working really well! (I tested an Android physical device)
I'm not sure if this is helpful at all, but saw some comments about headless tasks... the whole headless JS thing is necessary because Android is so protective of UI threads. The only way to render anything on Android is via a UI thread, and ignoring some exceptions we are not granted access to these threads outside of an Activity. Services allow us to run code in the background but don't provide access to the UI thread and are restricted by the OS, hence why ReactNative Headless tasks extend from Service, doesn't have access to the App context, and cannot make any UI changes.
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to staging by @roryabraham in version: 1.0.91-1 🚀
|
This issue is failing this PR #5022 |
@isagoico Can we please retest this PR with the following testing steps:
|
Just tested this on Android with the new steps and it was a pass 🎉 Checking it off |
🚀 Deployed to production by @roryabraham in version: 1.0.92-0 🚀
|
@isagoico, when you get a chance can you please confirm that the testing steps from this PR are included in our regression suite? |
Details
This pull request makes it so that push notifications received when the Android app is closed will update Onyx, within the bounds of certain OS restrictions. This is important to achieve a background data trickle, and update the mobile app with chat data as frequently as possible.
On Android, push notifications received when the app is closed will wake a headless JS process (that lives in the UrbanAirship RN sdk) and execute a JS callback. However, it will not mount any RN components, so the push notification callbacks must be registered outside of any React lifecycle. Because the callback is dependent on the Onyx store, we must also initialize that outside of any React lifecycle. Fortunately, that works just fine for our application 😁
Fixed Issues
$ (partial) https://github.com/Expensify/Expensify/issues/158830
Tests
This is a bit of a doozy to test. It will be native-only, with only regression testing on other platforms.
Get a prod build running – Android
Follow the instructions in this SO to generate a signing key and provide it to the app through
build.gradle
.Open
android/app/src/main/assets/airshipconfig.properties
. Swap out theproductionAppKey
andproductionAppSecret
with thedevelopmentAppKey
anddevelopmentAppSecret
.Run
npm i
Run
react-native start --reset-cache
. Kill this command once you see the cache has been cleared.Run
cd android && ./gradlew clean
Open your Android emulator and make sure to fully uninstall any Expensify.cash app on there.
Run
npm run android -- --variant=release
.Once that runs, verify that you do not see any logs in the metro window that opens. Kill the metro window, and verify that you can still view the app. Close the app (hit the square button and swipe up), then reopen it. It should still work.
Get a prod build running – iOS
npm i -g ios-deploy
Expensify.cash
project configurations, clickSigining and Capabilities
, and click "Enable Automatic". This will make some temporary changes that must not be committed, but for me are always necessary to get the app to launch on a physical device.npm run ios -- --configuration Release --device "Your Device Name"
Test push notifications (both platforms)
Tail your VM logs for
[Report] Handled event sent by Airship
. This will indicate that the push notification callback executed.Run
npm run web
(you pick)Sign into account A on the mobile app. Sign into account B on the web app. These should be accounts on your VM, not prod accounts.
Send a message from account B to account A. It should arrive normally.
Send a reply from account A to account B. It should arrive normally.
As user A, open a different chat, and background the app.
Send a message from B to A. A push notification should appear, and a log line demonstrating that the callback occurred should also appear.
Put the emulator/device on airplane mode.
Double-tap the notification. It should open E.cash to the correct chat, and the message should be available.
Take the emulator/device off airplane mode.
(android only) Open the emulator settings, then go to
Security
->Screen Lock
->Swipe
.Hit the power button on the emulator menu (or lock button on the iPhone) to lock the emulator/device:
Send a message from B to A. A push notification should appear, and a log line demonstrating that the callback occurred should also appear.
Put the emulator/device on airplane mode.
Double-tap the notification. It should open E.cash to the correct chat, and the new message should be available.
Hit the square button and swipe up to close E.cash entirely.
Send a message from B to A. A push notification should appear, and a log line demonstrating that the callback occurred should also appear.
Put the emulator/device on airplane mode.
Double-tap the notification. It should open E.cash to the correct chat, and the new message should be available.
QA Steps
Security
->Screen Lock
->Swipe
(doesn't have to be swipe – just make sure you can see a lock screen on the device).Tested On
Screenshots
Web
Mobile Web
Desktop
iOS
Android
....Will need to gather screen recordings after the long weekend.