Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/mobile/chat/features/chat/src/lib/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function Chat({ chatId, selectedModelId, isNewChat, resetToChatsList }: C
} = useEditMessage({ chat, modelId: selectedModelId });

const history = chat?.chat.history;
const isResponseGenerating = !history?.messages[history.currentId].done;
const isResponseGenerating = history?.lastAssistantMessage?.done !== true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes related to lastAssistantMessage cause a bug when switching message history. If we return to an old chat thread, the input becomes disabled.

Untitled.mov.zip


const shouldHideContent = isLoading || isRefetching || !isMessagesListLoaded || !selectedModelId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import { useSetSelectedModel } from '@open-webui-react-native/mobile/shared/feat
import { View, AppFlashList } from '@open-webui-react-native/mobile/shared/ui/ui-kit';
import { ChatScreenParams } from '@open-webui-react-native/mobile/shared/utils/navigation';
import {
Chat,
chatApi,
History as ChatHistory,
Message,
patchChatQueryData,
prepareCompleteChatPayload,
} from '@open-webui-react-native/shared/data-access/api';
import { Role } from '@open-webui-react-native/shared/data-access/common';
Expand Down Expand Up @@ -131,6 +133,19 @@ export default function ChatMessagesList({
const handleContinueResponsePress = (messageId: string): void => {
if (!modelId) return;

// mark message as not completed
patchChatQueryData(chatId, {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change is enough to fix the original bug, why do we need the rest of the changes?

chat: {
history: {
messages: {
[messageId]: {
done: false,
},
},
},
} as Chat,
});

const completePayload = prepareCompleteChatPayload({
chatId,
messages,
Expand All @@ -146,7 +161,11 @@ export default function ChatMessagesList({
const message = history?.messages[item.id];
if (!message) return null;

const isLast = item.id === history?.lastAssistantMessage?.id;
const lastAssistantMessageInUIList = [...messages]
.reverse()
.find((m) => history?.messages[m.id]?.role === Role.ASSISTANT);

const isLast = item.id === lastAssistantMessageInUIList?.id;

return item.role === Role.ASSISTANT ? (
<AiMessageActions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Role } from '@open-webui-react-native/shared/data-access/common';
import { ChatResponse, Message } from '../models';
import { ChatResponse, Message, History } from '../models';

export function patchCompletedMessage(oldData: ChatResponse | undefined): ChatResponse | undefined {
if (
Expand Down Expand Up @@ -33,11 +33,10 @@ export function patchCompletedMessage(oldData: ChatResponse | undefined): ChatRe
: undefined;

const updatedHistory = updatedHistoryMessages
? {
...history,
? new History({
messages: updatedHistoryMessages,
lastAssistantMessage: history?.lastAssistantMessage ?? updatedLastMessage,
}
currentId: history.currentId,
})
: history;

return {
Expand Down
Loading