From daa0617ca8464073891678364ceb69a017a40653 Mon Sep 17 00:00:00 2001 From: Ovidijus Parsiunas Date: Sat, 4 Jan 2025 13:23:47 +0900 Subject: [PATCH] refactoring messages code for consistency --- .../src/views/chat/messages/html/htmlMessages.ts | 8 ++++---- .../src/views/chat/messages/utils/messageUtils.ts | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/component/src/views/chat/messages/html/htmlMessages.ts b/component/src/views/chat/messages/html/htmlMessages.ts index 9fe6cb3cb..7e854a82f 100644 --- a/component/src/views/chat/messages/html/htmlMessages.ts +++ b/component/src/views/chat/messages/html/htmlMessages.ts @@ -27,10 +27,10 @@ export class HTMLMessages { } // prettier-ignore - private static overwrite(messages: MessagesBase, html: string, role: string, messagesEls: MessageElements[]) { + private static overwrite(messages: MessagesBase, html: string, role: string, messageElementRefs: MessageElements[]) { const {messageToElements: msgToEls} = messages; const overwrittenElements = MessageUtils.overwriteMessage( - msgToEls, messagesEls, html, role, 'html', HTMLMessages.HTML_BUBBLE_CLASS); + msgToEls, messageElementRefs, html, role, 'html', HTMLMessages.HTML_BUBBLE_CLASS); if (overwrittenElements) { HTMLMessages.overwriteElements(messages, html, overwrittenElements); } @@ -49,9 +49,9 @@ export class HTMLMessages { // prettier-ignore public static add( messages: MessagesBase, html: string, role: string, - messagesEls: MessageElements[], overwrite?: Overwrite, isTop = false) { + messageElementRefs: MessageElements[], overwrite?: Overwrite, isTop = false) { if (overwrite?.status) { - const overwrittenElements = this.overwrite(messages, html, role, messagesEls); + const overwrittenElements = this.overwrite(messages, html, role, messageElementRefs); if (overwrittenElements) return overwrittenElements; overwrite.status = false; } diff --git a/component/src/views/chat/messages/utils/messageUtils.ts b/component/src/views/chat/messages/utils/messageUtils.ts index f77e93ebb..e013b207a 100644 --- a/component/src/views/chat/messages/utils/messageUtils.ts +++ b/component/src/views/chat/messages/utils/messageUtils.ts @@ -18,14 +18,14 @@ export class MessageUtils { private static readonly POSITION_MIDDLE_MESSAGE_CLASS = 'deep-chat-middle-message'; private static readonly POSITION_BOTTOM_MESSAGE_CLASS = 'deep-chat-bottom-message'; - public static getLastElementsByClass(messagesElements: MessageElements[], classes: string[], avoidedClasses?: string[]) { - for (let i = messagesElements.length - 1; i >= 0; i -= 1) { - const elements = messagesElements[i]; + public static getLastElementsByClass(messageElementRefs: MessageElements[], classes: string[], avoidClasses?: string[]) { + for (let i = messageElementRefs.length - 1; i >= 0; i -= 1) { + const elements = messageElementRefs[i]; if (elements.bubbleElement.classList.contains(classes[0])) { const notFound = classes.slice(1).find((className) => !elements.bubbleElement.classList.contains(className)); if (!notFound) { - if (avoidedClasses) { - const avoided = avoidedClasses.find((className) => elements.bubbleElement.classList.contains(className)); + if (avoidClasses) { + const avoided = avoidClasses.find((className) => elements.bubbleElement.classList.contains(className)); if (!avoided) return elements; } else { return elements; @@ -61,11 +61,11 @@ export class MessageUtils { // IMPORTANT: If the overwrite message does not contain a role property it will look for the last 'ai' role message // and if messages have custom roles, it will still look to update the last 'ai' role message // prettier-ignore - public static overwriteMessage(messageToElements: MessageToElements, messagesElements: MessageElements[], + public static overwriteMessage(messageToElements: MessageToElements, messageElementRefs: MessageElements[], content: string, role: string, contentType: 'text' | 'html', className: string) { // not sure if LoadingStyle.LOADING_MESSAGE_TEXT_CLASS is needed const elements = MessageUtils.getLastElementsByClass( - messagesElements, [MessageUtils.getRoleClass(role), className], [LoadingStyle.BUBBLE_CLASS]); + messageElementRefs, [MessageUtils.getRoleClass(role), className], [LoadingStyle.BUBBLE_CLASS]); const lastMessage = MessageUtils.getLastMessage(messageToElements, role, contentType); if (lastMessage) lastMessage[contentType] = content; return elements;