Insert emote text after quotes

This commit is contained in:
Danila Fedorin 2021-08-04 15:50:42 -07:00
parent b5f16468ce
commit 508214a46b
2 changed files with 17 additions and 8 deletions

View File

@ -142,6 +142,15 @@ export class MessageBody {
this.sourceString = sourceString; this.sourceString = sourceString;
this.parts = parts; 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() { export function tests() {

View File

@ -20,12 +20,7 @@ import {parseHTMLBody} from "../deserialize.js";
export class TextTile extends BaseTextTile { export class TextTile extends BaseTextTile {
_getContentString(key) { _getContentString(key) {
const content = this._getContent(); return this._getContent()?.[key] || "";
let val = content?.[key] || "";
if (content.msgtype === "m.emote") {
val = `* ${this.displayName} ${val}`;
}
return val;
} }
_getPlainBody() { _getPlainBody() {
@ -53,10 +48,15 @@ export class TextTile extends BaseTextTile {
} }
_parseBody(body, format) { _parseBody(body, format) {
let messageBody;
if (format === BodyFormat.Html) { 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 { } else {
return parsePlainBody(body); messageBody = parsePlainBody(body);
} }
if (this._getContent()?.msgtype === "m.emote") {
messageBody.insertEmote(`* ${this.displayName} `);
}
return messageBody;
} }
} }