From d1aa47544bbed8949d3cbd0ae6384f1f53983d3a Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Mon, 8 Jan 2024 16:31:24 -0800 Subject: [PATCH] upgradeSchema: New keepOnDisk option, used for edits --- ts/signal.ts | 22 ++++++++++++---------- ts/types/Message2.ts | 14 +++++++++++--- ts/util/MessageModelLogger.ts | 3 --- ts/util/handleEditMessage.ts | 5 ++++- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/ts/signal.ts b/ts/signal.ts index 857f64ffdbc..873d356d328 100644 --- a/ts/signal.ts +++ b/ts/signal.ts @@ -111,7 +111,7 @@ type MigrationsModuleType = { }>; upgradeMessageSchema: ( attributes: MessageAttributesType, - options?: { maxVersion?: number } + options?: { maxVersion?: number; keepOnDisk?: boolean } ) => Promise; writeMessageAttachments: ( message: MessageAttributesType @@ -266,24 +266,26 @@ export function initializeMigrations({ }), upgradeMessageSchema: ( message: MessageAttributesType, - options: { maxVersion?: number } = {} + options: { maxVersion?: number; keepOnDisk?: boolean } = {} ) => { - const { maxVersion } = options; + const { maxVersion, keepOnDisk } = options; return MessageType.upgradeSchema(message, { - writeNewAttachmentData, - getRegionCode, + deleteOnDisk, getAbsoluteAttachmentPath, - makeObjectUrl, - revokeObjectUrl, + getAbsoluteStickerPath, getImageDimensions, + getRegionCode, makeImageThumbnail, + makeObjectUrl, makeVideoScreenshot, + revokeObjectUrl, + writeNewAttachmentData, + writeNewStickerData, + + keepOnDisk, logger, maxVersion, - getAbsoluteStickerPath, - writeNewStickerData, - deleteOnDisk, }); }, writeMessageAttachments: MessageType.createAttachmentDataWriter({ diff --git a/ts/types/Message2.ts b/ts/types/Message2.ts index 6e8c3987f21..d895001feb7 100644 --- a/ts/types/Message2.ts +++ b/ts/types/Message2.ts @@ -52,6 +52,7 @@ export type ContextType = { height: number; }>; getRegionCode: () => string | undefined; + keepOnDisk?: boolean; logger: LoggerType; makeImageThumbnail: (params: { size: number; @@ -380,14 +381,19 @@ const toVersion1 = _withSchemaVersion({ context, options ): Promise => { - const { deleteOnDisk } = context; + const { deleteOnDisk, keepOnDisk } = context; const rotatedAttachment = await autoOrientJPEG( attachment, context, options ); - if (attachment.path) { + if ( + !keepOnDisk && + attachment !== rotatedAttachment && + rotatedAttachment.data && + attachment.path + ) { await deleteOnDisk(attachment.path); } @@ -500,6 +506,7 @@ export const upgradeSchema = async ( makeVideoScreenshot, writeNewStickerData, deleteOnDisk, + keepOnDisk, logger, maxVersion = CURRENT_SCHEMA_VERSION, }: ContextType @@ -559,6 +566,7 @@ export const upgradeSchema = async ( getImageDimensions, makeImageThumbnail, makeVideoScreenshot, + keepOnDisk, logger, getAbsoluteStickerPath, getRegionCode, @@ -640,7 +648,7 @@ export const processNewAttachment = async ( logger, }); - if (attachment.path) { + if (rotatedAttachment !== attachment && attachment.path) { await deleteOnDisk(attachment.path); } } diff --git a/ts/util/MessageModelLogger.ts b/ts/util/MessageModelLogger.ts index e422ea21e46..4e6e5243f42 100644 --- a/ts/util/MessageModelLogger.ts +++ b/ts/util/MessageModelLogger.ts @@ -2,7 +2,6 @@ // SPDX-License-Identifier: AGPL-3.0-only import type { MessageModel } from '../models/messages'; -import * as log from '../logging/log'; import { getEnvironment, Environment } from '../environment'; export function getMessageModelLogger(model: MessageModel): MessageModel { @@ -37,8 +36,6 @@ export function getMessageModelLogger(model: MessageModel): MessageModel { // Disallowed set of methods & attributes - log.warn(`MessageModelLogger: model.${property}`, new Error().stack); - if (typeof target[property] === 'function') { return target[property].bind(target); } diff --git a/ts/util/handleEditMessage.ts b/ts/util/handleEditMessage.ts index 6708e56981d..95402a16038 100644 --- a/ts/util/handleEditMessage.ts +++ b/ts/util/handleEditMessage.ts @@ -134,7 +134,10 @@ export async function handleEditMessage( } const upgradedEditedMessageData = - await window.Signal.Migrations.upgradeMessageSchema(editAttributes.message); + await window.Signal.Migrations.upgradeMessageSchema( + editAttributes.message, + { keepOnDisk: true } + ); // Copies over the attachments from the main message if they're the same // and they have already been downloaded.