|
27 | 27 | import { EditorType, SenderAction, UserRole } from '$lib/helpers/enums'; |
28 | 28 | import RichContent from './richContent/rich-content.svelte'; |
29 | 29 | import RcDisclaimer from './richContent/rc-disclaimer.svelte'; |
30 | | - import ChatImage from './chatImage/chat-image.svelte'; |
| 30 | + import MessageImageGallery from './chatImage/message-image-gallery.svelte'; |
| 31 | + import ChatImageUploader from './chatImage/chat-image-uploader.svelte'; |
| 32 | + import ChatImageGallery from './chatImage/chat-image-gallery.svelte'; |
31 | 33 | import ContentLog from './contentLogs/content-log.svelte'; |
32 | 34 | import _ from "lodash"; |
33 | 35 | import { Pane, Splitpanes } from 'svelte-splitpanes'; |
|
36 | 38 | import "sweetalert2/src/sweetalert2.scss"; |
37 | 39 | import moment from 'moment'; |
38 | 40 | |
| 41 | + |
39 | 42 | const options = { |
40 | 43 | scrollbars: { |
41 | 44 | visibility: 'auto', |
|
216 | 219 | // trigger UI render |
217 | 220 | dialogs = dialogs?.map(item => { return { ...item }; }) || []; |
218 | 221 | lastBotMsg = findLastBotMessage(dialogs); |
| 222 | + assignLoadImageMessages(dialogs); |
219 | 223 | assignMessageDisclaimer(dialogs) |
220 | 224 | groupedDialogs = groupDialogs(dialogs); |
221 | 225 | await tick(); |
|
233 | 237 | }); |
234 | 238 | } |
235 | 239 |
|
| 240 | + /** @param {import('$types').ChatResponseModel[]} dialogs */ |
| 241 | + function assignLoadImageMessages(dialogs) { |
| 242 | + if (!!!dialogs) return; |
| 243 | +
|
| 244 | + for (let idx = 0; idx < dialogs.length; idx++) { |
| 245 | + const curMsg = dialogs[idx]; |
| 246 | + if (!USER_SENDERS.includes(curMsg?.sender?.role || '')) { |
| 247 | + continue; |
| 248 | + } |
| 249 | +
|
| 250 | + const botMsgId = dialogs.findLastIndex((x, i) => i < idx && !USER_SENDERS.includes(x.sender?.role || '')); |
| 251 | + if (botMsgId > -1 && dialogs[botMsgId]?.rich_content?.editor === EditorType.File) { |
| 252 | + const userMsgs = dialogs.filter(x => x.message_id === curMsg.message_id && USER_SENDERS.includes(x.sender?.role || '')); |
| 253 | + if (userMsgs?.length > 1) { |
| 254 | + const userMsg = userMsgs.slice(-1)[0]; |
| 255 | + userMsg.is_load_images = true; |
| 256 | + } else { |
| 257 | + curMsg.is_load_images = true; |
| 258 | + } |
| 259 | + } |
| 260 | + } |
| 261 | + } |
| 262 | +
|
236 | 263 | /** @param {import('$types').ChatResponseModel[]} dialogs */ |
237 | 264 | function assignMessageDisclaimer(dialogs) { |
238 | 265 | if (!!!dialogs) return null; |
|
278 | 305 | } |
279 | 306 |
|
280 | 307 | const attachments = conversationUserAttachmentStore.get(); |
281 | | - const files = attachments?.accepted_files || []; |
282 | | - return files.map((/** @type {any} */ f) => { |
283 | | - return { |
284 | | - ...f, |
285 | | - message_id: lastBotMsg?.message_id |
286 | | - }; |
287 | | - }); |
| 308 | + return attachments?.accepted_files || []; |
288 | 309 | } |
289 | 310 |
|
290 | 311 |
|
|
915 | 936 | on:click={() => directToLog(message.message_id)} |
916 | 937 | > |
917 | 938 | <div> |
918 | | - <!--<div class="conversation-name">{message.sender.full_name}</div>--> |
919 | 939 | <div class="text-start">{@html replaceNewLine(message.text)}</div> |
920 | 940 | <p class="chat-time mb-0"> |
921 | 941 | <i class="bx bx-time-five align-middle me-1" /> |
922 | | - <!-- {format(message.created_at, 'short-time')} --> |
923 | 942 | {utcToLocal(message.created_at, 'hh:mm A')} |
924 | 943 | </p> |
925 | 944 | </div> |
926 | 945 | </div> |
927 | 946 | {#if !!message.post_action_disclaimer} |
928 | 947 | <RcDisclaimer content={message.post_action_disclaimer} /> |
929 | 948 | {/if} |
| 949 | + {#if message.is_load_images} |
| 950 | + <MessageImageGallery message={message} /> |
| 951 | + {/if} |
930 | 952 | </div> |
931 | 953 | {#if !isLite} |
932 | 954 | <Dropdown> |
|
955 | 977 | disabled={isSendingMsg || isThinking} |
956 | 978 | onConfirm={confirmSelectedOption} |
957 | 979 | /> |
958 | | - {#if message.rich_content?.editor === EditorType.File && message.message_id != lastBotMsg?.message_id} |
959 | | - <ChatImage message={message} /> |
960 | | - {/if} |
961 | 980 | </div> |
962 | 981 | {/if} |
963 | 982 | </div> |
|
973 | 992 | </div> |
974 | 993 | <div class="msg-container"> |
975 | 994 | <div class="ctext-wrap float-start"> |
976 | | - <span class="chat-indication"> |
977 | | - {indication} |
978 | | - </span> |
| 995 | + {#if !!indication} |
| 996 | + <span class="chat-indication"> |
| 997 | + {indication} |
| 998 | + </span> |
| 999 | + {/if} |
979 | 1000 | <div class="flex-shrink-0 align-self-center" style="display: inline-block;"> |
980 | 1001 | <LoadingDots duration={'1s'} size={10} color={'var(--bs-primary)'} /> |
981 | 1002 | </div> |
|
985 | 1006 | </li> |
986 | 1007 | {/if} |
987 | 1008 | </ul> |
| 1009 | +
|
| 1010 | + {#if lastBotMsg?.rich_content?.editor === EditorType.File} |
| 1011 | + <ChatImageGallery disabled={isSendingMsg || isThinking} /> |
| 1012 | + {/if} |
988 | 1013 | </div> |
989 | 1014 | </div> |
990 | 1015 |
|
|
1003 | 1028 | <div class="col"> |
1004 | 1029 | <div class="position-relative"> |
1005 | 1030 | <ChatTextArea |
1006 | | - className={'chat-input'} |
| 1031 | + className={`chat-input ${lastBotMsg?.rich_content?.editor == EditorType.File ? 'chat-input-image' : ''}`} |
1007 | 1032 | bind:text={text} |
1008 | 1033 | disabled={isSendingMsg || isThinking || lastBotMsg?.rich_content?.editor == EditorType.None} |
1009 | 1034 | editor={lastBotMsg?.rich_content?.editor || ''} |
1010 | 1035 | onKeyDown={e => onSendMessage(e)} |
1011 | 1036 | /> |
| 1037 | + {#if lastBotMsg?.rich_content?.editor == EditorType.File} |
| 1038 | + <ChatImageUploader /> |
| 1039 | + {/if} |
1012 | 1040 | </div> |
1013 | 1041 | </div> |
1014 | 1042 | <div class="col-auto"> |
|
0 commit comments