Flesh out the fallback formatting a bit.

This commit is contained in:
Danila Fedorin 2021-07-23 15:52:29 -07:00
parent c0d39a5983
commit 0db6870edb

View file

@ -151,18 +151,48 @@ export class BaseEventEntry extends BaseEntry {
return createAnnotation(this.id, key); return createAnnotation(this.id, key);
} }
_formatReplyBody() { _fallbackBlurb() {
// This is just a rough sketch for now. switch (this.content.msgtype) {
// TODO case-by-case formatting case "m.file":
return "sent a file.";
case "m.image":
return "sent an image.";
case "m.video":
return "sent a video.";
case "m.audio":
return "sent an audio file.";
}
}
_fallbackPrefix() {
return this.content.msgtype === "m.emote" ? "* " : "";
}
_replyFormattedFallback() {
// TODO check for absense? // TODO check for absense?
const bodyLines = this.content.body.split("\n"); // TODO escape unformatted body if needed
const sender = this.sender; const body = this._fallbackBlurb() || this.content.formatted_body || this.content.body;
bodyLines[0] = `<${sender}> ${bodyLines[0]}` const prefix = this._fallbackPrefix();
return `> ${bodyLines.join("\n> ")}\n\n`; return `<mx-reply>
<blockquote>
In reply to
${prefix}<a href="https://matrix.to/#/${this.sender}">${this.displayName}</a>
<br />
${body}
</blockquote>
</mx-reply>`
}
_replyBodyFallback() {
// TODO check for absense?
const body = this._fallbackBlurb() || this.content.body;
const bodyLines = body.split("\n");
bodyLines[0] = `> <${this.sender}> ${bodyLines[0]}`
return `${bodyLines.join("\n> ")}`;
} }
reply(msgtype, body) { reply(msgtype, body) {
return createReply(this.id, msgtype, this._formatReplyBody() + body); return createReply(this.id, msgtype, this._replyBodyFallback() + '\n\n' + body);
} }
/** takes both remote event id and local txn id into account, see overriding in PendingEventEntry */ /** takes both remote event id and local txn id into account, see overriding in PendingEventEntry */