Ensure that long message attachments don't show in media gallery
This commit is contained in:
parent
ddae8708b4
commit
3feb0037e5
4 changed files with 92 additions and 14 deletions
|
@ -936,16 +936,20 @@
|
|||
);
|
||||
|
||||
// Unlike visual media, only one non-image attachment is supported
|
||||
const documents = rawDocuments.map(message => {
|
||||
const attachments = message.attachments || [];
|
||||
const attachment = attachments[0];
|
||||
return {
|
||||
contentType: attachment.contentType,
|
||||
index: 0,
|
||||
attachment,
|
||||
message,
|
||||
};
|
||||
});
|
||||
const documents = rawDocuments
|
||||
.filter(message =>
|
||||
Boolean(message.attachments && message.attachments.length)
|
||||
)
|
||||
.map(message => {
|
||||
const attachments = message.attachments || [];
|
||||
const attachment = attachments[0];
|
||||
return {
|
||||
contentType: attachment.contentType,
|
||||
index: 0,
|
||||
attachment,
|
||||
message,
|
||||
};
|
||||
});
|
||||
|
||||
const saveAttachment = async ({ attachment, message } = {}) => {
|
||||
const timestamp = message.received_at;
|
||||
|
|
|
@ -133,5 +133,73 @@ describe('Message', () => {
|
|||
const actual = await Message.initializeAttachmentMetadata(input);
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -9,6 +9,7 @@ export const IMAGE_JPEG = 'image/jpeg' as MIMEType;
|
|||
export const IMAGE_WEBP = 'image/webp' as MIMEType;
|
||||
export const VIDEO_MP4 = 'video/mp4' 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 isImage = (value: MIMEType): boolean =>
|
||||
|
|
|
@ -17,12 +17,17 @@ export const initializeAttachmentMetadata = async (
|
|||
return message;
|
||||
}
|
||||
|
||||
const hasAttachments = IndexedDB.toIndexableBoolean(
|
||||
message.attachments.length > 0
|
||||
const attachments = message.attachments.filter(
|
||||
(attachment: Attachment.Attachment) =>
|
||||
attachment.contentType !== 'text/x-signal-plain'
|
||||
);
|
||||
const hasAttachments = IndexedDB.toIndexableBoolean(attachments.length > 0);
|
||||
|
||||
const hasFileAttachments = hasFileAttachment(message);
|
||||
const hasVisualMediaAttachments = hasVisualMediaAttachment(message);
|
||||
const hasFileAttachments = hasFileAttachment({ ...message, attachments });
|
||||
const hasVisualMediaAttachments = hasVisualMediaAttachment({
|
||||
...message,
|
||||
attachments,
|
||||
});
|
||||
|
||||
return {
|
||||
...message,
|
||||
|
|
Loading…
Reference in a new issue