Mark attachment as corrupted if audio load failed
Sending corrupted audio should not leave user with non-functional UI. Mark attachment as corrupted and show generic attachment UI for it instead.
This commit is contained in:
parent
d6063d71e5
commit
9fa3359477
12 changed files with 98 additions and 5 deletions
|
@ -2967,6 +2967,47 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
return false;
|
||||
}
|
||||
|
||||
markAttachmentAsCorrupted(attachment: AttachmentType): void {
|
||||
if (!attachment.path) {
|
||||
throw new Error(
|
||||
"Attachment can't be marked as corrupted because it wasn't loaded"
|
||||
);
|
||||
}
|
||||
|
||||
// We intentionally don't check in quotes/stickers/contacts/... here,
|
||||
// because this function should be called only for something that can
|
||||
// be displayed as a generic attachment.
|
||||
const attachments: ReadonlyArray<AttachmentType> =
|
||||
this.get('attachments') || [];
|
||||
|
||||
let changed = false;
|
||||
const newAttachments = attachments.map(existing => {
|
||||
if (existing.path !== attachment.path) {
|
||||
return existing;
|
||||
}
|
||||
changed = true;
|
||||
|
||||
return {
|
||||
...existing,
|
||||
isCorrupted: true,
|
||||
};
|
||||
});
|
||||
|
||||
if (!changed) {
|
||||
throw new Error(
|
||||
"Attachment can't be marked as corrupted because it wasn't found"
|
||||
);
|
||||
}
|
||||
|
||||
window.log.info(
|
||||
'markAttachmentAsCorrupted: marking an attachment as corrupted'
|
||||
);
|
||||
|
||||
this.set({
|
||||
attachments: newAttachments,
|
||||
});
|
||||
}
|
||||
|
||||
// eslint-disable-next-line class-methods-use-this
|
||||
async copyFromQuotedMessage(message: WhatIsThis): Promise<boolean> {
|
||||
const { quote } = message;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue