From 4f1db0e63970d00d7210eacd023c319b0926c9ff Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 4 Sep 2024 15:18:42 +0200 Subject: [PATCH] MOBILE-4359 localnotifications: Fix open local notif when app is dead --- .../services/pushnotifications.ts | 1 + src/core/services/local-notifications.ts | 28 +++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/core/features/pushnotifications/services/pushnotifications.ts b/src/core/features/pushnotifications/services/pushnotifications.ts index 92b8b21ef..0ac678149 100644 --- a/src/core/features/pushnotifications/services/pushnotifications.ts +++ b/src/core/features/pushnotifications/services/pushnotifications.ts @@ -444,6 +444,7 @@ export class CorePushNotificationsProvider { async notificationClicked(data: CorePushNotificationsNotificationBasicData): Promise { await ApplicationInit.donePromise; + // This code is also done when clicking local notifications. If it's modified, it should be modified in there too. if (CoreSites.isLoggedIn()) { CoreSites.runAfterLoginNavigation({ priority: 600, diff --git a/src/core/services/local-notifications.ts b/src/core/services/local-notifications.ts index 77608781e..06daa1eea 100644 --- a/src/core/services/local-notifications.ts +++ b/src/core/services/local-notifications.ts @@ -23,7 +23,7 @@ import { CoreText } from '@singletons/text'; import { CoreQueueRunner } from '@classes/queue-runner'; import { CoreError } from '@classes/errors/error'; import { CoreConstants } from '@/core/constants'; -import { makeSingleton, NgZone, Translate, LocalNotifications } from '@singletons'; +import { makeSingleton, NgZone, Translate, LocalNotifications, ApplicationInit } from '@singletons'; import { CoreLogger } from '@singletons/logger'; import { APP_SCHEMA, @@ -42,6 +42,9 @@ import { AsyncInstance, asyncInstance } from '@/core/utils/async-instance'; import { CoreDatabaseTable } from '@classes/database/database-table'; import { CoreDatabaseCachingStrategy, CoreDatabaseTableProxy } from '@classes/database/database-table-proxy'; import { CoreDomUtils } from './utils/dom'; +import { CoreSites } from './sites'; +import { CoreNavigator } from './navigator'; +import { CoreWait } from '@singletons/wait'; /** * Service to handle local notifications. @@ -87,7 +90,28 @@ export class CoreLocalNotificationsProvider { this.handleEvent('trigger', notification); }); - this.clickSubscription = LocalNotifications.on('click').subscribe((notification: ILocalNotification) => { + this.clickSubscription = LocalNotifications.on('click').subscribe(async (notification: ILocalNotification) => { + await ApplicationInit.donePromise; + + // This code is also done when clicking push notifications. If it's modified, it should be modified in there too. + if (CoreSites.isLoggedIn()) { + CoreSites.runAfterLoginNavigation({ + priority: 0, // Use a low priority because the execution of this process doesn't block the next ones. + callback: async () => { + this.handleEvent('click', notification); + }, + }); + + return; + } + + // User not logged in, wait for the path to be a "valid" path (not a parent path used when starting the app). + await CoreWait.waitFor(() => { + const currentPath = CoreNavigator.getCurrentPath(); + + return currentPath !== '/' && currentPath !== '/login'; + }, { timeout: 400 }); + this.handleEvent('click', notification); });