From 2603d53891626e51aac63d156fee0638ed59edb9 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Wed, 26 Jan 2022 15:39:25 -0800 Subject: [PATCH] Improve storage service migration to new field understanding --- ts/ConversationController.ts | 7 +++++-- ts/background.ts | 6 ++---- ts/textsecure/MessageReceiver.ts | 11 ++++++++++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/ts/ConversationController.ts b/ts/ConversationController.ts index c3995e5be..2e9b6ac7d 100644 --- a/ts/ConversationController.ts +++ b/ts/ConversationController.ts @@ -21,6 +21,7 @@ import { Address } from './types/Address'; import { QualifiedAddress } from './types/QualifiedAddress'; import * as log from './logging/log'; import { sleep } from './util/sleep'; +import { isNotNil } from './util/isNotNil'; const MAX_MESSAGE_BODY_LENGTH = 64 * 1024; @@ -789,9 +790,11 @@ export class ConversationController { // If it's scoped to a given conversation, it's easy to trigger('change'). There are // important values in storage and the storage service which change rendering pretty // radically, so this function is necessary to force regeneration of props. - async forceRerender(): Promise { + async forceRerender(identifiers?: Array): Promise { let count = 0; - const conversations = this._conversations.models.slice(); + const conversations = identifiers + ? identifiers.map(identifier => this.get(identifier)).filter(isNotNil) + : this._conversations.models.slice(); log.info( `forceRerender: Starting to loop through ${conversations.length} conversations` ); diff --git a/ts/background.ts b/ts/background.ts index a4b6be5ec..31b4f8e68 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -684,10 +684,8 @@ export async function startApp(): Promise { } if ( - (window.isBeforeVersion(lastVersion, 'v1.36.0-beta.1') && - window.isAfterVersion(lastVersion, 'v1.35.0-beta.1')) || - // 5.30 introduced understanding of new storage service AccountRecord fields - window.isBeforeVersion(lastVersion, 'v5.30.0-alpha') + window.isBeforeVersion(lastVersion, 'v1.36.0-beta.1') && + window.isAfterVersion(lastVersion, 'v1.35.0-beta.1') ) { await window.Signal.Services.eraseAllStorageServiceState(); } diff --git a/ts/textsecure/MessageReceiver.ts b/ts/textsecure/MessageReceiver.ts index b3d02e9f5..7da181d84 100644 --- a/ts/textsecure/MessageReceiver.ts +++ b/ts/textsecure/MessageReceiver.ts @@ -2680,15 +2680,19 @@ export default class MessageReceiver envelope: ProcessedEnvelope, blocked: Proto.SyncMessage.IBlocked ): Promise { + const allIdentifiers = []; let changed = false; if (blocked.numbers) { const previous = this.storage.get('blocked', []); + log.info('handleBlocked: Blocking these numbers:', blocked.numbers); await this.storage.put('blocked', blocked.numbers); if (!areArraysMatchingSets(previous, blocked.numbers)) { changed = true; + allIdentifiers.push(...previous); + allIdentifiers.push(...blocked.numbers); } } if (blocked.uuids) { @@ -2701,6 +2705,8 @@ export default class MessageReceiver if (!areArraysMatchingSets(previous, uuids)) { changed = true; + allIdentifiers.push(...previous); + allIdentifiers.push(...blocked.uuids); } } @@ -2731,6 +2737,8 @@ export default class MessageReceiver if (!areArraysMatchingSets(previous, ids)) { changed = true; + allIdentifiers.push(...previous); + allIdentifiers.push(...ids); } } @@ -2738,7 +2746,8 @@ export default class MessageReceiver if (changed) { log.info('handleBlocked: Block list changed, forcing re-render.'); - window.ConversationController.forceRerender(); + const uniqueIdentifiers = Array.from(new Set(allIdentifiers)); + window.ConversationController.forceRerender(uniqueIdentifiers); } }