diff --git a/backend/open_webui/apps/webui/models/chats.py b/backend/open_webui/apps/webui/models/chats.py index f6a1e4548..21250add8 100644 --- a/backend/open_webui/apps/webui/models/chats.py +++ b/backend/open_webui/apps/webui/models/chats.py @@ -203,15 +203,22 @@ class ChatTable: def update_shared_chat_by_chat_id(self, chat_id: str) -> Optional[ChatModel]: try: with get_db() as db: - print("update_shared_chat_by_id") chat = db.get(Chat, chat_id) - print(chat) - chat.title = chat.title - chat.chat = chat.chat - db.commit() - db.refresh(chat) + shared_chat = ( + db.query(Chat).filter_by(user_id=f"shared-{chat_id}").first() + ) - return self.get_chat_by_id(chat.share_id) + if shared_chat is None: + return self.insert_shared_chat_by_chat_id(chat_id) + + shared_chat.title = chat.title + shared_chat.chat = chat.chat + + shared_chat.updated_at = int(time.time()) + db.commit() + db.refresh(shared_chat) + + return ChatModel.model_validate(shared_chat) except Exception: return None diff --git a/src/lib/components/chat/ShareChatModal.svelte b/src/lib/components/chat/ShareChatModal.svelte index e6ccc1323..f7cc6d6be 100644 --- a/src/lib/components/chat/ShareChatModal.svelte +++ b/src/lib/components/chat/ShareChatModal.svelte @@ -80,7 +80,7 @@ } - +
{$i18n.t('Share Chat')}
diff --git a/src/lib/components/common/Modal.svelte b/src/lib/components/common/Modal.svelte index 9d77f9e2f..795d3d0f1 100644 --- a/src/lib/components/common/Modal.svelte +++ b/src/lib/components/common/Modal.svelte @@ -20,7 +20,7 @@ } else if (size === 'sm') { return 'w-[30rem]'; } else if (size === 'md') { - return 'w-[48rem]'; + return 'w-[42rem]'; } else { return 'w-[56rem]'; } diff --git a/src/routes/s/[id]/+page.svelte b/src/routes/s/[id]/+page.svelte index 898097272..0d4579838 100644 --- a/src/routes/s/[id]/+page.svelte +++ b/src/routes/s/[id]/+page.svelte @@ -6,7 +6,7 @@ import dayjs from 'dayjs'; import { settings, chatId, WEBUI_NAME, models } from '$lib/stores'; - import { convertMessagesToHistory } from '$lib/utils'; + import { convertMessagesToHistory, createMessagesList } from '$lib/utils'; import { getChatByShareId } from '$lib/apis/chats'; @@ -40,19 +40,7 @@ currentId: null }; - $: if (history.currentId !== null) { - let _messages = []; - - let currentMessage = history.messages[history.currentId]; - while (currentMessage !== null) { - _messages.unshift({ ...currentMessage }); - currentMessage = - currentMessage.parentId !== null ? history.messages[currentMessage.parentId] : null; - } - messages = _messages; - } else { - messages = []; - } + $: messages = createMessagesList(history, history.currentId); $: if ($page.params.id) { (async () => { @@ -138,7 +126,7 @@
-
+