|
216 | 216 | let isHandlingQueue = $state(false); |
217 | 217 | let isStopStreamClicked = $state(false); |
218 | 218 |
|
219 | | - let isWaiting = $derived(isSendingMsg || isThinking || messageQueue.length > 0); |
| 219 | + let isWaiting = $derived(isSendingMsg || isThinking || isStreaming || messageQueue.length > 0); |
220 | 220 | let loadEditor = true; |
221 | 221 | let disableAction = $derived(!ADMIN_ROLES.includes(currentUser?.role || '') |
222 | 222 | && currentUser?.id !== conversationUser?.id |
|
916 | 916 | return; |
917 | 917 | } |
918 | 918 |
|
919 | | - if ((e.key === 'Enter' && (!!e.shiftKey || !!e.ctrlKey)) || e.key !== 'Enter' || !_.trim(text) || isSendingMsg || isThinking) { |
| 919 | + if ((e.key === 'Enter' && (!!e.shiftKey || !!e.ctrlKey)) || e.key !== 'Enter' || !_.trim(text) || isWaiting) { |
920 | 920 | return; |
921 | 921 | } |
922 | 922 |
|
|
962 | 962 | * @param {string} payload |
963 | 963 | */ |
964 | 964 | async function confirmSelectedOption(title, payload) { |
965 | | - if (isSendingMsg || isThinking) return; |
| 965 | + if (isWaiting) return; |
966 | 966 |
|
967 | 967 | const postback = buildPostbackMessage(dialogs, payload || title, null);; |
968 | 968 | await sendChatMessage(title, { postback: postback }); |
|
1137 | 1137 | * @param {string} messageId |
1138 | 1138 | */ |
1139 | 1139 | function deleteMessage(e, messageId) { |
| 1140 | + if (isWaiting || disableAction) return; |
1140 | 1141 | handleDeleteMessage(messageId); |
1141 | 1142 | } |
1142 | 1143 |
|
|
1153 | 1154 | * @param {import('$conversationTypes').ChatResponseModel} message |
1154 | 1155 | */ |
1155 | 1156 | async function editMessage(message) { |
| 1157 | + if (isWaiting || disableAction) return; |
1156 | 1158 | truncateMsgId = message?.message_id; |
1157 | 1159 | editText = message?.text || ''; |
1158 | 1160 | await tick(); |
|
1192 | 1194 |
|
1193 | 1195 | /** @param {import('$conversationTypes').ChatResponseModel} message */ |
1194 | 1196 | async function resendMessage(message) { |
1195 | | - if (isSendingMsg || isThinking || disableAction) return; |
| 1197 | + if (isWaiting || disableAction) return; |
1196 | 1198 | const msgId = message?.message_id; |
1197 | 1199 | const msgText = message?.text || ''; |
1198 | 1200 | if (!msgId || !msgText) return; |
|
1387 | 1389 |
|
1388 | 1390 | /** @param {import('$conversationTypes').ChatResponseModel} message */ |
1389 | 1391 | async function openBotMsgEditor(message) { |
| 1392 | + if (isWaiting || disableAction) return; |
1390 | 1393 | let source = "text"; |
1391 | 1394 | if (message.rich_content?.message?.text === message.text) { |
1392 | 1395 | source = "both"; |
|
1975 | 1978 | data-bs-toggle="tooltip" |
1976 | 1979 | data-bs-placement="top" |
1977 | 1980 | title="Edit" |
| 1981 | + aria-disabled={isWaiting || disableAction} |
1978 | 1982 | onclick={() => editMessage(message)} |
1979 | 1983 | > |
1980 | 1984 | <i class="bx bxs-edit cb-text-primary"></i> |
|
1988 | 1992 | data-bs-toggle="tooltip" |
1989 | 1993 | data-bs-placement="top" |
1990 | 1994 | title="Resend" |
1991 | | - aria-disabled={isSendingMsg || isThinking || disableAction} |
| 1995 | + aria-disabled={isWaiting || disableAction} |
1992 | 1996 | onclick={() => resendMessage(message)} |
1993 | 1997 | > |
1994 | 1998 | <i class="bx bx-redo cb-text-primary"></i> |
|
2021 | 2025 | data-bs-toggle="tooltip" |
2022 | 2026 | data-bs-placement="top" |
2023 | 2027 | title="Delete" |
2024 | | - aria-disabled={isSendingMsg || isThinking || disableAction} |
2025 | | - onclick={(e) => { |
2026 | | - if (isSendingMsg || isThinking || disableAction) return; |
2027 | | - deleteMessage(e, message.message_id); |
2028 | | - }} |
| 2028 | + aria-disabled={isWaiting || disableAction} |
| 2029 | + onclick={(e) => deleteMessage(e, message.message_id)} |
2029 | 2030 | > |
2030 | 2031 | <i class="bx bx-trash cb-text-danger"></i> |
2031 | 2032 | </div> |
|
2129 | 2130 | data-bs-toggle="tooltip" |
2130 | 2131 | data-bs-placement="top" |
2131 | 2132 | title="Edit" |
| 2133 | + aria-disabled={isWaiting || disableAction} |
2132 | 2134 | onclick={() => openBotMsgEditor(message)} |
2133 | 2135 | > |
2134 | 2136 | <i class="bx bxs-edit cb-text-primary"></i> |
|
2209 | 2211 | {/if} |
2210 | 2212 | </ul> |
2211 | 2213 |
|
2212 | | - <ChatFileGallery disabled={isSendingMsg || isThinking} /> |
| 2214 | + <ChatFileGallery disabled={isWaiting} /> |
2213 | 2215 | {#if !!lastBotMsg && !isSendingMsg && !isThinking} |
2214 | 2216 | <RichContent |
2215 | 2217 | message={lastBotMsg} |
2216 | | - disabled={isSendingMsg || isThinking || disableAction} |
| 2218 | + disabled={isWaiting || disableAction} |
2217 | 2219 | onConfirm={(title, payload) => confirmSelectedOption(title, payload)} |
2218 | 2220 | /> |
2219 | 2221 | {/if} |
|
2229 | 2231 | class={`cb-btn cb-btn-round ${mode === TRAINING_MODE ? 'cb-btn-danger' : 'cb-btn-primary'} ${isListening ? 'cb-btn-listening' : ''}`} |
2230 | 2232 | aria-label="Start/stop listening" |
2231 | 2233 | aria-pressed={isListening} |
2232 | | - disabled={isSendingMsg || isThinking || disableAction} |
| 2234 | + disabled={isWaiting || disableAction} |
2233 | 2235 | onclick={() => startListen()} |
2234 | 2236 | > |
2235 | 2237 | <i class="mdi mdi-{isListening ? 'microphone' : 'microphone-off'} cb-md-36"></i> |
|
2242 | 2244 | id={'chat-textarea'} |
2243 | 2245 | className={`${!isLite ? 'cb-textarea-more-util' : ''}`} |
2244 | 2246 | maxLength={maxTextLength} |
2245 | | - disabled={isSendingMsg || isThinking || disableAction} |
| 2247 | + disabled={isWaiting || disableAction} |
2246 | 2248 | bind:text={text} |
2247 | 2249 | bind:loadUtils={loadChatUtils} |
2248 | 2250 | bind:options={chatUtilOptions} |
|
2254 | 2256 | <ChatFileUploader |
2255 | 2257 | accept={'.png,.jpg,.jpeg'} |
2256 | 2258 | containerClasses={'cb-util-uploader'} |
2257 | | - disabled={isSendingMsg || isThinking || disableAction} |
| 2259 | + disabled={isWaiting || disableAction} |
2258 | 2260 | onfiledroped={() => refresh()} |
2259 | 2261 | > |
2260 | 2262 | <span> |
|
2268 | 2270 | <ChatFileUploader |
2269 | 2271 | accept={'.pdf,.xlsx,.xls,.csv'} |
2270 | 2272 | containerClasses={'cb-util-uploader'} |
2271 | | - disabled={isSendingMsg || isThinking || disableAction} |
| 2273 | + disabled={isWaiting || disableAction} |
2272 | 2274 | onfiledroped={() => refresh()} |
2273 | 2275 | > |
2274 | 2276 | <span> |
|
2282 | 2284 | <ChatFileUploader |
2283 | 2285 | accept={'.wav,.mp3'} |
2284 | 2286 | containerClasses={'cb-util-uploader'} |
2285 | | - disabled={isSendingMsg || isThinking || disableAction} |
| 2287 | + disabled={isWaiting || disableAction} |
2286 | 2288 | onfiledroped={() => refresh()} |
2287 | 2289 | > |
2288 | 2290 | <span> |
|
2296 | 2298 | </ChatTextArea> |
2297 | 2299 | <div class="cb-util-links"> |
2298 | 2300 | <ChatBigMessage |
2299 | | - disabled={isSendingMsg || isThinking || disableAction} |
| 2301 | + disabled={isWaiting || disableAction} |
2300 | 2302 | onclick={() => toggleBigMessageModal()} |
2301 | 2303 | /> |
2302 | 2304 | {#if PUBLIC_LIVECHAT_FILES_ENABLED === 'true'} |
2303 | 2305 | <ChatUtil |
2304 | | - disabled={isSendingMsg || isThinking || disableAction} |
| 2306 | + disabled={isWaiting || disableAction} |
2305 | 2307 | onclick={() => loadChatUtils = true} |
2306 | 2308 | /> |
2307 | 2309 | {/if} |
|
2323 | 2325 | <button |
2324 | 2326 | type="submit" |
2325 | 2327 | class={`cb-btn cb-btn-round cb-btn-send ${mode === TRAINING_MODE ? 'cb-btn-danger' : 'cb-btn-primary'}`} |
2326 | | - disabled={!_.trim(text) || isSendingMsg || isThinking || disableAction} |
| 2328 | + disabled={!_.trim(text) || isWaiting || disableAction} |
2327 | 2329 | onclick={() => sentTextMessage()} |
2328 | 2330 | > |
2329 | 2331 | <span class="cb-send-label">Send</span> |
|
0 commit comments