make sure to keep error state of attachment DL failing

pull/2137/head
audric 3 years ago
parent fe269a0cfe
commit 72409e3f1f

@ -130,7 +130,7 @@ export const MessageAttachment = (props: Props) => {
/> />
</div> </div>
); );
} else if (!firstAttachment.pending && isAudio(attachments)) { } else if (!firstAttachment.pending && !firstAttachment.error && isAudio(attachments)) {
return ( return (
<div <div
role="main" role="main"

@ -609,7 +609,6 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
public async sendMessageJob(message: MessageModel, expireTimer: number | undefined) { public async sendMessageJob(message: MessageModel, expireTimer: number | undefined) {
try { try {
const uploads = await message.uploadData(); const uploads = await message.uploadData();
const { id } = message; const { id } = message;
const destination = this.id; const destination = this.id;

@ -472,9 +472,8 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
if (status) { if (status) {
props.status = status; props.status = status;
} }
const attachmentsProps = attachments
.filter((attachment: any) => !attachment.error) const attachmentsProps = attachments.map(this.getPropsForAttachment);
.map((attachment: any) => this.getPropsForAttachment(attachment));
if (attachmentsProps && attachmentsProps.length) { if (attachmentsProps && attachmentsProps.length) {
props.attachments = attachmentsProps; props.attachments = attachmentsProps;
} }
@ -615,6 +614,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
const isVoiceMessageBool = const isVoiceMessageBool =
// tslint:disable-next-line: no-bitwise // tslint:disable-next-line: no-bitwise
Boolean(flags && flags & SignalService.AttachmentPointer.Flags.VOICE_MESSAGE) || false; Boolean(flags && flags & SignalService.AttachmentPointer.Flags.VOICE_MESSAGE) || false;
return { return {
id, id,
contentType, contentType,

@ -8,7 +8,6 @@ import {
removeAttachmentDownloadJob, removeAttachmentDownloadJob,
resetAttachmentDownloadPending, resetAttachmentDownloadPending,
saveAttachmentDownloadJob, saveAttachmentDownloadJob,
saveMessage,
setAttachmentDownloadJobPending, setAttachmentDownloadJobPending,
} from '../../../ts/data/data'; } from '../../../ts/data/data';
import { MessageModel } from '../../models/message'; import { MessageModel } from '../../models/message';
@ -197,7 +196,7 @@ async function _runJob(job: any) {
await _finishJob(found, id); await _finishJob(found, id);
found = await getMessageById(messageId); found = await getMessageById(messageId);
await _addAttachmentToMessage(found, _markAttachmentAsError(attachment), { type, index }); _addAttachmentToMessage(found, _markAttachmentAsError(attachment), { type, index });
return; return;
} }
@ -213,7 +212,7 @@ async function _runJob(job: any) {
}); });
found = await getMessageById(messageId); found = await getMessageById(messageId);
await _addAttachmentToMessage(found, upgradedAttachment, { type, index }); _addAttachmentToMessage(found, upgradedAttachment, { type, index });
await _finishJob(found, id); await _finishJob(found, id);
} catch (error) { } catch (error) {
@ -227,8 +226,8 @@ async function _runJob(job: any) {
); );
found = await getMessageById(messageId); found = await getMessageById(messageId);
_addAttachmentToMessage(found, _markAttachmentAsError(attachment), { type, index });
await _finishJob(found || null, id); await _finishJob(found || null, id);
await _addAttachmentToMessage(found, _markAttachmentAsError(attachment), { type, index });
return; return;
} }
@ -254,7 +253,6 @@ async function _runJob(job: any) {
async function _finishJob(message: MessageModel | null, id: string) { async function _finishJob(message: MessageModel | null, id: string) {
if (message) { if (message) {
await saveMessage(message.attributes);
const conversation = message.getConversation(); const conversation = message.getConversation();
if (conversation) { if (conversation) {
await message.commit(); await message.commit();
@ -275,11 +273,12 @@ function _markAttachmentAsError(attachment: any) {
return { return {
...omit(attachment, ['key', 'digest', 'id']), ...omit(attachment, ['key', 'digest', 'id']),
error: true, error: true,
pending: false,
}; };
} }
// tslint:disable-next-line: cyclomatic-complexity // tslint:disable-next-line: cyclomatic-complexity
async function _addAttachmentToMessage( function _addAttachmentToMessage(
message: MessageModel | null | undefined, message: MessageModel | null | undefined,
attachment: any, attachment: any,
{ type, index }: any { type, index }: any
@ -298,6 +297,7 @@ async function _addAttachmentToMessage(
); );
} }
_replaceAttachment(attachments, index, attachment, logPrefix); _replaceAttachment(attachments, index, attachment, logPrefix);
return; return;
} }
@ -331,6 +331,7 @@ async function _addAttachmentToMessage(
throw new Error(`_addAttachmentToMessage: attachment ${index} was falsey`); throw new Error(`_addAttachmentToMessage: attachment ${index} was falsey`);
} }
_replaceAttachment(item, 'thumbnail', attachment, logPrefix); _replaceAttachment(item, 'thumbnail', attachment, logPrefix);
return; return;
} }

@ -145,6 +145,7 @@ export type PropsForAttachment = {
isVoiceMessage: boolean; isVoiceMessage: boolean;
pending: boolean; pending: boolean;
fileName: string; fileName: string;
error?: number; // if the download somhehow failed, this will be set to true and be 0-1 once saved in the db
screenshot: { screenshot: {
contentType: string; contentType: string;
width: number; width: number;

@ -1,5 +1,5 @@
import { remote } from 'electron'; import { remote } from 'electron';
import { isArrayBuffer, isUndefined, omit, isEmpty } from 'lodash'; import { isArrayBuffer, isEmpty, isUndefined, omit } from 'lodash';
import { import {
createAbsolutePathGetter, createAbsolutePathGetter,
createDeleter, createDeleter,

Loading…
Cancel
Save