From c6dd9a451abef12e93e19624a64cfb8a9a1f6465 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Thu, 8 Oct 2026 01:20:51 +0400 Subject: [PATCH] refac --- src/lib/components/chat/Chat.svelte | 44 ++++++++++++++++++++++++++--- src/routes/s/[id]/+page.svelte | 16 +++++------ 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 7331ec9900..2c482c6422 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -82,6 +82,7 @@ getAllTags, getChatById, getTagsById, + importChats, resolveChatMessageToolCall, updateChatById, updateChatFolderIdById @@ -381,6 +382,33 @@ // Read-only when viewing someone else's chat (e.g. via shared folder access) $: readOnly = chat != null && chat.user_id !== $user?.id; + $: canClone = readOnly && ($user?.role === 'admin' || ($user?.permissions?.chat?.import ?? true)); + let cloning = false; + + const cloneSharedChat = async () => { + if (!canClone || cloning) return; + cloning = true; + try { + const [copy] = await importChats(localStorage.token, [ + { + chat: { + ...chat.chat, + title: $i18n.t('Clone of {{TITLE}}', { TITLE: chat.title }), + originalChatId: chat.id, + branchPointMessageId: history.currentId + } + } + ]); + if (copy) { + await goto(`/c/${copy.id}`); + await refreshChatList(localStorage.token); + } + } catch (error) { + toast.error(`${error}`); + } finally { + cloning = false; + } + }; let chatOwner = null; @@ -4671,11 +4699,19 @@ {#if readOnly} -
-
- {$i18n.t('Read only')} + {#if canClone} +
+
-
+ {/if} {:else}
-
- -
+
{/if}