Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Attempt to fix push notification #572

Merged
merged 3 commits into from
Jul 9, 2020
Merged

Conversation

henrytao-me
Copy link
Contributor

@henrytao-me henrytao-me commented Jul 9, 2020

This PR attempts to fix push notification.

What could when wrong on master?

Initial state is incorrect:

Since we start persisting exposure status, we split start into start and init. Because the initial state is retrieved from local storage, it is async. So, if the app is running in background (through background job), master just call updateExposureStatusInBackground without calling init. Based on this assumption,

  1. On Android: ✅
    We call init before calling updateExposureStatusInBackground which means Android should receive notification. If there is no notification, it could be different issue.

  2. On iOS: ❌
    We don't call init in backgroundScheduler.registerPeriodicTask which means in some race condition, iOS won't have correct initial state.

Logic to show notification:

Also the logic for showing exposed notification is quite fragile to break https://github.com/cds-snc/covid-shield-mobile/blob/master/src/services/ExposureNotificationService/ExposureNotificationService.ts#L151. Essentially, we want to send exposure notification to user only once but the way we are doing it is checking the status from monitoring to exposed.

This will break when: If user finishes onboarding and minimize the app, the app still runs in but without updateExposureStatusInBackground. It means if the status is changed to exposed, the next time updateExposureStatusInBackground is run, it won't show notification. In this case, user doesn't know that the app is set to exposed already.

Ref #570

@henrytao-me henrytao-me requested a review from a team as a code owner July 9, 2020 15:12
@@ -31,7 +31,6 @@ BackgroundScheduler.registerAndroidHeadlessPeriodicTask(async () => {
SecureStorage,
ExposureNotification,
);
await exposureNotificationService.init();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is moved to updateExposureStatusInBackground

await this.updateExposureStatus();
const currentStatus = this.exposureStatus.get();
if (lastStatus.type === 'monitoring' && currentStatus.type === 'exposed') {
if (currentStatus.type === 'exposed' && !currentStatus.notificationSent) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change logic of showing notification. This making sure that we show exposed notification once.

Copy link
Contributor Author

@henrytao-me henrytao-me left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of notes for reviewing 🙇

@henrytao-me henrytao-me merged commit 4d3c491 into master Jul 9, 2020
@henrytao-me henrytao-me deleted the issue/570/push-notification branch July 9, 2020 18:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants