From 04c3533b9503f1439c718b66dfc938f378ca9868 Mon Sep 17 00:00:00 2001 From: Anurag Shivarathri Date: Fri, 28 Oct 2022 14:04:58 +0100 Subject: [PATCH] =?UTF-8?q?[Gekidou=20MM-47224]=20Don=E2=80=99t=20show=20i?= =?UTF-8?q?n=20app=20notifications=20for=20the=20active=20thread=20(#6704)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Conditions fix * Comments fix --- app/init/push_notifications.ts | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/app/init/push_notifications.ts b/app/init/push_notifications.ts index 01cfeee20..e60fc2b69 100644 --- a/app/init/push_notifications.ts +++ b/app/init/push_notifications.ts @@ -95,19 +95,38 @@ class PushNotifications { const isTabletDevice = await isTablet(); const displayName = await queryServerName(DatabaseManager.appDatabase!.database, serverUrl); const channelId = await getCurrentChannelId(database); + const isCRTEnabled = await getIsCRTEnabled(database); let serverName; if (Object.keys(DatabaseManager.serverDatabases).length > 1) { serverName = displayName; } - const isDifferentChannel = payload?.channel_id !== channelId; - const isVisibleThread = payload?.root_id === EphemeralStore.getCurrentThreadId(); - let isChannelScreenVisible = NavigationStore.getNavigationTopComponentId() === Screens.CHANNEL; - if (isTabletDevice) { - isChannelScreenVisible = NavigationStore.getVisibleTab() === Screens.HOME; - } + const isThreadNotification = Boolean(payload?.root_id); - if (isDifferentChannel || (!isChannelScreenVisible && !isVisibleThread)) { + const isSameChannelNotification = payload?.channel_id === channelId; + const isSameThreadNotification = isThreadNotification && payload?.root_id === EphemeralStore.getCurrentThreadId(); + + let isInChannelScreen = NavigationStore.getNavigationTopComponentId() === Screens.CHANNEL; + if (isTabletDevice) { + isInChannelScreen = NavigationStore.getVisibleTab() === Screens.HOME; + } + const isInThreadScreen = NavigationStore.getNavigationTopComponentId() === Screens.THREAD; + + // Conditions: + // 1. If not in channel screen or thread screen, show the notification + const condition1 = !isInChannelScreen && !isInThreadScreen; + + // 2. If is in channel screen, + // - Show notification of other channels + // or + // - Show notification if CRT is enabled and it's a thread notification (doesn't matter if it's the same channel) + const condition2 = isInChannelScreen && (!isSameChannelNotification || (isCRTEnabled && isThreadNotification)); + + // 3. If is in thread screen, + // - Show the notification if it doesn't belong to the thread + const condition3 = isInThreadScreen && !isSameThreadNotification; + + if (condition1 || condition2 || condition3) { DeviceEventEmitter.emit(Navigation.NAVIGATION_SHOW_OVERLAY); const screen = Screens.IN_APP_NOTIFICATION;