-
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
Fix: Push notification onyx updates not applied when notification is selected #42510
Fix: Push notification onyx updates not applied when notification is selected #42510
Conversation
@allroundexperts Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
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.
Looks pretty good. I think you're right that we don't have to call DeferredOnyxUpdates.enqueueAndProcess
directly. Also I merged your last PR so be sure to merge main
to clear the old changes on this one.
src/libs/Notification/PushNotification/subscribePushNotification/index.ts
Outdated
Show resolved
Hide resolved
src/libs/Notification/PushNotification/extractDataFromPushNotification.ts
Outdated
Show resolved
Hide resolved
src/libs/Notification/PushNotification/subscribePushNotification/index.ts
Outdated
Show resolved
Hide resolved
src/libs/Notification/PushNotification/subscribePushNotification/index.ts
Outdated
Show resolved
Hide resolved
…on/index.ts Co-authored-by: Andrew Rosiclair <arosiclair@gmail.com>
…ing to report screen
src/libs/Notification/PushNotification/subscribePushNotification/index.ts
Outdated
Show resolved
Hide resolved
src/libs/Notification/PushNotification/subscribePushNotification/index.ts
Show resolved
Hide resolved
// const updates = wrapAirshipUpdatesDataInOnyxUpdatesFromServer({onyxData, lastUpdateID, previousUpdateID}); | ||
// return DeferredOnyxUpdates.enqueueAndProcess(updates); | ||
|
||
return Promise.all(onyxUpdates.map((update) => applyOnyxData(update))); |
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.
On second thought, I think we do need to enqueueAndProcess
these updates as we're applying them in a random order here.
The end goal we're looking for is that all of the push notification updates are sorted and then applied in-order. The DeferredOnyxUpdates queue should be able to do that with enqueueAndProcess
. Does that make sense?
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.
The sorting and processing is actually also achieved by calling applyOnyxData
. This will trigger applyOnyxUpdatesReliably
which will then trigger handleOnyxUpdateGap
and DeferredOnyxUpdates.enqueue
functions consecutively.
Once the deferred updates are being processed by validateAndApplyDeferredUpdates
they will be sorted and applied.
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.
So we're essentially trying to avoid unnecessary calls to handleOnyxUpdateGap
to begin with. For example, let's say our clientLastUpdateID
is 10 and we have push notifications for updates 11-15. Ideally, we would apply them in-order and thus, detect no gaps as we do that.
If we applyOnyxUpdatesReliably
in a random order, the first update will probably be out of order so it will trigger an unnecessary call to handleOnyxUpdateGap
and GetMissingOnyxMessages
. The following updates should just get enqueued and then processed like you said, but that first API call was unnecessary.
So we must sort and apply these updates synchronously and we should be able to do that with enqueueAndProcess
. Do you follow?
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.
gotcha! makes sense
@arosiclair i've updated the PR to use Could you test if this brings the expected output when clicking on push notifications? It's hard to test this on the simulator (as i cannot build the Expensify app with (Remote) push notifications, because i'm not in the Expensify Apple Developer organization) I'm gonna try to mock the push notification with the onyx payload later today, but first i have to work on some other stuff. |
You should be able to test on Android (emulator or device are both fine). I'll give it a test on iOS though. |
src/libs/Notification/PushNotification/subscribePushNotification/index.ts
Outdated
Show resolved
Hide resolved
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.
Alright I did some testing on iOS and have a few findings:
- It's not clear what's going on with the deferred updates queue when just looking at logs. We should add a couple to
enqueue
andprocess
:
Log.info('[DeferredOnyxUpdates] enqueuing updates', false, { lastUpdateIDs: Object.keys(updates)});
Log.info('[DeferredOnyxUpdates] processing updates', false, { lastUpdateIDs: Object.keys(deferredUpdates)});
- It looks like clearReportNotifications is clearing notifications and their payloads before we get to enqueue them. Commenting out that function fixed the issue for me. So we need to just need to get the notifications before navigating. Something like:
function navigateToReport({reportID, reportActionID}) {
Airship.push.getActiveNotifications().then((notifications) => {
// ...
DeferredOnyxUpdates.enqueueAndProcess(onyxUpdates);
Navigation.isNavigationReady().then(...)
}
}
- Even with the above changes, there's still a noticeable delay for the new messages to appear after killing the app, receiving push notifications and tapping one to view the chat. With the force offline toggle enabled, the messages never appear (presumably because the updates were never merged). It's not clear in logs if that's because there's a gap that cannot be filled while offline or another reason.
@chrispader Can you please update the checklist? |
@arosiclair i've applied the changes you suggested and tested it on Android. In my case, the updates from the notifications are already applied when received, therefore they also appear in the report screen when navigated there. Calling (The Airship docs state, that on Android Also, we still have the Is our approach, to "re-apply" all open/active notifications, in case these couldn't be applied (yet) or are missing? |
Since i cannot really test this on iOS, where it seems to be the bigger problem, i'm not sure if i can properly test and work on this PR... Could you test the current state and lmk if i can help with anything further? |
@allroundexperts i completed the checklist so this PR is not blocked by me, but we still have to ensure this works on Android and iOS |
It should work on both. That's what we use for
The idea is that sometimes the
Yeah it might be best for me to take over this PR. I'll put some work on it today |
thanks! |
I'm merging this into my own branch and continuing from there |
98d3570
into
Expensify:arosiclair-push-notif-deferred-updates
New PR is here: #43001 |
@arosiclair
Details
Fixes an issue where
OnyxServerUpdate
's received from push notifications are not applied to Onyx locally, when a notification is selected/clicked.Based on #42044 because it isn't merged yet
Fixed Issues
$ #40227
PROPOSAL:
Tests
Note
test iOS and Android native only
Offline tests
None
QA Steps
Same as Tests
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label and/or tagged@Expensify/design
so the design team can review the changes.ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop