@@ -3,9 +3,10 @@ import {
33 PostData ,
44 usePolycentric ,
55} from '@/src/common/lib/polycentric-hooks' ;
6+ import { getKeyFingerprint } from '@/src/common/lib/polycentric-hooks/helpers' ;
67import { invalidateQuery } from '@/src/common/query/hooks/useQuery' ;
78import { COLLECTION , v2 , SyncStrategy } from '@polycentric/react-native' ;
8- import { router , useSegments } from 'expo-router' ;
9+ import { router , useLocalSearchParams , useSegments } from 'expo-router' ;
910import { feedQueryKeys } from '../../feed/hooks/feedCache' ;
1011import { threadQueryKey } from './useThread' ;
1112
@@ -29,6 +30,12 @@ export default function usePostActions(post: PostData): PostActions {
2930 const client = usePolycentric ( ) ;
3031 const segments = useSegments ( ) ;
3132
33+ const { identityId, keyFingerprint, sequence } = useLocalSearchParams < {
34+ identityId ?: string ;
35+ keyFingerprint ?: string ;
36+ sequence ?: string ;
37+ } > ( ) ;
38+
3239 // Tombstone the event identified by `hexEventKey` (a FEED-collection
3340 // Delete referencing it).
3441 const deleteEventAtKey = async ( hexEventKey : string ) => {
@@ -74,9 +81,23 @@ export default function usePostActions(post: PostData): PostActions {
7481 invalidateFeeds ( post . identity ) ;
7582 invalidateThreads ( post . reply ) ;
7683
77- if ( segments [ 0 ] === '[identityId]' && segments [ 1 ] === 'post' ) {
78- // Redirect to profile
79- router . navigate ( '../../' ) ;
84+ // We want to change the active page if we are currently viewing the post
85+ // that just got deleted:
86+
87+ const onPostScreen =
88+ segments [ 0 ] === '[identityId]' && segments [ 1 ] === 'post' ;
89+
90+ const isSubject =
91+ post . identity === identityId &&
92+ getKeyFingerprint ( post . signedBy ) === keyFingerprint &&
93+ post . sequence === sequence ;
94+
95+ if ( onPostScreen && isSubject ) {
96+ if ( router . canGoBack ( ) ) {
97+ router . back ( ) ;
98+ } else {
99+ router . replace ( '../../' ) ;
100+ }
80101 return ;
81102 }
82103 } ,
0 commit comments