Message schema 6: Change classification of media and documents
For an easier implementation, we change our original definition of `initializeAttachmentMetadata`. This means we have to re-run it marked as version 6 and mark schema version 5 as deprecated as its definition has changed.
This commit is contained in:
parent
f4a5bc9907
commit
16bc1d34c6
4 changed files with 120 additions and 15 deletions
|
@ -3,13 +3,14 @@ import { assert } from 'chai';
|
|||
|
||||
import * as Message from '../../../../ts/types/message/initializeAttachmentMetadata';
|
||||
import { IncomingMessage } from '../../../../ts/types/Message';
|
||||
import { SignalService } from '../../../../ts/protobuf';
|
||||
import * as MIME from '../../../../ts/types/MIME';
|
||||
// @ts-ignore
|
||||
import { stringToArrayBuffer } from '../../../../js/modules/string_to_array_buffer';
|
||||
|
||||
describe('Message', () => {
|
||||
describe('initializeAttachmentMetadata', () => {
|
||||
it('should handle visual media attachments', async () => {
|
||||
it('should classify visual media attachments', async () => {
|
||||
const input: IncomingMessage = {
|
||||
type: 'incoming',
|
||||
conversationId: 'foo',
|
||||
|
@ -49,5 +50,89 @@ describe('Message', () => {
|
|||
const actual = await Message.initializeAttachmentMetadata(input);
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
it('should classify file 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.APPLICATION_OCTET_STREAM,
|
||||
data: stringToArrayBuffer('foo'),
|
||||
fileName: 'foo.bin',
|
||||
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.APPLICATION_OCTET_STREAM,
|
||||
data: stringToArrayBuffer('foo'),
|
||||
fileName: 'foo.bin',
|
||||
size: 1111,
|
||||
},
|
||||
],
|
||||
hasAttachments: 1,
|
||||
hasVisualMediaAttachments: undefined,
|
||||
hasFileAttachments: 1,
|
||||
};
|
||||
|
||||
const actual = await Message.initializeAttachmentMetadata(input);
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
it('should classify voice 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.AUDIO_AAC,
|
||||
flags: SignalService.AttachmentPointer.Flags.VOICE_MESSAGE,
|
||||
data: stringToArrayBuffer('foo'),
|
||||
fileName: 'Voice Message.aac',
|
||||
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.AUDIO_AAC,
|
||||
flags: SignalService.AttachmentPointer.Flags.VOICE_MESSAGE,
|
||||
data: stringToArrayBuffer('foo'),
|
||||
fileName: 'Voice Message.aac',
|
||||
size: 1111,
|
||||
},
|
||||
],
|
||||
hasAttachments: 1,
|
||||
hasVisualMediaAttachments: undefined,
|
||||
hasFileAttachments: undefined,
|
||||
};
|
||||
|
||||
const actual = await Message.initializeAttachmentMetadata(input);
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
import { partition } from 'lodash';
|
||||
|
||||
import * as Attachment from '../Attachment';
|
||||
import * as IndexedDB from '../IndexedDB';
|
||||
import { Message } from '../Message';
|
||||
import { Message, UserMessage } from '../Message';
|
||||
|
||||
const hasAttachment = (
|
||||
predicate: (value: Attachment.Attachment) => boolean
|
||||
) => (message: UserMessage): IndexedDB.IndexablePresence =>
|
||||
IndexedDB.toIndexablePresence(message.attachments.some(predicate));
|
||||
|
||||
const hasFileAttachment = hasAttachment(Attachment.isFile);
|
||||
const hasVisualMediaAttachment = hasAttachment(Attachment.isVisualMedia);
|
||||
|
||||
export const initializeAttachmentMetadata = async (
|
||||
message: Message
|
||||
|
@ -14,17 +20,14 @@ export const initializeAttachmentMetadata = async (
|
|||
const hasAttachments = IndexedDB.toIndexableBoolean(
|
||||
message.attachments.length > 0
|
||||
);
|
||||
const [hasVisualMediaAttachments, hasFileAttachments] = partition(
|
||||
message.attachments,
|
||||
Attachment.isVisualMedia
|
||||
)
|
||||
.map(attachments => attachments.length > 0)
|
||||
.map(IndexedDB.toIndexablePresence);
|
||||
|
||||
const hasFileAttachments = hasFileAttachment(message);
|
||||
const hasVisualMediaAttachments = hasVisualMediaAttachment(message);
|
||||
|
||||
return {
|
||||
...message,
|
||||
hasAttachments,
|
||||
hasVisualMediaAttachments,
|
||||
hasFileAttachments,
|
||||
hasVisualMediaAttachments,
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue