Skip to content

Commit 4f1db0e

Browse files
committed
MOBILE-4359 localnotifications: Fix open local notif when app is dead
1 parent 0e6058a commit 4f1db0e

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/core/features/pushnotifications/services/pushnotifications.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ export class CorePushNotificationsProvider {
444444
async notificationClicked(data: CorePushNotificationsNotificationBasicData): Promise<void> {
445445
await ApplicationInit.donePromise;
446446

447+
// This code is also done when clicking local notifications. If it's modified, it should be modified in there too.
447448
if (CoreSites.isLoggedIn()) {
448449
CoreSites.runAfterLoginNavigation({
449450
priority: 600,

src/core/services/local-notifications.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { CoreText } from '@singletons/text';
2323
import { CoreQueueRunner } from '@classes/queue-runner';
2424
import { CoreError } from '@classes/errors/error';
2525
import { CoreConstants } from '@/core/constants';
26-
import { makeSingleton, NgZone, Translate, LocalNotifications } from '@singletons';
26+
import { makeSingleton, NgZone, Translate, LocalNotifications, ApplicationInit } from '@singletons';
2727
import { CoreLogger } from '@singletons/logger';
2828
import {
2929
APP_SCHEMA,
@@ -42,6 +42,9 @@ import { AsyncInstance, asyncInstance } from '@/core/utils/async-instance';
4242
import { CoreDatabaseTable } from '@classes/database/database-table';
4343
import { CoreDatabaseCachingStrategy, CoreDatabaseTableProxy } from '@classes/database/database-table-proxy';
4444
import { CoreDomUtils } from './utils/dom';
45+
import { CoreSites } from './sites';
46+
import { CoreNavigator } from './navigator';
47+
import { CoreWait } from '@singletons/wait';
4548

4649
/**
4750
* Service to handle local notifications.
@@ -87,7 +90,28 @@ export class CoreLocalNotificationsProvider {
8790
this.handleEvent('trigger', notification);
8891
});
8992

90-
this.clickSubscription = LocalNotifications.on('click').subscribe((notification: ILocalNotification) => {
93+
this.clickSubscription = LocalNotifications.on('click').subscribe(async (notification: ILocalNotification) => {
94+
await ApplicationInit.donePromise;
95+
96+
// This code is also done when clicking push notifications. If it's modified, it should be modified in there too.
97+
if (CoreSites.isLoggedIn()) {
98+
CoreSites.runAfterLoginNavigation({
99+
priority: 0, // Use a low priority because the execution of this process doesn't block the next ones.
100+
callback: async () => {
101+
this.handleEvent('click', notification);
102+
},
103+
});
104+
105+
return;
106+
}
107+
108+
// User not logged in, wait for the path to be a "valid" path (not a parent path used when starting the app).
109+
await CoreWait.waitFor(() => {
110+
const currentPath = CoreNavigator.getCurrentPath();
111+
112+
return currentPath !== '/' && currentPath !== '/login';
113+
}, { timeout: 400 });
114+
91115
this.handleEvent('click', notification);
92116
});
93117

0 commit comments

Comments
 (0)