From 69944d9a07c50fca3303a5806ea8ced7429bc34d Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Wed, 6 Nov 2024 17:19:40 -0600 Subject: [PATCH] add copy message --- .../[conversationId]/chat-box.svelte | 54 ++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte b/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte index 1ec3feb..48a527d 100644 --- a/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte +++ b/src/routes/chat/[agentId]/[conversationId]/chat-box.svelte @@ -106,6 +106,7 @@ let notificationText = ''; let successText = "Done"; let errorText = "Error"; + let note = ''; /** @type {number} */ let messageInputTimeout; @@ -193,6 +194,7 @@ let isDisplayNotification = false; let isComplete = false; let isError = false; + let clickCopy = false; $: { // const editor = lastBotMsg?.rich_content?.editor || ''; @@ -1169,6 +1171,31 @@ sendChatMessage(text, data); } + /** + * @param {any} e + * @param {any} message + */ + function copyMessage(e, message) { + e.preventDefault(); + + const elem = document.getElementById(`message-note-${message.message_id}`); + if (!elem) return; + + const text = message?.rich_content?.message?.text || message?.text || ''; + elem.classList.remove('hide'); + + navigator.clipboard.writeText(text).then(() => { + elem.textContent = 'Copied!'; + }).catch(() => { + elem.textContent = 'Error!'; + }).finally(() => { + clickCopy = false; + setTimeout(() => { + elem.classList.add('hide'); + }, 800); + }); + } + function toggleNotificationModal() { isDisplayNotification = !isDisplayNotification; if (!isDisplayNotification) { @@ -1636,7 +1663,7 @@
{#if message?.message_id === lastBotMsg?.message_id && message?.uuid === lastBotMsg?.uuid} -
+
{#if PUBLIC_LIVECHAT_SPEAKER_ENABLED === 'true'}
{/if} +
+ + +
copyMessage(e, message)} + on:mousedown={() => clickCopy = true} + > + {#if clickCopy} + + {:else} + + {/if} +
+
+
+
{/if} {#if !!message.is_chat_message || !!message.has_message_files}