Cache result in TextTile

Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
RMidhunSuresh 2021-05-11 16:03:14 +05:30
parent 86f4b6186a
commit 3830a95af2

View file

@ -18,14 +18,22 @@ import {MessageTile} from "./MessageTile.js";
import { MessageBodyBuilder } from "../MessageBodyBuilder.js"; import { MessageBodyBuilder } from "../MessageBodyBuilder.js";
export class TextTile extends MessageTile { export class TextTile extends MessageTile {
get body() {
get _contentBody() {
const content = this._getContent(); const content = this._getContent();
let body = content?.body || ""; let body = content?.body || "";
if (content.msgtype === "m.emote") { if (content.msgtype === "m.emote")
body = `* ${this.displayName} ${body}`; body = `* ${this.displayName} ${body}`;
} return body;
}
get body() {
const body = this._contentBody;
if (body === this._body)
return this._message;
const message = new MessageBodyBuilder(); const message = new MessageBodyBuilder();
message.fromText(body); message.fromText(body);
[this._body, this._message] = [body, message];
return message; return message;
} }
} }