From 2eaecfcaa49088b8a7172a7f1325506714a4b379 Mon Sep 17 00:00:00 2001 From: Hailey Date: Sat, 18 May 2024 12:23:24 -0700 Subject: [PATCH] =?UTF-8?q?[=F0=9F=90=B4]=20Reset=20screen=20when=20pressi?= =?UTF-8?q?ng=20a=20DM=20notification=20while=20already=20in=20the=20conve?= =?UTF-8?q?rsation=20screen=20(#4091)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add a small comment * reset if current screen --- src/lib/hooks/useNotificationHandler.ts | 30 +++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/lib/hooks/useNotificationHandler.ts b/src/lib/hooks/useNotificationHandler.ts index f3c4da7f..347062be 100644 --- a/src/lib/hooks/useNotificationHandler.ts +++ b/src/lib/hooks/useNotificationHandler.ts @@ -59,9 +59,13 @@ export function useNotificationsHandler() { const {setShowLoggedOut} = useLoggedOutViewControls() const closeAllActiveElements = useCloseAllActiveElements() + // On Android, we cannot control which sound is used for a notification on Android + // 28 or higher. Instead, we have to configure a notification channel ahead of time + // which has the sounds we want in the configuration for that channel. These two + // channels allow for the mute/unmute functionality we want for the background + // handler. React.useEffect(() => { if (!isAndroid) return - Notifications.setNotificationChannelAsync('chat-messages', { name: 'Chat', importance: Notifications.AndroidImportance.MAX, @@ -99,9 +103,27 @@ export function useNotificationsHandler() { } else { navigation.dispatch(state => { if (state.routes[0].name === 'Messages') { - return CommonActions.navigate('MessagesConversation', { - conversation: payload.convoId, - }) + if ( + state.routes[state.routes.length - 1].name === + 'MessagesConversation' + ) { + return CommonActions.reset({ + ...state, + routes: [ + ...state.routes.slice(0, state.routes.length - 1), + { + name: 'MessagesConversation', + params: { + conversation: payload.convoId, + }, + }, + ], + }) + } else { + return CommonActions.navigate('MessagesConversation', { + conversation: payload.convoId, + }) + } } else { return CommonActions.navigate('MessagesTab', { screen: 'Messages',