Ensure that long message attachments don't show in media gallery

This commit is contained in:
Scott Nonnenberg 2019-06-21 14:06:37 -07:00
parent ddae8708b4
commit 3feb0037e5
4 changed files with 92 additions and 14 deletions

View file

@ -936,16 +936,20 @@
); );
// Unlike visual media, only one non-image attachment is supported // Unlike visual media, only one non-image attachment is supported
const documents = rawDocuments.map(message => { const documents = rawDocuments
const attachments = message.attachments || []; .filter(message =>
const attachment = attachments[0]; Boolean(message.attachments && message.attachments.length)
return { )
contentType: attachment.contentType, .map(message => {
index: 0, const attachments = message.attachments || [];
attachment, const attachment = attachments[0];
message, return {
}; contentType: attachment.contentType,
}); index: 0,
attachment,
message,
};
});
const saveAttachment = async ({ attachment, message } = {}) => { const saveAttachment = async ({ attachment, message } = {}) => {
const timestamp = message.received_at; const timestamp = message.received_at;

View file

@ -133,5 +133,73 @@ describe('Message', () => {
const actual = await Message.initializeAttachmentMetadata(input); const actual = await Message.initializeAttachmentMetadata(input);
assert.deepEqual(actual, expected); assert.deepEqual(actual, expected);
}); });
it('does not include long message attachments', async () => {
const input: IncomingMessage = {
type: 'incoming',
conversationId: 'foo',
id: '11111111-1111-1111-1111-111111111111',
timestamp: 1523317140899,
received_at: 1523317140899,
sent_at: 1523317140800,
attachments: [
{
contentType: MIME.LONG_MESSAGE,
data: stringToArrayBuffer('foo'),
fileName: 'message.txt',
size: 1111,
},
],
};
const expected: IncomingMessage = {
type: 'incoming',
conversationId: 'foo',
id: '11111111-1111-1111-1111-111111111111',
timestamp: 1523317140899,
received_at: 1523317140899,
sent_at: 1523317140800,
attachments: [
{
contentType: MIME.LONG_MESSAGE,
data: stringToArrayBuffer('foo'),
fileName: 'message.txt',
size: 1111,
},
],
hasAttachments: 0,
hasVisualMediaAttachments: undefined,
hasFileAttachments: undefined,
};
const actual = await Message.initializeAttachmentMetadata(input);
assert.deepEqual(actual, expected);
});
it('handles not attachments', async () => {
const input: IncomingMessage = {
type: 'incoming',
conversationId: 'foo',
id: '11111111-1111-1111-1111-111111111111',
timestamp: 1523317140899,
received_at: 1523317140899,
sent_at: 1523317140800,
attachments: [],
};
const expected: IncomingMessage = {
type: 'incoming',
conversationId: 'foo',
id: '11111111-1111-1111-1111-111111111111',
timestamp: 1523317140899,
received_at: 1523317140899,
sent_at: 1523317140800,
attachments: [],
hasAttachments: 0,
hasVisualMediaAttachments: undefined,
hasFileAttachments: undefined,
};
const actual = await Message.initializeAttachmentMetadata(input);
assert.deepEqual(actual, expected);
});
}); });
}); });

View file

@ -9,6 +9,7 @@ export const IMAGE_JPEG = 'image/jpeg' as MIMEType;
export const IMAGE_WEBP = 'image/webp' as MIMEType; export const IMAGE_WEBP = 'image/webp' as MIMEType;
export const VIDEO_MP4 = 'video/mp4' as MIMEType; export const VIDEO_MP4 = 'video/mp4' as MIMEType;
export const VIDEO_QUICKTIME = 'video/quicktime' as MIMEType; export const VIDEO_QUICKTIME = 'video/quicktime' as MIMEType;
export const LONG_MESSAGE = 'text/x-signal-plain' as MIMEType;
export const isJPEG = (value: MIMEType): boolean => value === 'image/jpeg'; export const isJPEG = (value: MIMEType): boolean => value === 'image/jpeg';
export const isImage = (value: MIMEType): boolean => export const isImage = (value: MIMEType): boolean =>

View file

@ -17,12 +17,17 @@ export const initializeAttachmentMetadata = async (
return message; return message;
} }
const hasAttachments = IndexedDB.toIndexableBoolean( const attachments = message.attachments.filter(
message.attachments.length > 0 (attachment: Attachment.Attachment) =>
attachment.contentType !== 'text/x-signal-plain'
); );
const hasAttachments = IndexedDB.toIndexableBoolean(attachments.length > 0);
const hasFileAttachments = hasFileAttachment(message); const hasFileAttachments = hasFileAttachment({ ...message, attachments });
const hasVisualMediaAttachments = hasVisualMediaAttachment(message); const hasVisualMediaAttachments = hasVisualMediaAttachment({
...message,
attachments,
});
return { return {
...message, ...message,