Ensure we don't add empty attachments to quote
This commit is contained in:
parent
84bb9be6a9
commit
12739ac82d
1 changed files with 57 additions and 30 deletions
|
@ -755,41 +755,20 @@
|
||||||
return _.without(this.get('members'), me);
|
return _.without(this.get('members'), me);
|
||||||
},
|
},
|
||||||
|
|
||||||
async makeQuote(quotedMessage) {
|
async getQuoteAttachment(attachments, preview) {
|
||||||
const { getName } = Contact;
|
if (attachments && attachments.length) {
|
||||||
const contact = quotedMessage.getContact();
|
return Promise.all(
|
||||||
const attachments = quotedMessage.get('attachments');
|
attachments
|
||||||
const preview = quotedMessage.get('preview');
|
|
||||||
|
|
||||||
const body = quotedMessage.get('body');
|
|
||||||
const embeddedContact = quotedMessage.get('contact');
|
|
||||||
const embeddedContactName =
|
|
||||||
embeddedContact && embeddedContact.length > 0
|
|
||||||
? getName(embeddedContact[0])
|
|
||||||
: '';
|
|
||||||
|
|
||||||
const media =
|
|
||||||
attachments && attachments.length ? attachments : preview || [];
|
|
||||||
|
|
||||||
return {
|
|
||||||
author: contact.id,
|
|
||||||
id: quotedMessage.get('sent_at'),
|
|
||||||
text: body || embeddedContactName,
|
|
||||||
attachments: await Promise.all(
|
|
||||||
media
|
|
||||||
.filter(
|
.filter(
|
||||||
attachment =>
|
attachment =>
|
||||||
attachment &&
|
attachment &&
|
||||||
(attachment.image || (!attachment.pending && !attachment.error))
|
attachment.contentType &&
|
||||||
|
!attachment.pending &&
|
||||||
|
!attachment.error
|
||||||
)
|
)
|
||||||
.slice(0, 1)
|
.slice(0, 1)
|
||||||
.map(async attachment => {
|
.map(async attachment => {
|
||||||
const { fileName } = attachment;
|
const { fileName, thumbnail, contentType } = attachment;
|
||||||
|
|
||||||
const thumbnail = attachment.thumbnail || attachment.image;
|
|
||||||
const contentType =
|
|
||||||
attachment.contentType ||
|
|
||||||
(attachment.image && attachment.image.contentType);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
contentType,
|
contentType,
|
||||||
|
@ -804,7 +783,55 @@
|
||||||
: null,
|
: null,
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
),
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preview && preview.length) {
|
||||||
|
return Promise.all(
|
||||||
|
preview
|
||||||
|
.filter(item => item && item.image)
|
||||||
|
.slice(0, 1)
|
||||||
|
.map(async attachment => {
|
||||||
|
const { image } = attachment;
|
||||||
|
const { contentType } = image;
|
||||||
|
|
||||||
|
return {
|
||||||
|
contentType,
|
||||||
|
// Our protos library complains about this field being undefined, so we
|
||||||
|
// force it to null
|
||||||
|
fileName: null,
|
||||||
|
thumbnail: image
|
||||||
|
? {
|
||||||
|
...(await loadAttachmentData(image)),
|
||||||
|
objectUrl: getAbsoluteAttachmentPath(image.path),
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
},
|
||||||
|
|
||||||
|
async makeQuote(quotedMessage) {
|
||||||
|
const { getName } = Contact;
|
||||||
|
const contact = quotedMessage.getContact();
|
||||||
|
const attachments = quotedMessage.get('attachments');
|
||||||
|
const preview = quotedMessage.get('preview');
|
||||||
|
|
||||||
|
const body = quotedMessage.get('body');
|
||||||
|
const embeddedContact = quotedMessage.get('contact');
|
||||||
|
const embeddedContactName =
|
||||||
|
embeddedContact && embeddedContact.length > 0
|
||||||
|
? getName(embeddedContact[0])
|
||||||
|
: '';
|
||||||
|
|
||||||
|
return {
|
||||||
|
author: contact.id,
|
||||||
|
id: quotedMessage.get('sent_at'),
|
||||||
|
text: body || embeddedContactName,
|
||||||
|
attachments: await this.getQuoteAttachment(attachments, preview),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue