Skip to content

Commit

Permalink
ability to add new html message via changeMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
OvidijusParsiunas committed Dec 1, 2024
1 parent 79ed937 commit d981cd2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
15 changes: 10 additions & 5 deletions component/src/views/chat/messages/html/htmlMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ export class HTMLMessages {
return overwrittenElements;
}

public static create(messages: MessagesBase, html: string, role: string, isTop = false) {
const messageElements = HTMLMessages.createElements(messages, html, role, isTop);
MessageUtils.fillEmptyMessageElement(messageElements.bubbleElement, html);
HTMLUtils.apply(messages, messageElements.outerContainer);
Legacy.flagHTMLUpdateClass(messageElements.bubbleElement);
messages.applyCustomStyles(messageElements, role, false, messages.messageStyles?.html);
return messageElements;
}

// prettier-ignore
public static add(
messages: MessagesBase, html: string, role: string,
Expand All @@ -46,11 +55,7 @@ export class HTMLMessages {
if (overwrittenElements) return overwrittenElements;
overwrite.status = false;
}
const messageElements = HTMLMessages.createElements(messages, html, role, isTop);
MessageUtils.fillEmptyMessageElement(messageElements.bubbleElement, html);
HTMLUtils.apply(messages, messageElements.outerContainer);
Legacy.flagHTMLUpdateClass(messageElements.bubbleElement);
messages.applyCustomStyles(messageElements, role, false, messages.messageStyles?.html);
const messageElements = HTMLMessages.create(messages, html, role, isTop);
if (!isTop) HTMLMessages.addElement(messages, messageElements.outerContainer);
return messageElements;
}
Expand Down
8 changes: 7 additions & 1 deletion component/src/views/chat/messages/messageUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,13 @@ export class MessageUtils {
if (messageToEls[1].html) {
HTMLMessages.overwriteElements(msg, newHTML, messageToEls[1].html);
} else {
// add new
const messageElements = HTMLMessages.create(msg, newHTML, messageToEls[0].role);
const previousElements = (messageToEls[1].files?.[messageToEls[1].files?.length - 1] ||
messageToEls[1].text) as MessageElements;
msg.elementRef.insertBefore(messageElements.outerContainer, previousElements.outerContainer.nextSibling);
const prevMsgElsIndex = msg.messageElementRefs.findIndex((messageElements) => messageElements === previousElements);
msg.messageElementRefs.splice(prevMsgElsIndex + 1, 0, messageElements);
messageToEls[1].html = messageElements;
}
messageToEls[0].html = newHTML;
}
Expand Down

0 comments on commit d981cd2

Please sign in to comment.