From b7c17212c7dcf9b8c7bbc469ced94043b35e2ba8 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Tue, 22 Aug 2023 09:26:28 -0700 Subject: [PATCH] Keep onboarding story message ids on unlink --- ts/background.ts | 13 +++++++------ ts/services/storageRecordOps.ts | 6 +++++- ts/types/StorageUIKeys.ts | 1 + ts/util/downloadOnboardingStory.ts | 26 ++++---------------------- 4 files changed, 17 insertions(+), 29 deletions(-) diff --git a/ts/background.ts b/ts/background.ts index f52e8b5eadf..a951344d386 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -167,7 +167,6 @@ import { SeenStatus } from './MessageSeenStatus'; import MessageSender from './textsecure/SendMessage'; import type AccountManager from './textsecure/AccountManager'; import { onStoryRecipientUpdate } from './util/onStoryRecipientUpdate'; -import { downloadOnboardingStory } from './util/downloadOnboardingStory'; import { flushAttachmentDownloadQueue } from './util/attachmentDownloadQueue'; import { StartupQueue } from './util/StartupQueue'; import { showConfirmationDialog } from './util/showConfirmationDialog'; @@ -1146,7 +1145,6 @@ export async function startApp(): Promise { (async () => { menuOptions = await window.SignalContext.getMenuOptions(); })(), - downloadOnboardingStory(), ]); await window.ConversationController.checkForConflicts(); } catch (error) { @@ -1505,19 +1503,19 @@ export async function startApp(): Promise { log.info('Expiration start timestamp cleanup: complete'); log.info('listening for registration events'); - window.Whisper.events.on('registration_done', () => { + window.Whisper.events.on('registration_done', async () => { log.info('handling registration event'); strictAssert(server !== undefined, 'WebAPI not ready'); - void server.authenticate( + await server.authenticate( window.textsecure.storage.user.getWebAPICredentials() ); // Cancel throttled calls to refreshRemoteConfig since our auth changed. window.Signal.RemoteConfig.maybeRefreshRemoteConfig.cancel(); - void window.Signal.RemoteConfig.maybeRefreshRemoteConfig(server); + drop(window.Signal.RemoteConfig.maybeRefreshRemoteConfig(server)); - void connect(true); + drop(connect(true)); }); cancelInitializationMessage(); @@ -3013,6 +3011,9 @@ export async function startApp(): Promise { } await window.textsecure.storage.put(VERSION_KEY, window.getVersion()); + // Re-hydrate items from memory; removeAllConfiguration above changed database + await window.storage.fetch(); + log.info('unlinkAndDisconnect: Successfully cleared local configuration'); } catch (eraseError) { log.error( diff --git a/ts/services/storageRecordOps.ts b/ts/services/storageRecordOps.ts index fff8f126798..42c12d07d02 100644 --- a/ts/services/storageRecordOps.ts +++ b/ts/services/storageRecordOps.ts @@ -59,6 +59,8 @@ import dataInterface from '../sql/Client'; import { MY_STORY_ID, StorySendMode } from '../types/Stories'; import * as RemoteConfig from '../RemoteConfig'; import { findAndDeleteOnboardingStoryIfExists } from '../util/findAndDeleteOnboardingStoryIfExists'; +import { downloadOnboardingStory } from '../util/downloadOnboardingStory'; +import { drop } from '../util/drop'; const MY_STORY_BYTES = uuidToBytes(MY_STORY_ID); @@ -1414,7 +1416,9 @@ export async function mergeAccountRecord( hasViewedOnboardingStoryBool ); if (hasViewedOnboardingStoryBool) { - void findAndDeleteOnboardingStoryIfExists(); + drop(findAndDeleteOnboardingStoryIfExists()); + } else { + drop(downloadOnboardingStory()); } } { diff --git a/ts/types/StorageUIKeys.ts b/ts/types/StorageUIKeys.ts index cfcb5d7471f..13a2c5225db 100644 --- a/ts/types/StorageUIKeys.ts +++ b/ts/types/StorageUIKeys.ts @@ -17,6 +17,7 @@ export const STORAGE_UI_KEYS: ReadonlyArray = [ 'call-system-notification', 'customColors', 'defaultConversationColor', + 'existingOnboardingStoryMessageIds', 'hide-menu-bar', 'incoming-call-notification', 'notification-draw-attention', diff --git a/ts/util/downloadOnboardingStory.ts b/ts/util/downloadOnboardingStory.ts index 0a483058e7c..1f05c2faa4a 100644 --- a/ts/util/downloadOnboardingStory.ts +++ b/ts/util/downloadOnboardingStory.ts @@ -11,37 +11,19 @@ import { IMAGE_JPEG } from '../types/MIME'; import { ReadStatus } from '../messages/MessageReadStatus'; import { SeenStatus } from '../MessageSeenStatus'; import { findAndDeleteOnboardingStoryIfExists } from './findAndDeleteOnboardingStoryIfExists'; -import { runStorageServiceSyncJob } from '../services/storage'; import { saveNewMessageBatcher } from './messageBatcher'; import { strictAssert } from './assert'; import { incrementMessageCounter } from './incrementMessageCounter'; -// * Check if we've viewed onboarding story. Short circuit. -// * Run storage service sync (just in case) and check again. -// * If it has been viewed and it's downloaded on this device, delete & return. +// First, this function is meant to be run after a storage service sync + +// * If onboarding story has been viewed and it's downloaded on this device, +// delete & return. // * Check if we've already downloaded the onboarding story. // * Download onboarding story, create db entry, mark as downloaded. // * If story has been viewed mark as viewed on AccountRecord. // * If we viewed it >24 hours ago, delete. export async function downloadOnboardingStory(): Promise { - const hasViewedOnboardingStory = window.storage.get( - 'hasViewedOnboardingStory' - ); - - if (hasViewedOnboardingStory) { - await findAndDeleteOnboardingStoryIfExists(); - return; - } - - runStorageServiceSyncJob(); - - window.Whisper.events.once( - 'storageService:syncComplete', - continueDownloadingOnboardingStory - ); -} - -async function continueDownloadingOnboardingStory(): Promise { const { server } = window.textsecure; strictAssert(server, 'server not initialized');