From 1dcee5bc935e00439361cdf4535a3441230e7c48 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Tue, 28 Mar 2023 17:40:29 +1100 Subject: [PATCH] feat: wait for confSyncJob to be done before deleting account --- protos/SignalService.proto | 22 ++++++++--------- .../jobs/ConfigurationSyncDumpJob.ts | 2 ++ .../job_runners/jobs/ConfigurationSyncJob.ts | 8 +++++++ ts/session/utils/sync/syncUtils.ts | 24 +++++++++++++++++-- ts/shims/events.ts | 1 + 5 files changed, 44 insertions(+), 13 deletions(-) diff --git a/protos/SignalService.proto b/protos/SignalService.proto index 3db7416d7..0bbfcf659 100644 --- a/protos/SignalService.proto +++ b/protos/SignalService.proto @@ -180,16 +180,16 @@ message DataMessage { message ClosedGroupControlMessage { enum Type { - NEW = 1; // TODO: should get rid of this once closed group redesign has been released for a while - ENCRYPTION_KEY_PAIR = 3; // TODO: should get rid of this once closed group redesign has been released for a while - NAME_CHANGE = 4; // TODO: should get rid of this once closed group redesign has been released for a while - MEMBERS_ADDED = 5; // TODO: should get rid of this once closed group redesign has been released for a while - MEMBERS_REMOVED = 6; // TODO: should get rid of this once closed group redesign has been released for a while + NEW = 1; + ENCRYPTION_KEY_PAIR = 3; + NAME_CHANGE = 4; + MEMBERS_ADDED = 5; + MEMBERS_REMOVED = 6; MEMBER_LEFT = 7; - ENCRYPTION_KEY_PAIR_REQUEST = 8; // TODO: should get rid of this once closed group redesign has been released for a while + ENCRYPTION_KEY_PAIR_REQUEST = 8; } - // TODO: should get rid of this once closed group redesign has been released for a while + message KeyPairWrapper { // @required required bytes publicKey = 1; // The public key of the user the key pair is meant for @@ -201,11 +201,11 @@ message DataMessage { required Type type = 1; optional bytes publicKey = 2; optional string name = 3; - optional KeyPair encryptionKeyPair = 4; // TODO: should get rid of this once closed group redesign has been released for a while + optional KeyPair encryptionKeyPair = 4; repeated bytes members = 5; - repeated bytes admins = 6; // TODO: should get rid of this once closed group redesign has been released for a while - repeated KeyPairWrapper wrappers = 7; // TODO: should get rid of this once closed group redesign has been released for a while - optional uint32 expireTimer = 8; // TODO: should get rid of this once closed group redesign has been released for a while + repeated bytes admins = 6; + repeated KeyPairWrapper wrappers = 7; + optional uint32 expireTimer = 8; } diff --git a/ts/session/utils/job_runners/jobs/ConfigurationSyncDumpJob.ts b/ts/session/utils/job_runners/jobs/ConfigurationSyncDumpJob.ts index eef3b79c7..dd8f67c33 100644 --- a/ts/session/utils/job_runners/jobs/ConfigurationSyncDumpJob.ts +++ b/ts/session/utils/job_runners/jobs/ConfigurationSyncDumpJob.ts @@ -95,6 +95,8 @@ class ConfigurationSyncDumpJob extends PersistedJob public async run(): Promise { try { if (!window.sessionFeatureFlags.useSharedUtilForUserConfig) { + this.triggerConfSyncJobDone(); return RunJobResult.Success; } window.log.debug(`ConfigurationSyncJob starting ${this.persistedData.identifier}`); @@ -188,6 +190,7 @@ class ConfigurationSyncJob extends PersistedJob // If there are no pending changes then the job can just complete (next time something // is updated we want to try and run immediately so don't scuedule another run in this case) if (isEmpty(singleDestChanges?.messages)) { + this.triggerConfSyncJobDone(); return RunJobResult.Success; } const oldHashesToDelete = new Set(singleDestChanges.allOldHashes); @@ -225,6 +228,7 @@ class ConfigurationSyncJob extends PersistedJob // generate any config dumps which need to be stored await buildAndSaveDumpsToDB(changes, thisJobDestination); + this.triggerConfSyncJobDone(); return RunJobResult.Success; } catch (e) { throw e; @@ -260,6 +264,10 @@ class ConfigurationSyncJob extends PersistedJob private updateLastTickTimestamp() { lastRunConfigSyncJobTimestamp = Date.now(); } + + private triggerConfSyncJobDone() { + window.Whisper.events.trigger(ConfigurationSyncJobDone); + } } /** diff --git a/ts/session/utils/sync/syncUtils.ts b/ts/session/utils/sync/syncUtils.ts index f353441a6..3d401e86e 100644 --- a/ts/session/utils/sync/syncUtils.ts +++ b/ts/session/utils/sync/syncUtils.ts @@ -7,6 +7,7 @@ import { OpenGroupData } from '../../../data/opengroups'; import { ConversationModel } from '../../../models/conversation'; import { SignalService } from '../../../protobuf'; import { ECKeyPair } from '../../../receiver/keypairs'; +import { ConfigurationSyncJobDone } from '../../../shims/events'; import { SnodeNamespaces } from '../../apis/snode_api/namespaces'; import { DURATION } from '../../constants'; import { getConversationController } from '../../conversations'; @@ -78,10 +79,29 @@ export const forceSyncConfigurationNowIfNeeded = async (waitForMessageSent = fal new Promise(resolve => { // TODO this should check for feature flag and queue a ConfigurationSyncJob const allConvos = getConversationController().getConversations(); - // if we hang for more than 10sec, force resolve this promise. + // if we hang for more than 20sec, force resolve this promise. setTimeout(() => { resolve(false); - }, 10000); + }, 20000); + + if (window.sessionFeatureFlags.useSharedUtilForUserConfig) { + void ConfigurationDumpSync.queueNewJobIfNeeded() + .then(ConfigurationSync.queueNewJobIfNeeded) + .catch(e => { + window.log.warn( + 'forceSyncConfigurationNowIfNeeded scheduling of jobs failed with', + e.message + ); + }); + if (waitForMessageSent) { + window.Whisper.events.once(ConfigurationSyncJobDone, () => { + debugger; + resolve(true); + }); + } + + return; + } void getCurrentConfigurationMessage(allConvos) .then(configMessage => { diff --git a/ts/shims/events.ts b/ts/shims/events.ts index b54e3f083..b5e93d876 100644 --- a/ts/shims/events.ts +++ b/ts/shims/events.ts @@ -4,3 +4,4 @@ export function trigger(name: string, param1?: any, param2?: any) { } export const configurationMessageReceived = 'configurationMessageReceived'; +export const ConfigurationSyncJobDone = 'ConfigurationSyncJobDone';