Skip to content

Commit

Permalink
Merge pull request #137 from iceljc/features/refine-chat-window
Browse files Browse the repository at this point in the history
refine chat image upload
  • Loading branch information
Oceania2018 authored Jun 4, 2024
2 parents f958615 + fe8aae2 commit 4feb1d7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
2 changes: 0 additions & 2 deletions src/lib/common/MessageImageGallery.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
/** @type {any[]} */
let files = [];
/** @type {string} */
let token = "";
onMount(() => {
if (fetchFiles != null && fetchFiles != undefined) {
Expand Down
5 changes: 5 additions & 0 deletions src/lib/helpers/utils/gallery.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EditorType, ElementType } from '../enums';
import { conversationUserAttachmentStore } from '../store';

/**
* @param {import('$types').ChatResponseModel?} message
Expand All @@ -9,4 +10,8 @@ export function loadFileGallery(message) {
|| message?.rich_content?.message?.elements?.find(x => x.type == ElementType.File)
|| message?.rich_content?.message?.quick_replies?.find(x => x.type == ElementType.File)
|| message?.rich_content?.message?.options?.find(x => x.type == ElementType.File);
}

export function loadLocalFiles() {
return conversationUserAttachmentStore.get()?.accepted_files?.length > 0;
}
23 changes: 8 additions & 15 deletions src/routes/chat/[agentId]/[conversationId]/chat-box.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import { utcToLocal } from '$lib/helpers/datetime';
import { replaceNewLine } from '$lib/helpers/http';
import { EditorType, SenderAction, UserRole } from '$lib/helpers/enums';
import { loadFileGallery } from '$lib/helpers/utils/gallery';
import { loadFileGallery, loadLocalFiles } from '$lib/helpers/utils/gallery';
import RichContent from './rich-content/rich-content.svelte';
import RcMessage from "./rich-content/rc-message.svelte";
import RcDisclaimer from './rich-content/rc-disclaimer.svelte';
Expand Down Expand Up @@ -125,14 +125,13 @@
let isFrame = false;
let loadEditor = false;
let loadTextEditor = false;
let loadFileEditor = false;
let loadFileEditor = true;
let autoScrollLog = false;
let disableAction = false;
$: {
const editor = lastBotMsg?.rich_content?.editor || '';
loadTextEditor = TEXT_EDITORS.includes(editor) || !Object.values(EditorType).includes(editor);
loadFileEditor = FILE_EDITORS.includes(editor);
loadEditor = !isSendingMsg && !isThinking && (loadTextEditor || loadFileEditor);
}
Expand Down Expand Up @@ -277,7 +276,7 @@
}
const prevMsg = dialogs[idx-1];
if (!!prevMsg && BOT_SENDERS.includes(prevMsg?.sender?.role || '')
if (!!!prevMsg || BOT_SENDERS.includes(prevMsg?.sender?.role || '')
&& loadFileGallery(prevMsg)) {
curMsg.is_load_images = true;
}
Expand Down Expand Up @@ -324,12 +323,8 @@
}
function getChatFiles() {
if (loadFileGallery(lastBotMsg)) {
const attachments = conversationUserAttachmentStore.get();
return attachments?.accepted_files || [];
}
return [];
const attachments = conversationUserAttachmentStore.get();
return attachments?.accepted_files || [];
}
Expand Down Expand Up @@ -997,7 +992,7 @@
{#if !!message.post_action_disclaimer}
<RcDisclaimer content={message.post_action_disclaimer} />
{/if}
{#if message.is_load_images}
{#if message.is_load_images || USER_SENDERS.includes(message.sender?.role)}
<MessageImageGallery
galleryStyles={'justify-content: flex-end;'}
fetchFiles={() => getConversationFiles(params.conversationId, message.message_id)}
Expand Down Expand Up @@ -1056,9 +1051,7 @@
{/if}
</ul>
{#if loadFileGallery(lastBotMsg)}
<ChatImageGallery disabled={isSendingMsg || isThinking} />
{/if}
<ChatImageGallery disabled={isSendingMsg || isThinking} />
{#if !!lastBotMsg && !isSendingMsg && !isThinking}
<RichContent
message={lastBotMsg}
Expand Down Expand Up @@ -1092,7 +1085,7 @@
/>
{#if loadFileEditor}
<div class="chat-input-links">
<ChatImageUploader disabled={disableAction} />
<ChatImageUploader disabled={disableAction} onFileDrop={() => refresh()} />
</div>
{/if}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
/** @type {boolean} */
export let disabled = false;
/** @type {() => void} */
export let onFileDrop = () => {};
/** @type {any[]} */
let files = [];
Expand Down Expand Up @@ -40,6 +43,7 @@
conversationUserAttachmentStore.put({
accepted_files: newAttachments
});
onFileDrop?.();
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
}
const prevMsg = dialogs[idx-1];
if (!!prevMsg && BOT_SENDERS.includes(prevMsg?.sender?.role || '')
if (!!!prevMsg || BOT_SENDERS.includes(prevMsg?.sender?.role || '')
&& loadFileGallery(prevMsg)) {
curMsg.is_load_images = true;
}
Expand Down Expand Up @@ -88,7 +88,7 @@
<p class="fw-bold">
<Markdown text={dialog?.rich_content?.message?.text || dialog?.text} />
</p>
{#if dialog.is_load_images}
{#if dialog.is_load_images || showInRight(dialog)}
<MessageImageGallery
galleryClasses={'dialog-file-display'}
fetchFiles={() => getConversationFiles(conversation.id, dialog.message_id)}
Expand Down

0 comments on commit 4feb1d7

Please # to comment.