From d14761087a0c327901227b7bae83763cb9fd7318 Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Wed, 11 Apr 2018 11:21:32 -0400 Subject: [PATCH] Add schema version 4: Attachment metadata --- js/modules/types/message.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/js/modules/types/message.js b/js/modules/types/message.js index 17ef08251..0e8c63978 100644 --- a/js/modules/types/message.js +++ b/js/modules/types/message.js @@ -3,6 +3,8 @@ const { isFunction, isString, omit } = require('lodash'); const Attachment = require('./attachment'); const Errors = require('./errors'); const SchemaVersion = require('./schema_version'); +const { initializeAttachmentMetadata } = + require('../../../ts/types/message/initializeAttachmentMetadata'); const GROUP = 'group'; @@ -20,6 +22,11 @@ const PRIVATE = 'private'; // - Attachments: Write attachment data to disk and store relative path to it. // Version 4 // - Quotes: Write thumbnail data to disk and store relative path to it. +// Version 5 +// - Attachments: Track number and kind of attachments for media gallery +// - `numAttachments: Number` +// - `numVisualMediaAttachments: Number` (for media gallery ‘Media’ view) +// - `numFileAttachments: Number` (for media gallery ‘Documents’ view) const INITIAL_SCHEMA_VERSION = 0; @@ -29,7 +36,7 @@ const INITIAL_SCHEMA_VERSION = 0; // add more upgrade steps, we could design a pipeline that does this // incrementally, e.g. from version 0 / unknown -> 1, 1 --> 2, etc., similar to // how we do database migrations: -exports.CURRENT_SCHEMA_VERSION = 4; +exports.CURRENT_SCHEMA_VERSION = 5; // Public API @@ -206,6 +213,7 @@ const toVersion4 = exports._withSchemaVersion( 4, exports._mapQuotedAttachments(Attachment.migrateDataToFileSystem) ); +const toVersion5 = exports._withSchemaVersion(5, initializeAttachmentMetadata); // UpgradeStep exports.upgradeSchema = async (rawMessage, { writeNewAttachmentData } = {}) => { @@ -214,7 +222,7 @@ exports.upgradeSchema = async (rawMessage, { writeNewAttachmentData } = {}) => { } let message = rawMessage; - const versions = [toVersion0, toVersion1, toVersion2, toVersion3, toVersion4]; + const versions = [toVersion0, toVersion1, toVersion2, toVersion3, toVersion4, toVersion5]; for (let i = 0, max = versions.length; i < max; i += 1) { const currentVersion = versions[i];