static subscribeOnNotificationOpen()

in src/components/push-notifications/push-notifications-processor.ts [19:68]


  static subscribeOnNotificationOpen(
    onSwitchAccount: (account: StorageState, issueId?: string, articleId?: string) => any,
  ) {
    log.info(
      'Push notifications(subscribeOnNotificationOpen:Android): subscribe to open event',
    );

    if (this.registerNotificationOpenListener) {
      this.registerNotificationOpenListener.remove &&
        this.registerNotificationOpenListener.remove();
      this.registerNotificationOpenListener = null;
    }

    this.registerNotificationOpenListener = Notifications.events().registerNotificationOpened(
      async (notification: Notification, completion: () => void) => {
        log.info(`Push notifications: On notification open event`);
        const issueId: string | undefined = helper.getIssueId(notification);
        const articleId: string | undefined = helper.getArticleId(notification);
        if (issueId) {
          log.info(`Push notifications: On notification open:: Issue ID detected`);
        }
        if (articleId) {
          log.info(`Push notifications: On notification open:: Article ID detected`);
        }

        if (!issueId && !articleId) {
          return;
        }

        const targetBackendUrl: string = helper.getBackendURL(notification);
        if (targetBackendUrl) {
          log.info(
            `On notification open:: another account URL is detected`,
          );
        }
        const backendUrl = getStorageState().config!.backendUrl;
        log.info(`On notification open:: current account URL is ${backendUrl}`);
        const targetAccount = await targetAccountToSwitchTo(targetBackendUrl, backendUrl);
        if (targetAccount) {
          await onSwitchAccount(targetAccount, issueId, articleId);
          log.info(`On notification open:: switched to target account`);
        } else if (issueId || articleId) {
          log.info(`On notification open:: redirecting to detected Issue ID`);
          navigateToRouteById(issueId, articleId, helper.getActivityId(notification));
        }

        completion();
      },
    );
  }