| 
85 | 85 | 	onMount(async () => {  | 
86 | 86 | 		dialogs = await GetDialogs(params.conversationId);  | 
87 | 87 | 		initPrevSentMessages(dialogs);  | 
 | 88 | +		initContentLogView();  | 
88 | 89 | 
  | 
89 | 90 | 		signalr.onMessageReceivedFromClient = onMessageReceivedFromClient;  | 
90 | 91 | 		signalr.onMessageReceivedFromCsr = onMessageReceivedFromCsr;  | 
 | 
109 | 110 | 		sentMsgIdx = prevSentMsgs.length;  | 
110 | 111 | 	}  | 
111 | 112 | 
  | 
 | 113 | +	function initContentLogView() {  | 
 | 114 | +		isLoadContentLog = $page.url.searchParams.get('isLite') !== 'true';  | 
 | 115 | +	}  | 
 | 116 | +
  | 
 | 117 | +	async function refresh() {  | 
 | 118 | +		// trigger UI render  | 
 | 119 | +		dialogs = dialogs?.map(item => { return { ...item }; }) || [];  | 
 | 120 | +		groupedDialogs = groupDialogs(dialogs);  | 
 | 121 | +		await tick();  | 
 | 122 | +
  | 
 | 123 | +		setTimeout(() => {  | 
 | 124 | +			const { viewport } = scrollbar.elements();  | 
 | 125 | +			viewport.scrollTo({ top: viewport.scrollHeight, behavior: 'smooth' }); // set scroll offset  | 
 | 126 | +		}, 200);  | 
 | 127 | +    }  | 
 | 128 | +
  | 
 | 129 | +	/** @param {import('$types').ChatResponseModel[]} dialogs */  | 
 | 130 | +	function groupDialogs(dialogs) {  | 
 | 131 | +		if (!!!dialogs) return [];  | 
 | 132 | +		const format = 'MMM D, YYYY';  | 
 | 133 | +		// @ts-ignore  | 
 | 134 | +		return _.groupBy(dialogs, (x) => {  | 
 | 135 | +			const createDate = moment.utc(x.created_at).local().format(format);  | 
 | 136 | +			if (createDate == moment.utc().local().format(format)) {  | 
 | 137 | +				return 'Today';  | 
 | 138 | +			} else if (createDate == moment.utc().local().subtract(1, 'days').format(format)) {  | 
 | 139 | +				return 'Yesterday';  | 
 | 140 | +			}  | 
 | 141 | +			return createDate;  | 
 | 142 | +		});  | 
 | 143 | +	}  | 
 | 144 | +
  | 
112 | 145 | 
  | 
113 | 146 | 	/** @param {import('$types').ChatResponseModel} message */  | 
114 | 147 | 	function onMessageReceivedFromClient(message) {  | 
115 |  | -      dialogs.push(message);  | 
116 |  | -      refresh();  | 
117 |  | -      text = "";  | 
 | 148 | +		dialogs.push(message);  | 
 | 149 | +		refresh();  | 
 | 150 | +		text = "";  | 
118 | 151 |     }  | 
119 | 152 | 
  | 
120 | 153 |     /** @param {import('$types').ChatResponseModel} message */  | 
121 | 154 |     function onMessageReceivedFromCsr(message) {  | 
122 |  | -      dialogs.push(message);  | 
123 |  | -      refresh();  | 
 | 155 | +		dialogs.push(message);  | 
 | 156 | +		refresh();  | 
124 | 157 |     }  | 
125 | 158 | 
  | 
126 | 159 |     /** @param {import('$types').ChatResponseModel} message */  | 
 | 
168 | 201 | 				reject(err);  | 
169 | 202 | 			});  | 
170 | 203 | 		});  | 
171 |  | -		  | 
172 | 204 |     }  | 
173 | 205 | 
  | 
