@@ -204,16 +204,31 @@ export function useNavigateBackFromPost() {
204
204
const isWindowNarrow = useIsWindowNarrow ( ) ;
205
205
const navigation = useNavigation ( ) ;
206
206
const length = navigation . getState ( ) ?. routes . length ;
207
- const lastScreenWasActivity =
208
- navigation . getState ( ) ?. routes [ length - 2 ] ?. name === 'Activity' ;
207
+ const lastScreen = navigation . getState ( ) ?. routes [ length - 2 ] ;
208
+ const lastScreenWasActivity = lastScreen ?. name === 'Activity' ;
209
+ // @ts -expect-error - ChannelRoot is fine here.
210
+ const lastScreenWasChannel = lastScreen ?. name === 'ChannelRoot' ;
211
+ const lastChannelWasChat =
212
+ // @ts -expect-error - we know we'll have a channelId here if lastScreenWasChannel
213
+ lastScreenWasChannel && lastScreen ?. params ?. channelId
214
+ ? // @ts -expect-error - we know we'll have a channelId here if lastScreenWasChannel
215
+ lastScreen . params . channelId . startsWith ( 'chat' )
216
+ : false ;
209
217
210
218
return useCallback (
211
219
( channel : db . Channel , postId : string ) => {
220
+ const isChatShaped = [ 'chat' , 'dm' , 'groupDM' ] . includes ( channel . type ) ;
221
+ if ( lastChannelWasChat && ! isChatShaped ) {
222
+ // if we're returning from viewing a notebook/gallery post and the last
223
+ // channel was a chat, we should navigate to the chat instead of the
224
+ // notebook/gallery channel
225
+ navigation . goBack ( ) ;
226
+ return ;
227
+ }
212
228
if ( lastScreenWasActivity ) {
213
229
navigation . navigate ( 'Activity' ) ;
214
230
return ;
215
231
}
216
- const isChatShaped = [ 'chat' , 'dm' , 'groupDM' ] . includes ( channel . type ) ;
217
232
if ( isWindowNarrow ) {
218
233
const screenName = screenNameFromChannelId ( channel . id ) ;
219
234
navigation . navigate ( screenName , {
0 commit comments