|
80 | 80 | let isLoadStateLog = false; |
81 | 81 | let isOpenEditMsgModal = false; |
82 | 82 | let isOpenStateModal = false; |
| 83 | + let isSendingMsg = false; |
83 | 84 | |
84 | 85 | onMount(async () => { |
85 | 86 | dialogs = await GetDialogs(params.conversationId); |
|
157 | 158 | window.location.href = `chat/${params.agentId}/${conversation.id}`; |
158 | 159 | } |
159 | 160 |
|
160 | | - async function sendTextMessage() { |
161 | | - await sendMessageToHub(params.agentId, params.conversationId, text); |
| 161 | + function sendTextMessage() { |
| 162 | + isSendingMsg = true; |
| 163 | + return new Promise((resolve, reject) => { |
| 164 | + sendMessageToHub(params.agentId, params.conversationId, text).then(res => { |
| 165 | + isSendingMsg = false; |
| 166 | + resolve(res); |
| 167 | + }).catch(err => { |
| 168 | + isSendingMsg = false; |
| 169 | + reject(err); |
| 170 | + }); |
| 171 | + }); |
| 172 | + |
162 | 173 | } |
163 | 174 |
|
164 | 175 | async function startListen() { |
165 | 176 | microphoneIcon = "microphone"; |
166 | | - webSpeech.onSpeechToTextDetected = async (transcript) => { |
| 177 | + webSpeech.onSpeechToTextDetected = (transcript) => { |
167 | 178 | text = transcript; |
168 | | - await sendTextMessage(); |
169 | | - microphoneIcon = "microphone-off"; |
| 179 | + if (!!!_.trim(text) || isSendingMsg) return; |
| 180 | + sendTextMessage().then(() => { |
| 181 | + microphoneIcon = "microphone-off"; |
| 182 | + }).catch(() => { |
| 183 | + microphoneIcon = "microphone-off"; |
| 184 | + }); |
170 | 185 | } |
171 | 186 | webSpeech.start(); |
172 | 187 | } |
|
186 | 201 | /** @param {import('$types').ChatResponseModel[]} dialogs */ |
187 | 202 | function groupDialogs(dialogs) { |
188 | 203 | if (!!!dialogs) return []; |
| 204 | + const format = 'MMM D, YYYY'; |
189 | 205 | // @ts-ignore |
190 | 206 | return _.groupBy(dialogs, (x) => { |
191 | | - const createDate = moment.utc(x.created_at).local().format('MMM DD YYYY'); |
192 | | - if (createDate == moment.utc().local().format('MMM DD YYYY')) { |
| 207 | + const createDate = moment.utc(x.created_at).local().format(format); |
| 208 | + if (createDate == moment.utc().local().format(format)) { |
193 | 209 | return 'Today'; |
194 | | - } else if (createDate == moment.utc().local().subtract(1, 'days').format('MMM DD YYYY')) { |
| 210 | + } else if (createDate == moment.utc().local().subtract(1, 'days').format(format)) { |
195 | 211 | return 'Yesterday'; |
196 | 212 | } |
197 | 213 | return createDate; |
|
228 | 244 | return; |
229 | 245 | } |
230 | 246 |
|
231 | | - if ((e.key === 'Enter' && (!!e.shiftKey || !!e.ctrlKey)) || e.key !== 'Enter' || !!!_.trim(text)) { |
| 247 | + if ((e.key === 'Enter' && (!!e.shiftKey || !!e.ctrlKey)) || e.key !== 'Enter' || !!!_.trim(text) || isSendingMsg) { |
232 | 248 | return; |
233 | 249 | } |
234 | 250 |
|
235 | 251 | prevSentMsgs = [...prevSentMsgs, text]; |
236 | | - await sendMessageToHub(params.agentId, params.conversationId, text); |
| 252 | + isSendingMsg = true; |
| 253 | + sendMessageToHub(params.agentId, params.conversationId, text).then(() => { |
| 254 | + isSendingMsg = false; |
| 255 | + }).catch(() => { |
| 256 | + isSendingMsg = false; |
| 257 | + }); |
237 | 258 | } |
238 | 259 |
|
239 | 260 | function endChat() { |
|
482 | 503 | </Dropdown> |
483 | 504 | {:else} |
484 | 505 | <div class="cicon-wrap float-start"> |
485 | | - {#if message.sender.role == "client"} |
| 506 | + {#if message.sender.role == UserRole.Client} |
486 | 507 | <img src="images/users/user-dummy.jpg" class="rounded-circle avatar-xs" alt="avatar"> |
487 | 508 | {:else} |
488 | 509 | <img src={PUBLIC_LIVECHAT_ENTRY_ICON} class="rounded-circle avatar-xs" alt="avatar"> |
|
557 | 578 | <button |
558 | 579 | type="submit" |
559 | 580 | class="btn btn-primary btn-rounded chat-send waves-effect waves-light" |
560 | | - disabled={!!!_.trim(text)} |
| 581 | + disabled={!!!_.trim(text) || isSendingMsg} |
561 | 582 | on:click={sendTextMessage} |
562 | 583 | ><span class="d-none d-sm-inline-block me-2">Send</span> |
563 | 584 | <i class="mdi mdi-send" /> |
|
0 commit comments