Render error

This commit is contained in:
RMidhunSuresh 2021-12-14 14:23:52 +05:30
parent 545aae31d9
commit 67da746b48
2 changed files with 34 additions and 14 deletions

View file

@ -73,9 +73,27 @@ export class TextTile extends BaseTextTile {
if (!this._replyTextTile) { if (!this._replyTextTile) {
const entry = this._entry.contextEntry; const entry = this._entry.contextEntry;
if (entry) { if (entry) {
this._replyTextTile = new TextTile(this.childOptions({entry, roomVM: this._roomVM, timeline: this._timeline})); this._replyTextTile = new ReplyPreviewTile(this.childOptions({entry, roomVM: this._roomVM, timeline: this._timeline}));
} }
} }
return this._replyTextTile; return this._replyTextTile;
} }
} }
class ReplyPreviewTile extends TextTile {
constructor(options) {
super(options);
}
get isRedacted() {
return this._entry.isRedacted;
}
get decryptionError() {
return !!this._entry.decryptionError;
}
get error() {
return this.isRedacted || this.decryptionError;
}
}

View file

@ -31,23 +31,25 @@ export class ReplyPreviewView extends TemplateView {
return replyContainer; return replyContainer;
} }
_renderError({ error, avatar, senderName }) { _renderError(vm) {
const errorMessage = this._getErrorMessage(error); const errorMessage = this._getErrorMessage(vm);
const children = [tag.span({ className: "statusMessage" }, errorMessage), tag.br()]; const children = [tag.span({ className: "statusMessage" }, errorMessage), tag.br()];
const reply = avatar && senderName ? this._renderReplyHeader(avatar, senderName, children) : let reply;
tag.blockquote(children); try {
reply = this._renderReplyHeader(vm, children);
}
catch {
reply = tag.blockquote(children);
}
return reply; return reply;
} }
_getErrorMessage(error) { _getErrorMessage(vm) {
switch (error.name) { if (vm.isRedacted) {
case "ContextEntryNotFound": return "This message has been deleted.";
case "MissingBody": }
return "This message could not be fetched."; else if (vm.decryptionError) {
case "MessageRedacted": return "This message could not be decrypted."
return "This message has been deleted.";
default:
return error.message;
} }
} }