Skip to content

Commit

Permalink
ability to remove text message using changeMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
OvidijusParsiunas committed Nov 30, 2024
1 parent 4d12e86 commit cd516fa
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions component/src/views/chat/messages/messageUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@ export class MessageUtils {
});
}

private static removeText(msg: MessagesBase, messageToEls: MessageToElements[0]) {
const elemsToRemove = messageToEls[1].text;
const removalElsIndex = msg.messageElementRefs.findIndex((messageElements) => messageElements === elemsToRemove);
msg.messageElementRefs.splice(removalElsIndex, 1);
elemsToRemove?.outerContainer.remove();
delete messageToEls[0].text;
delete messageToEls[1].text;
}

private static changeText(msg: MessagesBase, messageToEls: MessageToElements[0], newText: string) {
if (messageToEls[1].text) {
msg.renderText(messageToEls[1].text.bubbleElement, newText);
Expand All @@ -214,6 +223,8 @@ export class MessageUtils {
if (messageToEls) {
if (messageBody.text) {
MessageUtils.changeText(msg, messageToEls, messageBody.text);
} else if (messageToEls[1].text) {
MessageUtils.removeText(msg, messageToEls);
}
} else {
console.error('Message index not found. Please use the `getMessages` method to find the correct index');
Expand Down

0 comments on commit cd516fa

Please sign in to comment.