mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
Insert emote text after quotes
This commit is contained in:
parent
b5f16468ce
commit
508214a46b
@ -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() {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user