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,7 +936,11 @@
|
||||||
);
|
);
|
||||||
|
|
||||||
// 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
|
||||||
|
.filter(message =>
|
||||||
|
Boolean(message.attachments && message.attachments.length)
|
||||||
|
)
|
||||||
|
.map(message => {
|
||||||
const attachments = message.attachments || [];
|
const attachments = message.attachments || [];
|
||||||
const attachment = attachments[0];
|
const attachment = attachments[0];
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -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 =>
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue