Extract `Message.process`

This commit is contained in:
Daniel Gasienica 2018-02-13 13:25:51 -05:00
parent 4a2e52f68a
commit 2c708eb94f
2 changed files with 11 additions and 13 deletions

View File

@ -15,7 +15,7 @@
;(function() {
'use strict';
const { Attachment } = window.Whisper.Types;
const { Message } = window.Whisper.Types;
// Implicitly used in `indexeddb-backbonejs-adapter`:
// https://github.com/signalapp/Signal-Desktop/blob/4033a9f8137e62ed286170ed5d4941982b1d3a64/components/indexeddb-backbonejs-adapter/backbone-indexeddb.js#L569
@ -521,21 +521,11 @@
{ type: 'group', id: data.message.group.id } :
{ type: 'private', id: data.source };
const processedData = Object.assign({}, data, {
message: Object.assign(
{},
data.message,
{
attachments: await Promise.all(
data.message.attachments.map(Attachment.process)
),
}
),
});
const processedMessage = await Message.process(data.message);
await ConversationController.getOrCreateAndWait(id, type);
return message.handleDataMessage(
processedData.message,
processedMessage,
ev.confirm,
{ initialLoadComplete }
);

View File

@ -1,2 +1,10 @@
const Attachment = require('./attachment');
exports.GROUP = 'group';
exports.PRIVATE = 'private';
// Message -> Promise Message
exports.process = async (message) =>
Object.assign({}, message, {
attachments: await Promise.all(message.attachments.map(Attachment.process)),
})