@@ -9,6 +9,7 @@ import { Keyboard, StyleSheet, useWindowDimensions, View } from 'react-native';
99import { LinearGradient } from 'expo-linear-gradient' ;
1010import { BottomSheetModal } from '@gorhom/bottom-sheet' ;
1111import { KeyboardStickyView } from 'react-native-keyboard-controller' ;
12+ import { router } from 'expo-router' ;
1213import Animated , {
1314 useAnimatedStyle ,
1415 useSharedValue ,
@@ -94,6 +95,7 @@ export default function ChatScreen({
9495 isGenerating,
9596 sendChatMessage,
9697 loadModel,
98+ setActiveChatId,
9799 model : loadedModel ,
98100 } = useLLMStore ( ) ;
99101 const { getModelById } = useModelStore ( ) ;
@@ -153,14 +155,21 @@ export default function ChatScreen({
153155 const hasDocuments = attachments ?. some ( ( a ) => a . type === 'document' ) ;
154156 if ( ( ! userInput . trim ( ) && ! imagePath && ! hasDocuments ) || isGenerating )
155157 return ;
156- if ( ! ( await checkIfChatExists ( db , chatId ! ) ) ) {
158+
159+ let targetChatId = chatId ! ;
160+ if ( ! ( await checkIfChatExists ( db , targetChatId ) ) ) {
157161 const docName = attachments ?. find ( ( a ) => a . type === 'document' ) ?. name ;
158162 const titleSource = userInput . trim ( ) || docName || 'New chat' ;
159163 const newChatTitle =
160164 titleSource . length > 25
161165 ? titleSource . slice ( 0 , 25 ) + '...'
162166 : titleSource ;
163- await addChat ( newChatTitle , model ! . id ) ;
167+ const newChatId = await addChat ( newChatTitle , model ! . id ) ;
168+ if ( ! newChatId ) return ;
169+
170+ targetChatId = newChatId ;
171+ await setActiveChatId ( targetChatId ) ;
172+ router . replace ( `/chat/${ targetChatId } ` ) ;
164173 }
165174
166175 let persistedImagePath : string | undefined = imagePath ;
@@ -177,9 +186,8 @@ export default function ChatScreen({
177186 }
178187 }
179188
180- inputRef . current ?. clear ( ) ;
181189 Keyboard . dismiss ( ) ;
182- updateLastUsed ( chatId ! ) ;
190+ updateLastUsed ( targetChatId ) ;
183191
184192 // Notify Messages that a send is in flight. It will seed blankSpace to
185193 // the full container height, then derive the final value from measured
@@ -221,7 +229,7 @@ export default function ChatScreen({
221229 // Enable new sources for this chat (persists for future messages)
222230 for ( const sourceId of attachmentSourceIds ) {
223231 if ( ! enabledSources . includes ( sourceId ) ) {
224- await enableSource ( chatId ! , sourceId ) ;
232+ await enableSource ( targetChatId , sourceId ) ;
225233 }
226234 }
227235
@@ -239,7 +247,7 @@ export default function ChatScreen({
239247 . join ( ', ' ) || undefined ;
240248 await sendChatMessage (
241249 userInput ,
242- chatId ! ,
250+ targetChatId ,
243251 context ,
244252 settings ,
245253 persistedImagePath ,
0 commit comments