From b5ce45aeededd1be4403e608708c35a0eebed619 Mon Sep 17 00:00:00 2001 From: automated-signal <37887102+automated-signal@users.noreply.github.com> Date: Thu, 17 Jul 2025 11:06:50 -0500 Subject: [PATCH] Stop round-tripping wallpaper data --- ts/services/backups/import.ts | 20 +++- ts/sql/migrations/1410-remove-wallpaper.ts | 41 +++++++ ts/sql/migrations/index.ts | 6 +- ts/test-node/sql/migration_1410_test.ts | 133 +++++++++++++++++++++ ts/types/Storage.d.ts | 13 +- 5 files changed, 201 insertions(+), 12 deletions(-) create mode 100644 ts/sql/migrations/1410-remove-wallpaper.ts create mode 100644 ts/test-node/sql/migration_1410_test.ts diff --git a/ts/services/backups/import.ts b/ts/services/backups/import.ts index 821e2f8318..ace5a96557 100644 --- a/ts/services/backups/import.ts +++ b/ts/services/backups/import.ts @@ -3738,13 +3738,25 @@ export class BackupImportStream extends Writable { autoBubbleColor = true; } + // We only roundtrip wallpaper info in tests since it is not synced in storage service + const shouldImportWallpaper = isTestOrMockEnvironment(); + return { - wallpaperPhotoPointer, - wallpaperPreset, color, customColorData, - dimWallpaperInDarkMode, - autoBubbleColor, + ...(shouldImportWallpaper + ? { + autoBubbleColor, + wallpaperPhotoPointer, + wallpaperPreset, + dimWallpaperInDarkMode, + } + : { + autoBubbleColor: undefined, + wallpaperPhotoPointer: undefined, + wallpaperPreset: undefined, + dimWallpaperInDarkMode: undefined, + }), }; } diff --git a/ts/sql/migrations/1410-remove-wallpaper.ts b/ts/sql/migrations/1410-remove-wallpaper.ts new file mode 100644 index 0000000000..0e91d48631 --- /dev/null +++ b/ts/sql/migrations/1410-remove-wallpaper.ts @@ -0,0 +1,41 @@ +// Copyright 2025 Signal Messenger, LLC +// SPDX-License-Identifier: AGPL-3.0-only + +import type { LoggerType } from '../../types/Logging'; +import { type WritableDB } from '../Interface'; + +export const version = 1410; + +export function updateToSchemaVersion1410( + currentVersion: number, + db: WritableDB, + logger: LoggerType +): void { + if (currentVersion >= 1410) { + return; + } + + db.transaction(() => { + db.exec(` + UPDATE conversations + SET json = json_remove(json, + '$.wallpaperPreset', + '$.wallpaperPhotoPointerBase64', + '$.dimWallpaperInDarkMode', + '$.autoBubbleColor' + ); + + DELETE FROM items + WHERE id IN ( + 'defaultWallpaperPhotoPointer', + 'defaultWallpaperPreset', + 'defaultDimWallpaperInDarkMode', + 'defaultAutoBubbleColor' + ); + `); + + db.pragma('user_version = 1410'); + })(); + + logger.info('updateToSchemaVersion1410: success!'); +} diff --git a/ts/sql/migrations/index.ts b/ts/sql/migrations/index.ts index bd33b41880..3819ae41c1 100644 --- a/ts/sql/migrations/index.ts +++ b/ts/sql/migrations/index.ts @@ -115,10 +115,11 @@ import { updateToSchemaVersion1360 } from './1360-attachments'; import { updateToSchemaVersion1370 } from './1370-message-attachment-indexes'; import { updateToSchemaVersion1380 } from './1380-donation-receipts'; import { updateToSchemaVersion1390 } from './1390-attachment-download-keys'; +import { updateToSchemaVersion1400 } from './1400-simplify-receipts'; import { - updateToSchemaVersion1400, + updateToSchemaVersion1410, version as MAX_VERSION, -} from './1400-simplify-receipts'; +} from './1410-remove-wallpaper'; import { DataWriter } from '../Server'; @@ -2113,6 +2114,7 @@ export const SCHEMA_VERSIONS = [ updateToSchemaVersion1390, updateToSchemaVersion1400, + updateToSchemaVersion1410, ]; export class DBVersionFromFutureError extends Error { diff --git a/ts/test-node/sql/migration_1410_test.ts b/ts/test-node/sql/migration_1410_test.ts new file mode 100644 index 0000000000..3c6ae27602 --- /dev/null +++ b/ts/test-node/sql/migration_1410_test.ts @@ -0,0 +1,133 @@ +// Copyright 2025 Signal Messenger, LLC +// SPDX-License-Identifier: AGPL-3.0-only + +import { assert } from 'chai'; + +import { type WritableDB } from '../../sql/Interface'; +import { createDB, updateToVersion, insertData, getTableData } from './helpers'; +import { createOrUpdate, getById } from '../../sql/util'; + +describe('SQL/updateToSchemaVersion1410', () => { + let db: WritableDB; + + afterEach(() => { + db.close(); + }); + + beforeEach(() => { + db = createDB(); + updateToVersion(db, 1400); + }); + + it('deletes conversation wallpaper data if exists', () => { + const convos = [ + { + id: 'convo-1', + expireTimerVersion: 1, + json: { + wallpaperPreset: 42, + wallpaperPhotoPointerBase64: 'base64', + dimWallpaperInDarkMode: false, + autoBubbleColor: true, + profileName: 'Alice', + }, + }, + { + id: 'convo-2', + expireTimerVersion: 3, + json: { + wallpaperPreset: 42, + wallpaperPhotoPointerBase64: 'base64', + profileName: 'Bob', + }, + }, + { + id: 'convo-3', + expireTimerVersion: 4, + json: { + profileName: 'Charlie', + }, + }, + ]; + insertData(db, 'conversations', convos); + updateToVersion(db, 1410); + + assert.deepStrictEqual(getTableData(db, 'conversations'), [ + { + id: 'convo-1', + expireTimerVersion: 1, + json: { + profileName: 'Alice', + }, + }, + { + id: 'convo-2', + expireTimerVersion: 3, + json: { + profileName: 'Bob', + }, + }, + { + id: 'convo-3', + expireTimerVersion: 4, + json: { + profileName: 'Charlie', + }, + }, + ]); + }); + + it('deletes default wallpaper data if exists', () => { + const items = [ + { + id: 'defaultWallpaperPhotoPointer', + value: JSON.stringify(new Uint8Array([1, 2, 3])), + }, + { + id: 'defaultWallpaperPreset', + value: 12, + }, + { + id: 'defaultDimWallpaperInDarkMode', + value: true, + }, + { + id: 'defaultAutoBubbleColor', + value: false, + }, + { + id: 'otherItem', + value: 'otherItem-shouldBePreserved', + }, + ]; + + for (const item of items) { + createOrUpdate(db, 'items', { id: item.id, value: item }); + } + updateToVersion(db, 1410); + + assert.deepStrictEqual( + getById(db, 'items', 'defaultWallpaperPhotoPointer'), + undefined + ); + assert.deepStrictEqual(getById(db, 'items', 'otherItem'), { + id: 'otherItem', + value: { + id: 'otherItem', + value: 'otherItem-shouldBePreserved', + }, + }); + assert.deepStrictEqual(getTableData(db, 'items'), [ + { + id: 'otherItem', + json: { + id: 'otherItem', + value: { + id: 'otherItem', + value: 'otherItem-shouldBePreserved', + }, + }, + }, + ]); + }); +}); diff --git a/ts/types/Storage.d.ts b/ts/types/Storage.d.ts index ed4e5568ca..fda90dfaf5 100644 --- a/ts/types/Storage.d.ts +++ b/ts/types/Storage.d.ts @@ -78,12 +78,6 @@ export type StorageAccessType = { blocked: ReadonlyArray; defaultConversationColor: DefaultConversationColorType; - // Not used UI, stored as is when imported from backup. - defaultWallpaperPhotoPointer: Uint8Array; - defaultWallpaperPreset: number; - defaultDimWallpaperInDarkMode: boolean; - defaultAutoBubbleColor: boolean; - customColors: CustomColorsItemType; device_name: string; existingOnboardingStoryMessageIds: ReadonlyArray | undefined; @@ -250,6 +244,13 @@ export type StorageAccessType = { avatarsHaveBeenMigrated: boolean; + // Test-only + // Not used UI, stored as is when imported from backup during tests + defaultWallpaperPhotoPointer: Uint8Array; + defaultWallpaperPreset: number; + defaultDimWallpaperInDarkMode: boolean; + defaultAutoBubbleColor: boolean; + // Deprecated 'challenge:retry-message-ids': never; nextSignedKeyRotationTime: number;