feat: wait for confSyncJob to be done before deleting account

pull/2620/head
Audric Ackermann 2 years ago
parent c623e2e49e
commit 1dcee5bc93

@ -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;
}

@ -95,6 +95,8 @@ class ConfigurationSyncDumpJob extends PersistedJob<ConfigurationSyncDumpPersist
// so when we call needsDump(), we know for sure that we are up to date
console.time('ConfigurationSyncDumpJob insertAll');
// TODO we need to add the dump of the wrappers of other destination than ourself once we had the closed group handling of config sync job
for (let index = 0; index < LibSessionUtil.requiredUserVariants.length; index++) {
const variant = LibSessionUtil.requiredUserVariants[index];
switch (variant) {

@ -2,6 +2,7 @@ import { compact, isArray, isEmpty, isNumber, isString } from 'lodash';
import { v4 } from 'uuid';
import { UserUtils } from '../..';
import { ConfigDumpData } from '../../../../data/configDump/configDump';
import { ConfigurationSyncJobDone } from '../../../../shims/events';
import { assertUnreachable } from '../../../../types/sqlSharedTypes';
import { GenericWrapperActions } from '../../../../webworker/workers/browser/libsession_worker_interface';
import { NotEmptyArrayOfBatchResults } from '../../../apis/snode_api/SnodeRequestTypes';
@ -148,6 +149,7 @@ class ConfigurationSyncJob extends PersistedJob<ConfigurationSyncPersistedData>
public async run(): Promise<RunJobResult> {
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<ConfigurationSyncPersistedData>
// 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<ConfigurationSyncPersistedData>
// 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<ConfigurationSyncPersistedData>
private updateLastTickTimestamp() {
lastRunConfigSyncJobTimestamp = Date.now();
}
private triggerConfSyncJobDone() {
window.Whisper.events.trigger(ConfigurationSyncJobDone);
}
}
/**

@ -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 => {

@ -4,3 +4,4 @@ export function trigger(name: string, param1?: any, param2?: any) {
}
export const configurationMessageReceived = 'configurationMessageReceived';
export const ConfigurationSyncJobDone = 'ConfigurationSyncJobDone';

Loading…
Cancel
Save