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

Commit

Permalink
Merge pull request #572 from cds-snc/issue/570/push-notification
Browse files Browse the repository at this point in the history
Attempt to fix push notification
  • Loading branch information
henrytao-me authored Jul 9, 2020
2 parents d598211 + d17022f commit 4d3c491
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ BackgroundScheduler.registerAndroidHeadlessPeriodicTask(async () => {
SecureStorage,
ExposureNotification,
);
await exposureNotificationService.init();
await exposureNotificationService.updateExposureStatusInBackground();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export type ExposureStatus =
| {
type: 'exposed';
summary: ExposureSummary;
notificationSent?: boolean;
lastChecked?: {
period: number;
timestamp: number;
Expand Down Expand Up @@ -113,11 +114,6 @@ export class ExposureNotificationService {
});
}

async init() {
const exposureStatus = JSON.parse((await this.storage.getItem(EXPOSURE_STATUS)) || 'null');
this.exposureStatus.append({...exposureStatus});
}

async start(): Promise<void> {
if (this.starting) {
return;
Expand Down Expand Up @@ -145,14 +141,17 @@ export class ExposureNotificationService {
}

async updateExposureStatusInBackground() {
const lastStatus = this.exposureStatus.get();
await this.init();
await this.updateExposureStatus();
const currentStatus = this.exposureStatus.get();
if (lastStatus.type === 'monitoring' && currentStatus.type === 'exposed') {
if (currentStatus.type === 'exposed' && !currentStatus.notificationSent) {
PushNotification.presentLocalNotification({
alertTitle: this.i18n.translate('Notification.ExposedMessageTitle'),
alertBody: this.i18n.translate('Notification.ExposedMessageBody'),
});
await this.exposureStatus.append({
notificationSent: true,
});
}
if (currentStatus.type === 'diagnosed' && currentStatus.needsSubmission) {
PushNotification.presentLocalNotification({
Expand Down Expand Up @@ -198,6 +197,11 @@ export class ExposureNotificationService {
await this.recordKeySubmission();
}

private async init() {
const exposureStatus = JSON.parse((await this.storage.getItem(EXPOSURE_STATUS)) || 'null');
this.exposureStatus.append({...exposureStatus});
}

/**
* If the exposureConfiguration is not available from the server for some reason,
* try and use a previously stored configuration, or use the default configuration bundled with the app.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export const ExposureNotificationServiceProvider = ({
);

useEffect(() => {
backgroundScheduler.registerPeriodicTask(() => {
return exposureNotificationService.updateExposureStatusInBackground();
backgroundScheduler.registerPeriodicTask(async () => {
await exposureNotificationService.updateExposureStatusInBackground();
});
}, [backgroundScheduler, exposureNotificationService]);

Expand Down

0 comments on commit 4d3c491

Please sign in to comment.