diff --git a/src/lib/components/chat/SettingsModal.svelte b/src/lib/components/chat/SettingsModal.svelte index 3758d4f79..976b6115a 100644 --- a/src/lib/components/chat/SettingsModal.svelte +++ b/src/lib/components/chat/SettingsModal.svelte @@ -238,6 +238,11 @@ const toggleSaveChatHistory = async () => { saveChatHistory = !saveChatHistory; + console.log(saveChatHistory); + + if (saveChatHistory === false) { + await goto('/'); + } saveSettings({ saveChatHistory: saveChatHistory }); }; diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index b0eb35b21..7ea08f988 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -6,7 +6,7 @@ import { goto, invalidateAll } from '$app/navigation'; import { page } from '$app/stores'; - import { user, chats, showSettings, chatId } from '$lib/stores'; + import { user, chats, settings, showSettings, chatId } from '$lib/stores'; import { onMount } from 'svelte'; import { deleteChatById, getChatList, updateChatById } from '$lib/apis/chats'; @@ -49,6 +49,12 @@ await deleteChatById(localStorage.token, id); await chats.set(await getChatList(localStorage.token)); }; + + const saveSettings = async (updated) => { + await settings.set({ ...$settings, ...updated }); + localStorage.setItem('settings', JSON.stringify($settings)); + location.href = '/'; + };
{/if} -
- + {/each} +
diff --git a/src/routes/(app)/+page.svelte b/src/routes/(app)/+page.svelte index be0faef46..86bdbbea9 100644 --- a/src/routes/(app)/+page.svelte +++ b/src/routes/(app)/+page.svelte @@ -280,11 +280,13 @@ } if ($chatId == _chatId) { - chat = await updateChatById(localStorage.token, _chatId, { - messages: messages, - history: history - }); - await chats.set(await getChatList(localStorage.token)); + if ($settings.saveChatHistory ?? true) { + chat = await updateChatById(localStorage.token, _chatId, { + messages: messages, + history: history + }); + await chats.set(await getChatList(localStorage.token)); + } } } else { if (res !== null) { @@ -444,11 +446,13 @@ } if ($chatId == _chatId) { - chat = await updateChatById(localStorage.token, _chatId, { - messages: messages, - history: history - }); - await chats.set(await getChatList(localStorage.token)); + if ($settings.saveChatHistory ?? true) { + chat = await updateChatById(localStorage.token, _chatId, { + messages: messages, + history: history + }); + await chats.set(await getChatList(localStorage.token)); + } } } else { if (res !== null) { @@ -527,20 +531,24 @@ // Create new chat if only one message in messages if (messages.length == 1) { - chat = await createNewChat(localStorage.token, { - id: $chatId, - title: 'New Chat', - models: selectedModels, - system: $settings.system ?? undefined, - options: { - ...($settings.options ?? {}) - }, - messages: messages, - history: history, - timestamp: Date.now() - }); - await chats.set(await getChatList(localStorage.token)); - await chatId.set(chat.id); + if ($settings.saveChatHistory ?? true) { + chat = await createNewChat(localStorage.token, { + id: $chatId, + title: 'New Chat', + models: selectedModels, + system: $settings.system ?? undefined, + options: { + ...($settings.options ?? {}) + }, + messages: messages, + history: history, + timestamp: Date.now() + }); + await chats.set(await getChatList(localStorage.token)); + await chatId.set(chat.id); + } else { + await chatId.set('local'); + } await tick(); } @@ -592,8 +600,10 @@ title = _title; } - chat = await updateChatById(localStorage.token, _chatId, { title: _title }); - await chats.set(await getChatList(localStorage.token)); + if ($settings.saveChatHistory ?? true) { + chat = await updateChatById(localStorage.token, _chatId, { title: _title }); + await chats.set(await getChatList(localStorage.token)); + } }; diff --git a/src/routes/(app)/c/[id]/+page.svelte b/src/routes/(app)/c/[id]/+page.svelte index d538b799b..341d2ff93 100644 --- a/src/routes/(app)/c/[id]/+page.svelte +++ b/src/routes/(app)/c/[id]/+page.svelte @@ -609,6 +609,12 @@ chat = await updateChatById(localStorage.token, _chatId, { title: _title }); await chats.set(await getChatList(localStorage.token)); }; + + onMount(async () => { + if (!($settings.saveChatHistory ?? true)) { + await goto('/'); + } + });