mirror of
https://github.com/open-webui/open-webui
synced 2025-04-16 21:42:50 +00:00
refac
This commit is contained in:
parent
6e4820cad8
commit
351c29917b
@ -519,9 +519,14 @@ class ChatTable:
|
|||||||
self, folder_id: str, user_id: str
|
self, folder_id: str, user_id: str
|
||||||
) -> list[ChatModel]:
|
) -> list[ChatModel]:
|
||||||
with get_db() as db:
|
with get_db() as db:
|
||||||
all_chats = (
|
query = db.query(Chat).filter_by(folder_id=folder_id, user_id=user_id)
|
||||||
db.query(Chat).filter_by(folder_id=folder_id, user_id=user_id).all()
|
|
||||||
)
|
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]
|
return [ChatModel.model_validate(chat) for chat in all_chats]
|
||||||
|
|
||||||
def update_chat_folder_id_by_id_and_user_id(
|
def update_chat_folder_id_by_id_and_user_id(
|
||||||
|
@ -39,7 +39,6 @@
|
|||||||
import ArchivedChatsModal from './Sidebar/ArchivedChatsModal.svelte';
|
import ArchivedChatsModal from './Sidebar/ArchivedChatsModal.svelte';
|
||||||
import UserMenu from './Sidebar/UserMenu.svelte';
|
import UserMenu from './Sidebar/UserMenu.svelte';
|
||||||
import ChatItem from './Sidebar/ChatItem.svelte';
|
import ChatItem from './Sidebar/ChatItem.svelte';
|
||||||
import DeleteConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
|
|
||||||
import Spinner from '../common/Spinner.svelte';
|
import Spinner from '../common/Spinner.svelte';
|
||||||
import Loader from '../common/Loader.svelte';
|
import Loader from '../common/Loader.svelte';
|
||||||
import AddFilesPlaceholder from '../AddFilesPlaceholder.svelte';
|
import AddFilesPlaceholder from '../AddFilesPlaceholder.svelte';
|
||||||
@ -152,6 +151,8 @@
|
|||||||
const initChatList = async () => {
|
const initChatList = async () => {
|
||||||
// Reset pagination variables
|
// Reset pagination variables
|
||||||
tags.set(await getAllTags(localStorage.token));
|
tags.set(await getAllTags(localStorage.token));
|
||||||
|
pinnedChats.set(await getPinnedChatList(localStorage.token));
|
||||||
|
initFolders();
|
||||||
|
|
||||||
currentChatPage.set(1);
|
currentChatPage.set(1);
|
||||||
allChatsLoaded = false;
|
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) => {
|
const inputFilesHandler = async (files) => {
|
||||||
console.log(files);
|
console.log(files);
|
||||||
|
|
||||||
@ -364,8 +343,6 @@
|
|||||||
localStorage.sidebar = value;
|
localStorage.sidebar = value;
|
||||||
});
|
});
|
||||||
|
|
||||||
await initFolders();
|
|
||||||
await pinnedChats.set(await getPinnedChatList(localStorage.token));
|
|
||||||
await initChatList();
|
await initChatList();
|
||||||
|
|
||||||
window.addEventListener('keydown', onKeyDown);
|
window.addEventListener('keydown', onKeyDown);
|
||||||
@ -405,23 +382,10 @@
|
|||||||
<ArchivedChatsModal
|
<ArchivedChatsModal
|
||||||
bind:show={$showArchivedChats}
|
bind:show={$showArchivedChats}
|
||||||
on:change={async () => {
|
on:change={async () => {
|
||||||
await pinnedChats.set(await getPinnedChatList(localStorage.token));
|
|
||||||
await initChatList();
|
await initChatList();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<DeleteConfirmDialog
|
|
||||||
bind:show={showDeleteConfirm}
|
|
||||||
title={$i18n.t('Delete chat?')}
|
|
||||||
on:confirm={() => {
|
|
||||||
deleteChatHandler(deleteChat.id);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div class=" text-sm text-gray-500 flex-1 line-clamp-3">
|
|
||||||
{$i18n.t('This will delete')} <span class=" font-semibold">{deleteChat.title}</span>.
|
|
||||||
</div>
|
|
||||||
</DeleteConfirmDialog>
|
|
||||||
|
|
||||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||||
|
|
||||||
{#if $showSidebar}
|
{#if $showSidebar}
|
||||||
@ -632,7 +596,6 @@
|
|||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
initChatList();
|
initChatList();
|
||||||
await initFolders();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -640,9 +603,7 @@
|
|||||||
const res = await toggleChatPinnedStatusById(localStorage.token, id);
|
const res = await toggleChatPinnedStatusById(localStorage.token, id);
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
await pinnedChats.set(await getPinnedChatList(localStorage.token));
|
|
||||||
initChatList();
|
initChatList();
|
||||||
await initFolders();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -666,16 +627,7 @@
|
|||||||
on:unselect={() => {
|
on:unselect={() => {
|
||||||
selectedChatId = null;
|
selectedChatId = null;
|
||||||
}}
|
}}
|
||||||
on:delete={(e) => {
|
|
||||||
if ((e?.detail ?? '') === 'shift') {
|
|
||||||
deleteChatHandler(chat.id);
|
|
||||||
} else {
|
|
||||||
deleteChat = chat;
|
|
||||||
showDeleteConfirm = true;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
on:change={async () => {
|
on:change={async () => {
|
||||||
await pinnedChats.set(await getPinnedChatList(localStorage.token));
|
|
||||||
initChatList();
|
initChatList();
|
||||||
}}
|
}}
|
||||||
on:tag={(e) => {
|
on:tag={(e) => {
|
||||||
@ -695,7 +647,9 @@
|
|||||||
{folders}
|
{folders}
|
||||||
on:update={async (e) => {
|
on:update={async (e) => {
|
||||||
initChatList();
|
initChatList();
|
||||||
await initFolders();
|
}}
|
||||||
|
on:change={async () => {
|
||||||
|
initChatList();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
@ -722,7 +676,6 @@
|
|||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
initChatList();
|
initChatList();
|
||||||
await initFolders();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -730,9 +683,7 @@
|
|||||||
const res = await toggleChatPinnedStatusById(localStorage.token, id);
|
const res = await toggleChatPinnedStatusById(localStorage.token, id);
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
await pinnedChats.set(await getPinnedChatList(localStorage.token));
|
|
||||||
initChatList();
|
initChatList();
|
||||||
await initFolders();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -798,16 +749,7 @@
|
|||||||
on:unselect={() => {
|
on:unselect={() => {
|
||||||
selectedChatId = null;
|
selectedChatId = null;
|
||||||
}}
|
}}
|
||||||
on:delete={(e) => {
|
|
||||||
if ((e?.detail ?? '') === 'shift') {
|
|
||||||
deleteChatHandler(chat.id);
|
|
||||||
} else {
|
|
||||||
deleteChat = chat;
|
|
||||||
showDeleteConfirm = true;
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
on:change={async () => {
|
on:change={async () => {
|
||||||
await pinnedChats.set(await getPinnedChatList(localStorage.token));
|
|
||||||
initChatList();
|
initChatList();
|
||||||
}}
|
}}
|
||||||
on:tag={(e) => {
|
on:tag={(e) => {
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
} from '$lib/stores';
|
} from '$lib/stores';
|
||||||
|
|
||||||
import ChatMenu from './ChatMenu.svelte';
|
import ChatMenu from './ChatMenu.svelte';
|
||||||
|
import DeleteConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
|
||||||
import ShareChatModal from '$lib/components/chat/ShareChatModal.svelte';
|
import ShareChatModal from '$lib/components/chat/ShareChatModal.svelte';
|
||||||
import GarbageBin from '$lib/components/icons/GarbageBin.svelte';
|
import GarbageBin from '$lib/components/icons/GarbageBin.svelte';
|
||||||
import Tooltip from '$lib/components/common/Tooltip.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) => {
|
const archiveChatHandler = async (id) => {
|
||||||
await archiveChatById(localStorage.token, id);
|
await archiveChatById(localStorage.token, id);
|
||||||
tags.set(await getAllTags(localStorage.token));
|
dispatch('change');
|
||||||
|
|
||||||
currentChatPage.set(1);
|
|
||||||
await chats.set(await getChatList(localStorage.token, $currentChatPage));
|
|
||||||
await pinnedChats.set(await getPinnedChatList(localStorage.token));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const focusEdit = async (node: HTMLInputElement) => {
|
const focusEdit = async (node: HTMLInputElement) => {
|
||||||
@ -158,10 +173,24 @@
|
|||||||
itemElement.removeEventListener('dragend', onDragEnd);
|
itemElement.removeEventListener('dragend', onDragEnd);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let showDeleteConfirm = false;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ShareChatModal bind:show={showShareChatModal} chatId={id} />
|
<ShareChatModal bind:show={showShareChatModal} chatId={id} />
|
||||||
|
|
||||||
|
<DeleteConfirmDialog
|
||||||
|
bind:show={showDeleteConfirm}
|
||||||
|
title={$i18n.t('Delete chat?')}
|
||||||
|
on:confirm={() => {
|
||||||
|
deleteChatHandler(id);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div class=" text-sm text-gray-500 flex-1 line-clamp-3">
|
||||||
|
{$i18n.t('This will delete')} <span class=" font-semibold">{title}</span>.
|
||||||
|
</div>
|
||||||
|
</DeleteConfirmDialog>
|
||||||
|
|
||||||
{#if dragged && x && y}
|
{#if dragged && x && y}
|
||||||
<DragGhost {x} {y}>
|
<DragGhost {x} {y}>
|
||||||
<div class=" bg-black/80 backdrop-blur-2xl px-2 py-1 rounded-lg w-fit max-w-40">
|
<div class=" bg-black/80 backdrop-blur-2xl px-2 py-1 rounded-lg w-fit max-w-40">
|
||||||
@ -295,7 +324,7 @@
|
|||||||
<button
|
<button
|
||||||
class=" self-center dark:hover:text-white transition"
|
class=" self-center dark:hover:text-white transition"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
dispatch('delete', 'shift');
|
deleteChatHandler(id);
|
||||||
}}
|
}}
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
@ -322,7 +351,7 @@
|
|||||||
confirmEdit = true;
|
confirmEdit = true;
|
||||||
}}
|
}}
|
||||||
deleteHandler={() => {
|
deleteHandler={() => {
|
||||||
dispatch('delete');
|
showDeleteConfirm = true;
|
||||||
}}
|
}}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
dispatch('unselect');
|
dispatch('unselect');
|
||||||
|
@ -25,5 +25,8 @@
|
|||||||
on:update={(e) => {
|
on:update={(e) => {
|
||||||
dispatch('update', e.detail);
|
dispatch('update', e.detail);
|
||||||
}}
|
}}
|
||||||
|
on:change={(e) => {
|
||||||
|
dispatch('change', e.detail);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
{/each}
|
{/each}
|
||||||
|
@ -381,13 +381,22 @@
|
|||||||
on:update={(e) => {
|
on:update={(e) => {
|
||||||
dispatch('update', e.detail);
|
dispatch('update', e.detail);
|
||||||
}}
|
}}
|
||||||
|
on:change={(e) => {
|
||||||
|
dispatch('change', e.detail);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
{/each}
|
{/each}
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if folders[folderId].items?.chats}
|
{#if folders[folderId].items?.chats}
|
||||||
{#each folders[folderId].items.chats as chat (chat.id)}
|
{#each folders[folderId].items.chats as chat (chat.id)}
|
||||||
<ChatItem id={chat.id} title={chat.title} />
|
<ChatItem
|
||||||
|
id={chat.id}
|
||||||
|
title={chat.title}
|
||||||
|
on:change={(e) => {
|
||||||
|
dispatch('change', e.detail);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
{/each}
|
{/each}
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user