diff --git a/ts/components/conversation/message/message-content/MessageAttachment.tsx b/ts/components/conversation/message/message-content/MessageAttachment.tsx index 1b1bce4f5..071367e10 100644 --- a/ts/components/conversation/message/message-content/MessageAttachment.tsx +++ b/ts/components/conversation/message/message-content/MessageAttachment.tsx @@ -130,7 +130,7 @@ export const MessageAttachment = (props: Props) => { /> </div> ); - } else if (!firstAttachment.pending && isAudio(attachments)) { + } else if (!firstAttachment.pending && !firstAttachment.error && isAudio(attachments)) { return ( <div role="main" diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index ecacaad35..51309cac9 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -609,7 +609,6 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> { public async sendMessageJob(message: MessageModel, expireTimer: number | undefined) { try { - const uploads = await message.uploadData(); const { id } = message; const destination = this.id; diff --git a/ts/models/message.ts b/ts/models/message.ts index ffa18378c..b7d6ac4c5 100644 --- a/ts/models/message.ts +++ b/ts/models/message.ts @@ -472,9 +472,8 @@ export class MessageModel extends Backbone.Model<MessageAttributes> { if (status) { props.status = status; } - const attachmentsProps = attachments - .filter((attachment: any) => !attachment.error) - .map((attachment: any) => this.getPropsForAttachment(attachment)); + + const attachmentsProps = attachments.map(this.getPropsForAttachment); if (attachmentsProps && attachmentsProps.length) { props.attachments = attachmentsProps; } @@ -615,6 +614,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> { const isVoiceMessageBool = // tslint:disable-next-line: no-bitwise Boolean(flags && flags & SignalService.AttachmentPointer.Flags.VOICE_MESSAGE) || false; + return { id, contentType, diff --git a/ts/session/utils/AttachmentsDownload.ts b/ts/session/utils/AttachmentsDownload.ts index d7826ec3c..386c88538 100644 --- a/ts/session/utils/AttachmentsDownload.ts +++ b/ts/session/utils/AttachmentsDownload.ts @@ -8,7 +8,6 @@ import { removeAttachmentDownloadJob, resetAttachmentDownloadPending, saveAttachmentDownloadJob, - saveMessage, setAttachmentDownloadJobPending, } from '../../../ts/data/data'; import { MessageModel } from '../../models/message'; @@ -197,7 +196,7 @@ async function _runJob(job: any) { await _finishJob(found, id); found = await getMessageById(messageId); - await _addAttachmentToMessage(found, _markAttachmentAsError(attachment), { type, index }); + _addAttachmentToMessage(found, _markAttachmentAsError(attachment), { type, index }); return; } @@ -213,7 +212,7 @@ async function _runJob(job: any) { }); found = await getMessageById(messageId); - await _addAttachmentToMessage(found, upgradedAttachment, { type, index }); + _addAttachmentToMessage(found, upgradedAttachment, { type, index }); await _finishJob(found, id); } catch (error) { @@ -227,8 +226,8 @@ async function _runJob(job: any) { ); found = await getMessageById(messageId); + _addAttachmentToMessage(found, _markAttachmentAsError(attachment), { type, index }); await _finishJob(found || null, id); - await _addAttachmentToMessage(found, _markAttachmentAsError(attachment), { type, index }); return; } @@ -254,7 +253,6 @@ async function _runJob(job: any) { async function _finishJob(message: MessageModel | null, id: string) { if (message) { - await saveMessage(message.attributes); const conversation = message.getConversation(); if (conversation) { await message.commit(); @@ -275,11 +273,12 @@ function _markAttachmentAsError(attachment: any) { return { ...omit(attachment, ['key', 'digest', 'id']), error: true, + pending: false, }; } // tslint:disable-next-line: cyclomatic-complexity -async function _addAttachmentToMessage( +function _addAttachmentToMessage( message: MessageModel | null | undefined, attachment: any, { type, index }: any @@ -298,6 +297,7 @@ async function _addAttachmentToMessage( ); } _replaceAttachment(attachments, index, attachment, logPrefix); + return; } @@ -331,6 +331,7 @@ async function _addAttachmentToMessage( throw new Error(`_addAttachmentToMessage: attachment ${index} was falsey`); } _replaceAttachment(item, 'thumbnail', attachment, logPrefix); + return; } diff --git a/ts/state/ducks/conversations.ts b/ts/state/ducks/conversations.ts index b1b2521f9..002eac6a6 100644 --- a/ts/state/ducks/conversations.ts +++ b/ts/state/ducks/conversations.ts @@ -145,6 +145,7 @@ export type PropsForAttachment = { isVoiceMessage: boolean; pending: boolean; 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: { contentType: string; width: number; diff --git a/ts/types/MessageAttachment.ts b/ts/types/MessageAttachment.ts index 59239ec2a..2b678e83a 100644 --- a/ts/types/MessageAttachment.ts +++ b/ts/types/MessageAttachment.ts @@ -1,5 +1,5 @@ import { remote } from 'electron'; -import { isArrayBuffer, isUndefined, omit, isEmpty } from 'lodash'; +import { isArrayBuffer, isEmpty, isUndefined, omit } from 'lodash'; import { createAbsolutePathGetter, createDeleter,