From f1d36a2011732c3d0a6fb6b7c171580d33882882 Mon Sep 17 00:00:00 2001 From: automated-signal <37887102+automated-signal@users.noreply.github.com> Date: Thu, 3 Feb 2022 09:48:32 -0800 Subject: [PATCH] Make sure isPinned is in sync with storage service Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> --- ts/ConversationController.ts | 19 +++++++++++++++++++ ts/background.ts | 9 ++++++++- ts/models/conversations.ts | 10 +++------- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/ts/ConversationController.ts b/ts/ConversationController.ts index 2e9b6ac7d..76cdf55cb 100644 --- a/ts/ConversationController.ts +++ b/ts/ConversationController.ts @@ -832,6 +832,25 @@ export class ConversationController { this.get(conversationId)?.onOpenComplete(loadStart); } + repairPinnedConversations(): void { + const pinnedIds = window.storage.get('pinnedConversationIds', []); + + for (const id of pinnedIds) { + const convo = this.get(id); + + if (!convo || convo.get('isPinned')) { + continue; + } + + log.warn( + `ConversationController: Repairing ${convo.idForLogging()}'s isPinned` + ); + convo.set('isPinned', true); + + window.Signal.Data.updateConversation(convo.attributes); + } + } + private async doLoad(): Promise { log.info('ConversationController: starting initial fetch'); diff --git a/ts/background.ts b/ts/background.ts index c2320a229..fdcc5607c 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -459,6 +459,7 @@ export async function startApp(): Promise { log.info('environment:', window.getEnvironment()); let newVersion = false; + let lastVersion: string | undefined; window.document.title = window.getTitle(); @@ -640,7 +641,7 @@ export async function startApp(): Promise { ); const currentVersion = window.getVersion(); - const lastVersion = window.storage.get('version'); + lastVersion = window.storage.get('version'); newVersion = !lastVersion || currentVersion !== lastVersion; await window.storage.put('version', currentVersion); @@ -1679,6 +1680,12 @@ export async function startApp(): Promise { } } + if (newVersion && lastVersion) { + if (window.isBeforeVersion(lastVersion, 'v5.31.0')) { + window.ConversationController.repairPinnedConversations(); + } + } + window.dispatchEvent(new Event('storage_ready')); badgeImageFileDownloader.checkForFilesToDownload(); diff --git a/ts/models/conversations.ts b/ts/models/conversations.ts index 549d33a81..a87766888 100644 --- a/ts/models/conversations.ts +++ b/ts/models/conversations.ts @@ -4159,9 +4159,7 @@ export class ConversationModel extends window.Backbone if (Boolean(before) !== Boolean(after)) { if (after) { - // we're capturing a storage sync below so - // we don't need to capture it twice - this.unpin({ stopStorageSync: true }); + this.unpin(); } this.captureChange('isArchived'); } @@ -5274,7 +5272,7 @@ export class ConversationModel extends window.Backbone window.Signal.Data.updateConversation(this.attributes); } - unpin({ stopStorageSync = false } = {}): void { + unpin(): void { if (!this.get('isPinned')) { return; } @@ -5287,9 +5285,7 @@ export class ConversationModel extends window.Backbone pinnedConversationIds.delete(this.id); - if (!stopStorageSync) { - this.writePinnedConversations([...pinnedConversationIds]); - } + this.writePinnedConversations([...pinnedConversationIds]); this.set('isPinned', false); window.Signal.Data.updateConversation(this.attributes);