174 | 206 |     async function startListen() {  | 
175 | 207 | 		microphoneIcon = "microphone";  | 
176 | 208 | 		webSpeech.onSpeechToTextDetected = (transcript) => {  | 
177 | 209 | 			text = transcript;  | 
178 | 210 | 			if (!!!_.trim(text) || isSendingMsg) return;  | 
 | 211 | +
  | 
179 | 212 | 			sendTextMessage().then(() => {  | 
180 | 213 | 				microphoneIcon = "microphone-off";  | 
181 | 214 | 			}).catch(() => {  | 
182 | 215 | 				microphoneIcon = "microphone-off";  | 
183 | 216 | 			});  | 
184 | 217 | 		}  | 
185 | 218 | 		webSpeech.start();  | 
186 |  | -    }	  | 
187 |  | -
  | 
188 |  | -    async function refresh() {  | 
189 |  | -      // trigger UI render  | 
190 |  | -      dialogs = dialogs?.map(item => { return { ...item }; }) || [];  | 
191 |  | -	  groupedDialogs = groupDialogs(dialogs);  | 
192 |  | -	  await tick();  | 
193 |  | -
  | 
194 |  | -      setTimeout(() => {  | 
195 |  | -		const { viewport } = scrollbar.elements();  | 
196 |  | -		viewport.scrollTo({ top: viewport.scrollHeight, behavior: 'smooth' }); // set scroll offset  | 
197 |  | -	  }, 200);  | 
198 |  | -    }  | 
199 |  | -
  | 
200 |  | -	/** @param {import('$types').ChatResponseModel[]} dialogs */  | 
201 |  | -	function groupDialogs(dialogs) {  | 
202 |  | -		if (!!!dialogs) return [];  | 
203 |  | -		const format = 'MMM D, YYYY';  | 
204 |  | -		// @ts-ignore  | 
205 |  | -		return _.groupBy(dialogs, (x) => {  | 
206 |  | -			const createDate = moment.utc(x.created_at).local().format(format);  | 
207 |  | -			if (createDate == moment.utc().local().format(format)) {  | 
208 |  | -				return 'Today';  | 
209 |  | -			} else if (createDate == moment.utc().local().subtract(1, 'days').format(format)) {  | 
210 |  | -				return 'Yesterday';  | 
211 |  | -			}  | 
212 |  | -			return createDate;  | 
213 |  | -		});  | 
214 | 219 | 	}  | 
215 | 220 | 
  | 
216 | 221 | 	/** @param {any} e */  | 
 | 
260 | 265 | 		});  | 
261 | 266 | 	}  | 
262 | 267 | 
  | 
 | 268 | +	/**  | 
 | 269 | +	 * @param {string} payload  | 
 | 270 | +	 * @param {import('$types').QuickReplyMessage} message  | 
 | 271 | +	 */  | 
 | 272 | +	function clickQuickReply(payload, message) {  | 
 | 273 | +		isSendingMsg = true;  | 
 | 274 | +		sendMessageToHub(params.agentId, params.conversationId, payload).then(() => {  | 
 | 275 | +			isSendingMsg = false;  | 
 | 276 | +			message.quick_replies = [];  | 
 | 277 | +		}).catch(() => {  | 
 | 278 | +			isSendingMsg = false;  | 
 | 279 | +			message.quick_replies = [];  | 
 | 280 | +		});  | 
 | 281 | +	}  | 
 | 282 | +
  | 
263 | 283 | 	function endChat() {  | 
264 | 284 | 		if (window.location === window.parent.location) {  | 
265 | 285 | 			// @ts-ignore  | 
 | 
537 | 557 | 												<RcText message={message.rich_content.message} />  | 
538 | 558 | 												{:else if message.rich_content && message.rich_content.message.rich_type == 'quick_reply'}  | 
539 | 559 | 												<RcQuickReply   | 
540 |  | -													agentId={params.agentId}   | 
541 |  | -													conversationId={params.conversationId}   | 
542 |  | -													message={message.rich_content.message}   | 
 | 560 | +													message={message.rich_content.message}  | 
 | 561 | +													onClickQuickReply={clickQuickReply}  | 
543 | 562 | 												/>  | 
544 | 563 | 												{:else}  | 
545 | 564 | 												<span>{message.text}</span>  | 
 | 
0 commit comments