Skip to content

Commit

Permalink
fix for clearing messages during stream and after stream
Browse files Browse the repository at this point in the history
  • Loading branch information
OvidijusParsiunas committed Sep 15, 2024
1 parent f3b575c commit 4e1f675
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
21 changes: 15 additions & 6 deletions component/src/views/chat/messages/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,21 +305,30 @@ export class Messages extends MessagesBase {
);
}

private static isActiveElement(bubbleClasslist: DOMTokenList) {
return (
bubbleClasslist.contains(LoadingStyle.BUBBLE_CLASS) ||
bubbleClasslist.contains(LoadingHistory.CLASS) ||
bubbleClasslist.contains(MessageStream.MESSAGE_CLASS)
);
}

// WORK - update all message classes to use deep-chat prefix
private clearMessages(serviceIO: ServiceIO, isReset?: boolean) {
const retainedElements: MessageElements[] = [];
const retainedTextElemenets: [MessageElements, string][] = [];
this.messageElementRefs.forEach((message) => {
const bubbleClasslist = message.bubbleElement.classList;
if (
bubbleClasslist.contains(LoadingStyle.BUBBLE_CLASS) ||
bubbleClasslist.contains(LoadingHistory.CLASS) ||
bubbleClasslist.contains(MessageStream.MESSAGE_CLASS)
) {
if (Messages.isActiveElement(bubbleClasslist)) {
retainedElements.push(message);
} else {
message.outerContainer.remove();
}
});
this.textElementsToText.forEach((textElementToText) => {
const bubbleClasslist = textElementToText[0].bubbleElement.classList;
if (Messages.isActiveElement(bubbleClasslist)) retainedTextElemenets.push(textElementToText);
});
// this is a form of cleanup as this.messageElementRefs does not contain error messages
// and can only be deleted by direct search
Array.from(this.elementRef.children).forEach((messageElement) => {
Expand All @@ -334,7 +343,7 @@ export class Messages extends MessagesBase {
this.addIntroductoryMessages();
}
this.messages.splice(0, this.messages.length);
this.textElementsToText.splice(0, this.textElementsToText.length);
this.textElementsToText = retainedTextElemenets;
this._onClearMessages?.();
delete serviceIO.sessionId;
}
Expand Down
2 changes: 1 addition & 1 deletion component/src/views/chat/messages/messagesBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class MessagesBase {
readonly messageStyles?: MessageStyles;
readonly messages: MessageContentI[] = [];
readonly htmlClassUtilities: HTMLClassUtilities = {};
readonly textElementsToText: [MessageElements, string][] = [];
textElementsToText: [MessageElements, string][] = [];
protected _introPanel?: IntroPanel;
protected readonly _avatars?: Avatars;
protected readonly _names?: Names;
Expand Down
1 change: 1 addition & 0 deletions component/src/views/chat/messages/stream/messageStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export class MessageStream {
if (this._elements) HTMLUtils.apply(this._messages, this._elements.outerContainer);
if (this._message) this._message.html = this._streamedContent;
}
this._elements.bubbleElement.classList.remove(MessageStream.MESSAGE_CLASS);
if (this._message) {
this._messages.sendClientUpdate(MessagesBase.createMessageContent(this._message), false);
}
Expand Down

0 comments on commit 4e1f675

Please sign in to comment.