"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "js/modules/types/message.js" between
Signal-Desktop-1.35.2.tar.gz and Signal-Desktop-1.36.1.tar.gz

About: Signal-Desktop is a cross-platform encrypted messaging service (also available for mobile devices).

message.js  (Signal-Desktop-1.35.2):message.js  (Signal-Desktop-1.36.1)
skipping to change at line 75 skipping to change at line 75
SchemaVersion.isValid(message.schemaVersion) && message.schemaVersion >= 1; SchemaVersion.isValid(message.schemaVersion) && message.schemaVersion >= 1;
if (isInitialized) { if (isInitialized) {
return message; return message;
} }
const numAttachments = Array.isArray(message.attachments) const numAttachments = Array.isArray(message.attachments)
? message.attachments.length ? message.attachments.length
: 0; : 0;
const hasAttachments = numAttachments > 0; const hasAttachments = numAttachments > 0;
if (!hasAttachments) { if (!hasAttachments) {
return Object.assign({}, message, { return { ...message, schemaVersion: INITIAL_SCHEMA_VERSION };
schemaVersion: INITIAL_SCHEMA_VERSION,
});
} }
// All attachments should have the same schema version, so we just pick // All attachments should have the same schema version, so we just pick
// the first one: // the first one:
const firstAttachment = message.attachments[0]; const firstAttachment = message.attachments[0];
const inheritedSchemaVersion = SchemaVersion.isValid( const inheritedSchemaVersion = SchemaVersion.isValid(
firstAttachment.schemaVersion firstAttachment.schemaVersion
) )
? firstAttachment.schemaVersion ? firstAttachment.schemaVersion
: INITIAL_SCHEMA_VERSION; : INITIAL_SCHEMA_VERSION;
const messageWithInitialSchema = Object.assign({}, message, { const messageWithInitialSchema = {
...message,
schemaVersion: inheritedSchemaVersion, schemaVersion: inheritedSchemaVersion,
attachments: message.attachments.map(attachment => attachments: message.attachments.map(attachment =>
Attachment.removeSchemaVersion({ attachment, logger }) Attachment.removeSchemaVersion({ attachment, logger })
), ),
}); };
return messageWithInitialSchema; return messageWithInitialSchema;
}; };
// Middleware // Middleware
// type UpgradeStep = (Message, Context) -> Promise Message // type UpgradeStep = (Message, Context) -> Promise Message
// SchemaVersion -> UpgradeStep -> UpgradeStep // SchemaVersion -> UpgradeStep -> UpgradeStep
exports._withSchemaVersion = ({ schemaVersion, upgrade }) => { exports._withSchemaVersion = ({ schemaVersion, upgrade }) => {
if (!SchemaVersion.isValid(schemaVersion)) { if (!SchemaVersion.isValid(schemaVersion)) {
skipping to change at line 161 skipping to change at line 160
} }
if (!exports.isValid(upgradedMessage)) { if (!exports.isValid(upgradedMessage)) {
logger.error( logger.error(
'Message._withSchemaVersion: Invalid upgraded message:', 'Message._withSchemaVersion: Invalid upgraded message:',
upgradedMessage upgradedMessage
); );
return message; return message;
} }
return Object.assign({}, upgradedMessage, { schemaVersion }); return { ...upgradedMessage, schemaVersion };
}; };
}; };
// Public API // Public API
// _mapAttachments :: (Attachment -> Promise Attachment) -> // _mapAttachments :: (Attachment -> Promise Attachment) ->
// (Message, Context) -> // (Message, Context) ->
// Promise Message // Promise Message
exports._mapAttachments = upgradeAttachment => async (message, context) => { exports._mapAttachments = upgradeAttachment => async (message, context) => {
const upgradeWithContext = attachment => const upgradeWithContext = attachment =>
upgradeAttachment(attachment, context); upgradeAttachment(attachment, context);
const attachments = await Promise.all( const attachments = await Promise.all(
(message.attachments || []).map(upgradeWithContext) (message.attachments || []).map(upgradeWithContext)
); );
return Object.assign({}, message, { attachments }); return { ...message, attachments };
}; };
// Public API // Public API
// _mapContact :: (Contact -> Promise Contact) -> // _mapContact :: (Contact -> Promise Contact) ->
// (Message, Context) -> // (Message, Context) ->
// Promise Message // Promise Message
exports._mapContact = upgradeContact => async (message, context) => { exports._mapContact = upgradeContact => async (message, context) => {
const contextWithMessage = Object.assign({}, context, { message }); const contextWithMessage = { ...context, message };
const upgradeWithContext = contact => const upgradeWithContext = contact =>
upgradeContact(contact, contextWithMessage); upgradeContact(contact, contextWithMessage);
const contact = await Promise.all( const contact = await Promise.all(
(message.contact || []).map(upgradeWithContext) (message.contact || []).map(upgradeWithContext)
); );
return Object.assign({}, message, { contact }); return { ...message, contact };
}; };
// _mapQuotedAttachments :: (QuotedAttachment -> Promise QuotedAttachment) -> // _mapQuotedAttachments :: (QuotedAttachment -> Promise QuotedAttachment) ->
// (Message, Context) -> // (Message, Context) ->
// Promise Message // Promise Message
exports._mapQuotedAttachments = upgradeAttachment => async ( exports._mapQuotedAttachments = upgradeAttachment => async (
message, message,
context context
) => { ) => {
if (!message.quote) { if (!message.quote) {
skipping to change at line 213 skipping to change at line 212
throw new Error('_mapQuotedAttachments: context must have logger object'); throw new Error('_mapQuotedAttachments: context must have logger object');
} }
const upgradeWithContext = async attachment => { const upgradeWithContext = async attachment => {
const { thumbnail } = attachment; const { thumbnail } = attachment;
if (!thumbnail) { if (!thumbnail) {
return attachment; return attachment;
} }
const upgradedThumbnail = await upgradeAttachment(thumbnail, context); const upgradedThumbnail = await upgradeAttachment(thumbnail, context);
return Object.assign({}, attachment, { return { ...attachment, thumbnail: upgradedThumbnail };
thumbnail: upgradedThumbnail,
});
}; };
const quotedAttachments = (message.quote && message.quote.attachments) || []; const quotedAttachments = (message.quote && message.quote.attachments) || [];
const attachments = await Promise.all( const attachments = await Promise.all(
quotedAttachments.map(upgradeWithContext) quotedAttachments.map(upgradeWithContext)
); );
return Object.assign({}, message, { return { ...message, quote: { ...message.quote, attachments } };
quote: Object.assign({}, message.quote, {
attachments,
}),
});
}; };
// _mapPreviewAttachments :: (PreviewAttachment -> Promise PreviewAttachmen t) -> // _mapPreviewAttachments :: (PreviewAttachment -> Promise PreviewAttachmen t) ->
// (Message, Context) -> // (Message, Context) ->
// Promise Message // Promise Message
exports._mapPreviewAttachments = upgradeAttachment => async ( exports._mapPreviewAttachments = upgradeAttachment => async (
message, message,
context context
) => { ) => {
if (!message.preview) { if (!message.preview) {
skipping to change at line 251 skipping to change at line 244
throw new Error('_mapPreviewAttachments: context must have logger object'); throw new Error('_mapPreviewAttachments: context must have logger object');
} }
const upgradeWithContext = async preview => { const upgradeWithContext = async preview => {
const { image } = preview; const { image } = preview;
if (!image) { if (!image) {
return preview; return preview;
} }
const upgradedImage = await upgradeAttachment(image, context); const upgradedImage = await upgradeAttachment(image, context);
return Object.assign({}, preview, { return { ...preview, image: upgradedImage };
image: upgradedImage,
});
}; };
const preview = await Promise.all( const preview = await Promise.all(
(message.preview || []).map(upgradeWithContext) (message.preview || []).map(upgradeWithContext)
); );
return Object.assign({}, message, { return { ...message, preview };
preview,
});
}; };
const toVersion0 = async (message, context) => const toVersion0 = async (message, context) =>
exports.initializeSchemaVersion({ message, logger: context.logger }); exports.initializeSchemaVersion({ message, logger: context.logger });
const toVersion1 = exports._withSchemaVersion({ const toVersion1 = exports._withSchemaVersion({
schemaVersion: 1, schemaVersion: 1,
upgrade: exports._mapAttachments(Attachment.autoOrientJPEG), upgrade: exports._mapAttachments(Attachment.autoOrientJPEG),
}); });
const toVersion2 = exports._withSchemaVersion({ const toVersion2 = exports._withSchemaVersion({
schemaVersion: 2, schemaVersion: 2,
skipping to change at line 536 skipping to change at line 525
}; };
}; };
exports.createAttachmentLoader = loadAttachmentData => { exports.createAttachmentLoader = loadAttachmentData => {
if (!isFunction(loadAttachmentData)) { if (!isFunction(loadAttachmentData)) {
throw new TypeError( throw new TypeError(
'createAttachmentLoader: loadAttachmentData is required' 'createAttachmentLoader: loadAttachmentData is required'
); );
} }
return async message => return async message => ({
Object.assign({}, message, { ...message,
attachments: await Promise.all( attachments: await Promise.all(message.attachments.map(loadAttachmentData)),
message.attachments.map(loadAttachmentData) });
),
});
}; };
exports.loadQuoteData = loadAttachmentData => { exports.loadQuoteData = loadAttachmentData => {
if (!isFunction(loadAttachmentData)) { if (!isFunction(loadAttachmentData)) {
throw new TypeError('loadQuoteData: loadAttachmentData is required'); throw new TypeError('loadQuoteData: loadAttachmentData is required');
} }
return async quote => { return async quote => {
if (!quote) { if (!quote) {
return null; return null;
skipping to change at line 770 skipping to change at line 757
}); });
const writeContactAvatar = async messageContact => { const writeContactAvatar = async messageContact => {
const { avatar } = messageContact; const { avatar } = messageContact;
if (avatar && !avatar.avatar) { if (avatar && !avatar.avatar) {
return omit(messageContact, ['avatar']); return omit(messageContact, ['avatar']);
} }
await writeExistingAttachmentData(avatar.avatar); await writeExistingAttachmentData(avatar.avatar);
return Object.assign({}, messageContact, { return {
avatar: Object.assign({}, avatar, { ...messageContact,
avatar: omit(avatar.avatar, ['data']), avatar: { ...avatar, avatar: omit(avatar.avatar, ['data']) },
}), };
});
}; };
const writePreviewImage = async item => { const writePreviewImage = async item => {
const { image } = item; const { image } = item;
if (!image) { if (!image) {
return omit(item, ['image']); return omit(item, ['image']);
} }
await writeExistingAttachmentData(image); await writeExistingAttachmentData(image);
return Object.assign({}, item, { return { ...item, image: omit(image, ['data']) };
image: omit(image, ['data']),
});
}; };
const messageWithoutAttachmentData = Object.assign( const messageWithoutAttachmentData = {
{}, ...(await writeThumbnails(message, { logger })),
await writeThumbnails(message, { logger }), contact: await Promise.all((contact || []).map(writeContactAvatar)),
{ preview: await Promise.all((preview || []).map(writePreviewImage)),
contact: await Promise.all((contact || []).map(writeContactAvatar)), attachments: await Promise.all(
preview: await Promise.all((preview || []).map(writePreviewImage)), (attachments || []).map(async attachment => {
attachments: await Promise.all( await writeExistingAttachmentData(attachment);
(attachments || []).map(async attachment => {
await writeExistingAttachmentData(attachment); if (attachment.screenshot && attachment.screenshot.data) {
await writeExistingAttachmentData(attachment.screenshot);
if (attachment.screenshot && attachment.screenshot.data) { }
await writeExistingAttachmentData(attachment.screenshot); if (attachment.thumbnail && attachment.thumbnail.data) {
} await writeExistingAttachmentData(attachment.thumbnail);
if (attachment.thumbnail && attachment.thumbnail.data) { }
await writeExistingAttachmentData(attachment.thumbnail);
} return {
...omit(attachment, ['data']),
return { ...(attachment.thumbnail
...omit(attachment, ['data']), ? { thumbnail: omit(attachment.thumbnail, ['data']) }
...(attachment.thumbnail : null),
? { thumbnail: omit(attachment.thumbnail, ['data']) } ...(attachment.screenshot
: null), ? { screenshot: omit(attachment.screenshot, ['data']) }
...(attachment.screenshot : null),
? { screenshot: omit(attachment.screenshot, ['data']) } };
: null), })
}; ),
}) };
),
}
);
return messageWithoutAttachmentData; return messageWithoutAttachmentData;
}; };
}; };
exports.hasExpiration = MessageTS.hasExpiration; exports.hasExpiration = MessageTS.hasExpiration;
 End of changes. 15 change blocks. 
67 lines changed or deleted 48 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)