do not fail if a message has a list of empty attachment

This commit is contained in:
Audric Ackermann 2020-12-08 09:44:18 +11:00
parent f28dfe5a94
commit 4a58b2c9f6
No known key found for this signature in database
GPG key ID: 999F434D76324AD4

View file

@ -174,8 +174,14 @@ class SessionRightPanel extends React.Component<Props, State> {
// Unlike visual media, only one non-image attachment is supported
const documents = rawDocuments.map(
(message: { attachments: Array<any> }) => {
const attachments = message.attachments || [];
const attachment = attachments[0];
// this is to not fail if the attachment is invalid (could be a Long Attachment type which is not supported)
if (!message.attachments?.length) {
window.log.info(
'Got a message with an empty list of attachment. Skipping...'
);
return null;
}
const attachment = message.attachments[0];
return {
contentType: attachment.contentType,
@ -220,7 +226,7 @@ class SessionRightPanel extends React.Component<Props, State> {
return {
media,
documents,
documents: _.compact(documents), // remove null
onItemClick,
};
}