11import { FlashList } from '@shopify/flash-list' ;
2+ import { useLocalSearchParams } from 'expo-router' ;
23import { delay } from 'lodash-es' ;
34import { ReactElement , useCallback , useRef , useState } from 'react' ;
45import { NativeScrollEvent , NativeSyntheticEvent } from 'react-native' ;
56import { useSharedValue , withTiming } from 'react-native-reanimated' ;
67import { AiMessageActions } from '@open-webui-react-native/mobile/chat/features/ai-message-actions' ;
78import { useManageMessageSiblings } from '@open-webui-react-native/mobile/chat/features/use-manage-messages-siblings' ;
89import { UserMessageActions } from '@open-webui-react-native/mobile/chat/features/user-message-actions' ;
10+ import { useSetSelectedModel } from '@open-webui-react-native/mobile/shared/features/use-set-selected-model' ;
911import { View , AppFlashList } from '@open-webui-react-native/mobile/shared/ui/ui-kit' ;
10- import { History as ChatHistory , Message } from '@open-webui-react-native/shared/data-access/api' ;
12+ import { ChatScreenParams } from '@open-webui-react-native/mobile/shared/utils/navigation' ;
13+ import {
14+ chatApi ,
15+ History as ChatHistory ,
16+ Message ,
17+ prepareCompleteChatPayload ,
18+ } from '@open-webui-react-native/shared/data-access/api' ;
1119import { Role } from '@open-webui-react-native/shared/data-access/common' ;
20+ import { socketService } from '@open-webui-react-native/shared/data-access/websocket' ;
1221import { ChatAiMessage } from '../ai-message' ;
1322import { ChatBottomButton } from '../chat-bottom-button' ;
1423import { ChatUserMessage } from '../user-message' ;
@@ -18,9 +27,9 @@ interface ChatMessagesListProps {
1827 isMessagesListLoaded : boolean ;
1928 onLayout : ( ) => void ;
2029 isInputFocusing : boolean ;
30+ onEditPress : ( messageId : string , content : string ) => void ;
2131 history ?: ChatHistory ;
2232 messages ?: Array < Message > ;
23- onEditPress : ( messageId : string , content : string ) => void ;
2433 editingMessageId ?: string ;
2534}
2635
@@ -42,6 +51,9 @@ export default function ChatMessagesList({
4251 const [ autoscrollToBottomThreshold , setAutoscrollToBottomThreshold ] = useState < number | undefined > ( 1 ) ;
4352
4453 const { showPreviousSibling, showNextSibling, getSiblingsInfo } = useManageMessageSiblings ( chatId , history ) ;
54+ const { mutate : completeChat } = chatApi . useCompleteChat ( ) ;
55+ const { id } : ChatScreenParams = useLocalSearchParams ( ) ;
56+ const { modelId } = useSetSelectedModel ( id ) ;
4557
4658 const handleContentSizeChange = ( ) : void => {
4759 //NOTE: Needs to wait until the initial scroll to the bottom or content generation finished and not show the ChatBottomButton before
@@ -116,13 +128,32 @@ export default function ChatMessagesList({
116128 } , 1000 ) ;
117129 } ;
118130
131+ const handleContinueResponsePress = ( messageId : string ) : void => {
132+ if ( ! modelId ) return ;
133+
134+ const completePayload = prepareCompleteChatPayload ( {
135+ chatId,
136+ messages,
137+ messageId : messageId ,
138+ sessionId : socketService . socketSessionId ,
139+ model : modelId ,
140+ } ) ;
141+ completeChat ( completePayload ) ;
142+ } ;
143+
119144 const renderItem = useCallback (
120145 ( { item, index } : { item : Message ; index : number } ) => {
121146 const message = history ?. messages [ item . id ] ;
122147 if ( ! message ) return null ;
123148
149+ const isLast = item . id === history ?. lastAssistantMessage ?. id ;
150+
124151 return item . role === Role . ASSISTANT ? (
125- < AiMessageActions message = { message } onEditPress = { onEditPress } >
152+ < AiMessageActions
153+ message = { message }
154+ onEditPress = { onEditPress }
155+ onContinueResponsePress = { handleContinueResponsePress }
156+ isLast = { isLast } >
126157 < ChatAiMessage
127158 message = { message }
128159 onEditPress = { ( ) => handleEditPress ( index , message . id , message . content ) }
@@ -144,7 +175,7 @@ export default function ChatMessagesList({
144175 </ UserMessageActions >
145176 ) ;
146177 } ,
147- [ history , onEditPress , editingMessageId , showPreviousSibling , showNextSibling , getSiblingsInfo ] ,
178+ [ history , onEditPress , editingMessageId , showPreviousSibling , showNextSibling , getSiblingsInfo , modelId ] ,
148179 ) ;
149180
150181 return (
0 commit comments