diff --git a/src/domain/session/room/timeline/MessageBody.js b/src/domain/session/room/timeline/MessageBody.js index d6a61e69..a811425c 100644 --- a/src/domain/session/room/timeline/MessageBody.js +++ b/src/domain/session/room/timeline/MessageBody.js @@ -142,6 +142,15 @@ export class MessageBody { this.sourceString = sourceString; this.parts = parts; } + + insertEmote(string) { + // We want to skip quotes introduced by replies when emoting. + // We assume that such quotes are not TextParts, because replies + // must have a formatted body. + let i = 0; + for (i = 0; i < this.parts.length && this.parts[i].type === "format" && this.parts[i].format === "blockquote"; i++); + this.parts.splice(i, 0, new TextPart(string)); + } } export function tests() { diff --git a/src/domain/session/room/timeline/tiles/TextTile.js b/src/domain/session/room/timeline/tiles/TextTile.js index 3dc830a2..1b235e20 100644 --- a/src/domain/session/room/timeline/tiles/TextTile.js +++ b/src/domain/session/room/timeline/tiles/TextTile.js @@ -20,12 +20,7 @@ import {parseHTMLBody} from "../deserialize.js"; export class TextTile extends BaseTextTile { _getContentString(key) { - const content = this._getContent(); - let val = content?.[key] || ""; - if (content.msgtype === "m.emote") { - val = `* ${this.displayName} ${val}`; - } - return val; + return this._getContent()?.[key] || ""; } _getPlainBody() { @@ -53,10 +48,15 @@ export class TextTile extends BaseTextTile { } _parseBody(body, format) { + let messageBody; if (format === BodyFormat.Html) { - return parseHTMLBody(this.platform, this._mediaRepository, this._entry.isReply, body); + messageBody = parseHTMLBody(this.platform, this._mediaRepository, this._entry.isReply, body); } else { - return parsePlainBody(body); + messageBody = parsePlainBody(body); } + if (this._getContent()?.msgtype === "m.emote") { + messageBody.insertEmote(`* ${this.displayName} `); + } + return messageBody; } }