[🐴] Reset screen when pressing a DM notification while already in the conversation screen (#4091)

* add a small comment

* reset if current screen
zio/stable
Hailey 2024-05-18 12:23:24 -07:00 committed by GitHub
parent d2c81c9d3d
commit 2eaecfcaa4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 26 additions and 4 deletions

View File

@ -59,9 +59,13 @@ export function useNotificationsHandler() {
const {setShowLoggedOut} = useLoggedOutViewControls() const {setShowLoggedOut} = useLoggedOutViewControls()
const closeAllActiveElements = useCloseAllActiveElements() 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(() => { React.useEffect(() => {
if (!isAndroid) return if (!isAndroid) return
Notifications.setNotificationChannelAsync('chat-messages', { Notifications.setNotificationChannelAsync('chat-messages', {
name: 'Chat', name: 'Chat',
importance: Notifications.AndroidImportance.MAX, importance: Notifications.AndroidImportance.MAX,
@ -99,9 +103,27 @@ export function useNotificationsHandler() {
} else { } else {
navigation.dispatch(state => { navigation.dispatch(state => {
if (state.routes[0].name === 'Messages') { if (state.routes[0].name === 'Messages') {
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', { return CommonActions.navigate('MessagesConversation', {
conversation: payload.convoId, conversation: payload.convoId,
}) })
}
} else { } else {
return CommonActions.navigate('MessagesTab', { return CommonActions.navigate('MessagesTab', {
screen: 'Messages', screen: 'Messages',