diff --git a/backend/open_webui/apps/webui/models/chats.py b/backend/open_webui/apps/webui/models/chats.py index 22c971243..4c3d89659 100644 --- a/backend/open_webui/apps/webui/models/chats.py +++ b/backend/open_webui/apps/webui/models/chats.py @@ -519,9 +519,14 @@ class ChatTable: self, folder_id: str, user_id: str ) -> list[ChatModel]: with get_db() as db: - all_chats = ( - db.query(Chat).filter_by(folder_id=folder_id, user_id=user_id).all() - ) + query = db.query(Chat).filter_by(folder_id=folder_id, user_id=user_id) + + query = query.filter_by(archived=False) + query = query.filter(or_(Chat.pinned == False, Chat.pinned == None)) + + query = query.order_by(Chat.updated_at.desc()) + + all_chats = query.all() return [ChatModel.model_validate(chat) for chat in all_chats] def update_chat_folder_id_by_id_and_user_id( diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index 1eb677f83..6e452db72 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -39,7 +39,6 @@ import ArchivedChatsModal from './Sidebar/ArchivedChatsModal.svelte'; import UserMenu from './Sidebar/UserMenu.svelte'; import ChatItem from './Sidebar/ChatItem.svelte'; - import DeleteConfirmDialog from '$lib/components/common/ConfirmDialog.svelte'; import Spinner from '../common/Spinner.svelte'; import Loader from '../common/Loader.svelte'; import AddFilesPlaceholder from '../AddFilesPlaceholder.svelte'; @@ -152,6 +151,8 @@ const initChatList = async () => { // Reset pagination variables tags.set(await getAllTags(localStorage.token)); + pinnedChats.set(await getPinnedChatList(localStorage.token)); + initFolders(); currentChatPage.set(1); allChatsLoaded = false; @@ -207,28 +208,6 @@ } }; - const deleteChatHandler = async (id) => { - const res = await deleteChatById(localStorage.token, id).catch((error) => { - toast.error(error); - return null; - }); - - if (res) { - tags.set(await getAllTags(localStorage.token)); - - if ($chatId === id) { - await chatId.set(''); - await tick(); - goto('/'); - } - - allChatsLoaded = false; - currentChatPage.set(1); - await chats.set(await getChatList(localStorage.token, $currentChatPage)); - await pinnedChats.set(await getPinnedChatList(localStorage.token)); - } - }; - const inputFilesHandler = async (files) => { console.log(files); @@ -364,8 +343,6 @@ localStorage.sidebar = value; }); - await initFolders(); - await pinnedChats.set(await getPinnedChatList(localStorage.token)); await initChatList(); window.addEventListener('keydown', onKeyDown); @@ -405,23 +382,10 @@ { - await pinnedChats.set(await getPinnedChatList(localStorage.token)); await initChatList(); }} /> - { - deleteChatHandler(deleteChat.id); - }} -> -
- {$i18n.t('This will delete')} {deleteChat.title}. -
-
- {#if $showSidebar} @@ -632,7 +596,6 @@ if (res) { initChatList(); - await initFolders(); } } @@ -640,9 +603,7 @@ const res = await toggleChatPinnedStatusById(localStorage.token, id); if (res) { - await pinnedChats.set(await getPinnedChatList(localStorage.token)); initChatList(); - await initFolders(); } } } @@ -666,16 +627,7 @@ on:unselect={() => { selectedChatId = null; }} - on:delete={(e) => { - if ((e?.detail ?? '') === 'shift') { - deleteChatHandler(chat.id); - } else { - deleteChat = chat; - showDeleteConfirm = true; - } - }} on:change={async () => { - await pinnedChats.set(await getPinnedChatList(localStorage.token)); initChatList(); }} on:tag={(e) => { @@ -695,7 +647,9 @@ {folders} on:update={async (e) => { initChatList(); - await initFolders(); + }} + on:change={async () => { + initChatList(); }} /> {/if} @@ -722,7 +676,6 @@ if (res) { initChatList(); - await initFolders(); } } @@ -730,9 +683,7 @@ const res = await toggleChatPinnedStatusById(localStorage.token, id); if (res) { - await pinnedChats.set(await getPinnedChatList(localStorage.token)); initChatList(); - await initFolders(); } } } @@ -798,16 +749,7 @@ on:unselect={() => { selectedChatId = null; }} - on:delete={(e) => { - if ((e?.detail ?? '') === 'shift') { - deleteChatHandler(chat.id); - } else { - deleteChat = chat; - showDeleteConfirm = true; - } - }} on:change={async () => { - await pinnedChats.set(await getPinnedChatList(localStorage.token)); initChatList(); }} on:tag={(e) => { diff --git a/src/lib/components/layout/Sidebar/ChatItem.svelte b/src/lib/components/layout/Sidebar/ChatItem.svelte index eb19ba5b4..7a189ecf9 100644 --- a/src/lib/components/layout/Sidebar/ChatItem.svelte +++ b/src/lib/components/layout/Sidebar/ChatItem.svelte @@ -28,6 +28,7 @@ } from '$lib/stores'; import ChatMenu from './ChatMenu.svelte'; + import DeleteConfirmDialog from '$lib/components/common/ConfirmDialog.svelte'; import ShareChatModal from '$lib/components/chat/ShareChatModal.svelte'; import GarbageBin from '$lib/components/icons/GarbageBin.svelte'; import Tooltip from '$lib/components/common/Tooltip.svelte'; @@ -85,13 +86,27 @@ } }; + const deleteChatHandler = async (id) => { + const res = await deleteChatById(localStorage.token, id).catch((error) => { + toast.error(error); + return null; + }); + + if (res) { + tags.set(await getAllTags(localStorage.token)); + if ($chatId === id) { + await chatId.set(''); + await tick(); + goto('/'); + } + + dispatch('change'); + } + }; + const archiveChatHandler = async (id) => { await archiveChatById(localStorage.token, id); - tags.set(await getAllTags(localStorage.token)); - - currentChatPage.set(1); - await chats.set(await getChatList(localStorage.token, $currentChatPage)); - await pinnedChats.set(await getPinnedChatList(localStorage.token)); + dispatch('change'); }; const focusEdit = async (node: HTMLInputElement) => { @@ -158,10 +173,24 @@ itemElement.removeEventListener('dragend', onDragEnd); } }); + + let showDeleteConfirm = false; + { + deleteChatHandler(id); + }} +> +
+ {$i18n.t('This will delete')} {title}. +
+
+ {#if dragged && x && y}
@@ -295,7 +324,7 @@