chore: renamed ConfigurationSyncJob to UserSyncJob

pull/2873/head
Audric Ackermann 2 years ago
parent eb77c50fa9
commit d134da3421

@ -45,7 +45,7 @@ import {
import { isDarkTheme } from '../../state/selectors/theme'; import { isDarkTheme } from '../../state/selectors/theme';
import { ThemeStateType } from '../../themes/constants/colors'; import { ThemeStateType } from '../../themes/constants/colors';
import { switchThemeTo } from '../../themes/switchTheme'; import { switchThemeTo } from '../../themes/switchTheme';
import { ConfigurationSync } from '../../session/utils/job_runners/jobs/ConfigurationSyncJob'; import { UserSync } from '../../session/utils/job_runners/jobs/UserSyncJob';
const Section = (props: { type: SectionType }) => { const Section = (props: { type: SectionType }) => {
const ourNumber = useSelector(getOurNumber); const ourNumber = useSelector(getOurNumber);
@ -212,7 +212,7 @@ const doAppStartUp = async () => {
global.setTimeout(() => { global.setTimeout(() => {
// Schedule a confSyncJob in some time to let anything incoming from the network be applied and see if there is a push needed // Schedule a confSyncJob in some time to let anything incoming from the network be applied and see if there is a push needed
void ConfigurationSync.queueNewJobIfNeeded(); void UserSync.queueNewJobIfNeeded();
}, 20000); }, 20000);
}; };

@ -10,7 +10,7 @@ import { SpacerLG } from '../../basic/Text';
import { TypingBubble } from '../../conversation/TypingBubble'; import { TypingBubble } from '../../conversation/TypingBubble';
import { UserUtils } from '../../../session/utils'; import { UserUtils } from '../../../session/utils';
import { ConfigurationSync } from '../../../session/utils/job_runners/jobs/ConfigurationSyncJob'; import { UserSync } from '../../../session/utils/job_runners/jobs/UserSyncJob';
import { SessionUtilUserProfile } from '../../../session/utils/libsession/libsession_utils_user_profile'; import { SessionUtilUserProfile } from '../../../session/utils/libsession/libsession_utils_user_profile';
import { import {
useHasBlindedMsgRequestsEnabled, useHasBlindedMsgRequestsEnabled,
@ -98,7 +98,7 @@ export const SettingsCategoryPrivacy = (props: {
await SessionUtilUserProfile.insertUserProfileIntoWrapper( await SessionUtilUserProfile.insertUserProfileIntoWrapper(
UserUtils.getOurPubKeyStrFromCache() UserUtils.getOurPubKeyStrFromCache()
); );
await ConfigurationSync.queueNewJobIfNeeded(); await UserSync.queueNewJobIfNeeded();
forceUpdate(); forceUpdate();
}} }}
title={window.i18n('blindedMsgReqsSettingTitle')} title={window.i18n('blindedMsgReqsSettingTitle')}

@ -15,7 +15,7 @@ import { getSodiumRenderer } from '../session/crypto';
import { getDecryptedMediaUrl } from '../session/crypto/DecryptedAttachmentsManager'; import { getDecryptedMediaUrl } from '../session/crypto/DecryptedAttachmentsManager';
import { perfEnd, perfStart } from '../session/utils/Performance'; import { perfEnd, perfStart } from '../session/utils/Performance';
import { fromHexToArray, toHex } from '../session/utils/String'; import { fromHexToArray, toHex } from '../session/utils/String';
import { ConfigurationSync } from '../session/utils/job_runners/jobs/ConfigurationSyncJob'; import { UserSync } from '../session/utils/job_runners/jobs/UserSyncJob';
import { SessionUtilContact } from '../session/utils/libsession/libsession_utils_contacts'; import { SessionUtilContact } from '../session/utils/libsession/libsession_utils_contacts';
import { forceSyncConfigurationNowIfNeeded } from '../session/utils/sync/syncUtils'; import { forceSyncConfigurationNowIfNeeded } from '../session/utils/sync/syncUtils';
import { import {
@ -466,7 +466,7 @@ export async function uploadOurAvatar(newAvatarDecrypted?: ArrayBuffer) {
if (newAvatarDecrypted) { if (newAvatarDecrypted) {
await setLastProfileUpdateTimestamp(Date.now()); await setLastProfileUpdateTimestamp(Date.now());
await ConfigurationSync.queueNewJobIfNeeded(); await UserSync.queueNewJobIfNeeded();
const userConfigLibsession = await ReleasedFeatures.checkIsUserConfigFeatureReleased(); const userConfigLibsession = await ReleasedFeatures.checkIsUserConfigFeatureReleased();
if (!userConfigLibsession) { if (!userConfigLibsession) {

@ -114,8 +114,8 @@ async function startJobRunners() {
// start the job runners // start the job runners
await runners.avatarDownloadRunner.loadJobsFromDb(); await runners.avatarDownloadRunner.loadJobsFromDb();
runners.avatarDownloadRunner.startProcessing(); runners.avatarDownloadRunner.startProcessing();
await runners.configurationSyncRunner.loadJobsFromDb(); await runners.userSyncRunner.loadJobsFromDb();
runners.configurationSyncRunner.startProcessing(); runners.userSyncRunner.startProcessing();
await runners.groupSyncRunner.loadJobsFromDb(); await runners.groupSyncRunner.loadJobsFromDb();
runners.groupSyncRunner.startProcessing(); runners.groupSyncRunner.startProcessing();
} }

@ -78,7 +78,7 @@ import {
MessageRequestResponseParams, MessageRequestResponseParams,
} from '../session/messages/outgoing/controlMessage/MessageRequestResponse'; } from '../session/messages/outgoing/controlMessage/MessageRequestResponse';
import { ed25519Str } from '../session/onions/onionPath'; import { ed25519Str } from '../session/onions/onionPath';
import { ConfigurationSync } from '../session/utils/job_runners/jobs/ConfigurationSyncJob'; import { UserSync } from '../session/utils/job_runners/jobs/UserSyncJob';
import { SessionUtilContact } from '../session/utils/libsession/libsession_utils_contacts'; import { SessionUtilContact } from '../session/utils/libsession/libsession_utils_contacts';
import { SessionUtilConvoInfoVolatile } from '../session/utils/libsession/libsession_utils_convo_info_volatile'; import { SessionUtilConvoInfoVolatile } from '../session/utils/libsession/libsession_utils_convo_info_volatile';
import { SessionUtilUserGroups } from '../session/utils/libsession/libsession_utils_user_groups'; import { SessionUtilUserGroups } from '../session/utils/libsession/libsession_utils_user_groups';
@ -2386,7 +2386,7 @@ async function commitConversationAndRefreshWrapper(id: string) {
if (Registration.isDone()) { if (Registration.isDone()) {
// save the new dump if needed to the DB asap // save the new dump if needed to the DB asap
// this call throttled so we do not run this too often (and not for every .commit()) // this call throttled so we do not run this too often (and not for every .commit())
await ConfigurationSync.queueNewJobIfNeeded(); await UserSync.queueNewJobIfNeeded();
} }
convo.triggerUIRefresh(); convo.triggerUIRefresh();
} }

@ -16,7 +16,7 @@ import { ProfileManager } from '../session/profile_manager/ProfileManager';
import { PubKey } from '../session/types'; import { PubKey } from '../session/types';
import { StringUtils, UserUtils } from '../session/utils'; import { StringUtils, UserUtils } from '../session/utils';
import { toHex } from '../session/utils/String'; import { toHex } from '../session/utils/String';
import { ConfigurationSync } from '../session/utils/job_runners/jobs/ConfigurationSyncJob'; import { UserSync } from '../session/utils/job_runners/jobs/UserSyncJob';
import { LibSessionUtil } from '../session/utils/libsession/libsession_utils'; import { LibSessionUtil } from '../session/utils/libsession/libsession_utils';
import { SessionUtilContact } from '../session/utils/libsession/libsession_utils_contacts'; import { SessionUtilContact } from '../session/utils/libsession/libsession_utils_contacts';
import { SessionUtilConvoInfoVolatile } from '../session/utils/libsession/libsession_utils_convo_info_volatile'; import { SessionUtilConvoInfoVolatile } from '../session/utils/libsession/libsession_utils_convo_info_volatile';
@ -910,7 +910,7 @@ async function processUserMergingResults(results: Map<ConfigWrapperUser, Incomin
// Now that the local state has been updated, trigger a config sync (this will push any // Now that the local state has been updated, trigger a config sync (this will push any
// pending updates and properly update the state) // pending updates and properly update the state)
if (anyNeedsPush) { if (anyNeedsPush) {
await ConfigurationSync.queueNewJobIfNeeded(); await UserSync.queueNewJobIfNeeded();
} }
} }

@ -29,7 +29,7 @@ import { SnodeNamespaces } from '../apis/snode_api/namespaces';
import { ClosedGroupMemberLeftMessage } from '../messages/outgoing/controlMessage/group/ClosedGroupMemberLeftMessage'; import { ClosedGroupMemberLeftMessage } from '../messages/outgoing/controlMessage/group/ClosedGroupMemberLeftMessage';
import { ed25519Str } from '../onions/onionPath'; import { ed25519Str } from '../onions/onionPath';
import { UserUtils } from '../utils'; import { UserUtils } from '../utils';
import { ConfigurationSync } from '../utils/job_runners/jobs/ConfigurationSyncJob'; import { UserSync } from '../utils/job_runners/jobs/UserSyncJob';
import { LibSessionUtil } from '../utils/libsession/libsession_utils'; import { LibSessionUtil } from '../utils/libsession/libsession_utils';
import { SessionUtilContact } from '../utils/libsession/libsession_utils_contacts'; import { SessionUtilContact } from '../utils/libsession/libsession_utils_contacts';
import { SessionUtilConvoInfoVolatile } from '../utils/libsession/libsession_utils_convo_info_volatile'; import { SessionUtilConvoInfoVolatile } from '../utils/libsession/libsession_utils_convo_info_volatile';
@ -227,7 +227,7 @@ class ConvoController {
} }
if (!options.fromSyncMessage) { if (!options.fromSyncMessage) {
await ConfigurationSync.queueNewJobIfNeeded(); await UserSync.queueNewJobIfNeeded();
} }
} }
@ -246,7 +246,7 @@ class ConvoController {
await this.removeGroupOrCommunityFromDBAndRedux(conversation.id); await this.removeGroupOrCommunityFromDBAndRedux(conversation.id);
if (!options.fromSyncMessage) { if (!options.fromSyncMessage) {
await ConfigurationSync.queueNewJobIfNeeded(); await UserSync.queueNewJobIfNeeded();
} }
} }
@ -291,7 +291,7 @@ class ConvoController {
} }
if (!options.fromSyncMessage) { if (!options.fromSyncMessage) {
await ConfigurationSync.queueNewJobIfNeeded(); await UserSync.queueNewJobIfNeeded();
} }
} }

@ -4,7 +4,7 @@ import {
FakeSleepForMultiJob, FakeSleepForMultiJob,
} from '../../../test/session/unit/utils/job_runner/FakeSleepForJob'; } from '../../../test/session/unit/utils/job_runner/FakeSleepForJob';
import { AvatarDownload } from './jobs/AvatarDownloadJob'; import { AvatarDownload } from './jobs/AvatarDownloadJob';
import { ConfigurationSync } from './jobs/ConfigurationSyncJob'; import { UserSync } from './jobs/UserSyncJob';
import { PersistedJob, TypeOfPersistedData } from './PersistedJob'; import { PersistedJob, TypeOfPersistedData } from './PersistedJob';
export function persistedJobFromData<T extends TypeOfPersistedData>( export function persistedJobFromData<T extends TypeOfPersistedData>(
@ -15,8 +15,8 @@ export function persistedJobFromData<T extends TypeOfPersistedData>(
} }
switch (data.jobType) { switch (data.jobType) {
case 'ConfigurationSyncJobType': case 'UserSyncJobType':
return new ConfigurationSync.ConfigurationSyncJob(data) as unknown as PersistedJob<T>; return new UserSync.UserSyncJob(data) as unknown as PersistedJob<T>;
case 'AvatarDownloadJobType': case 'AvatarDownloadJobType':
return new AvatarDownload.AvatarDownloadJob(data) as unknown as PersistedJob<T>; return new AvatarDownload.AvatarDownloadJob(data) as unknown as PersistedJob<T>;
case 'FakeSleepForJobType': case 'FakeSleepForJobType':

@ -1,17 +1,17 @@
import { cloneDeep, compact, isArray, isString } from 'lodash'; import { cloneDeep, compact, isArray, isString } from 'lodash';
import { Data } from '../../../data/data'; import { Data } from '../../../data/data';
import { Storage } from '../../../util/storage';
import { timeout } from '../Promise'; import { timeout } from '../Promise';
import { persistedJobFromData } from './JobDeserialization'; import { persistedJobFromData } from './JobDeserialization';
import { JobRunnerType } from './jobs/JobRunnerType';
import { import {
AvatarDownloadPersistedData, AvatarDownloadPersistedData,
ConfigurationSyncPersistedData,
GroupSyncPersistedData, GroupSyncPersistedData,
PersistedJob, PersistedJob,
RunJobResult, RunJobResult,
TypeOfPersistedData, TypeOfPersistedData,
UserSyncPersistedData,
} from './PersistedJob'; } from './PersistedJob';
import { Storage } from '../../../util/storage'; import { JobRunnerType } from './jobs/JobRunnerType';
/** /**
* 'job_in_progress' if there is already a job in progress * 'job_in_progress' if there is already a job in progress
@ -351,10 +351,7 @@ export class PersistedJobRunner<T extends TypeOfPersistedData> {
} }
} }
const configurationSyncRunner = new PersistedJobRunner<ConfigurationSyncPersistedData>( const userSyncRunner = new PersistedJobRunner<UserSyncPersistedData>('UserSyncJob', null);
'ConfigurationSyncJob',
null
);
const groupSyncRunner = new PersistedJobRunner<GroupSyncPersistedData>('GroupSyncJob', null); const groupSyncRunner = new PersistedJobRunner<GroupSyncPersistedData>('GroupSyncJob', null);
const avatarDownloadRunner = new PersistedJobRunner<AvatarDownloadPersistedData>( const avatarDownloadRunner = new PersistedJobRunner<AvatarDownloadPersistedData>(
@ -363,7 +360,7 @@ const avatarDownloadRunner = new PersistedJobRunner<AvatarDownloadPersistedData>
); );
export const runners = { export const runners = {
configurationSyncRunner, userSyncRunner,
groupSyncRunner, groupSyncRunner,
avatarDownloadRunner, avatarDownloadRunner,
}; };

@ -1,7 +1,7 @@
import { cloneDeep, isEmpty } from 'lodash'; import { cloneDeep, isEmpty } from 'lodash';
export type PersistedJobType = export type PersistedJobType =
| 'ConfigurationSyncJobType' | 'UserSyncJobType'
| 'GroupSyncJobType' | 'GroupSyncJobType'
| 'AvatarDownloadJobType' | 'AvatarDownloadJobType'
| 'FakeSleepForJobType' | 'FakeSleepForJobType'
@ -32,15 +32,15 @@ export interface AvatarDownloadPersistedData extends PersistedJobData {
conversationId: string; conversationId: string;
} }
export interface ConfigurationSyncPersistedData extends PersistedJobData { export interface UserSyncPersistedData extends PersistedJobData {
jobType: 'ConfigurationSyncJobType'; jobType: 'UserSyncJobType';
} }
export interface GroupSyncPersistedData extends PersistedJobData { export interface GroupSyncPersistedData extends PersistedJobData {
jobType: 'GroupSyncJobType'; jobType: 'GroupSyncJobType';
} }
export type TypeOfPersistedData = export type TypeOfPersistedData =
| ConfigurationSyncPersistedData | UserSyncPersistedData
| AvatarDownloadPersistedData | AvatarDownloadPersistedData
| FakeSleepJobData | FakeSleepJobData
| FakeSleepForMultiJobData | FakeSleepForMultiJobData

@ -162,7 +162,7 @@ class GroupSyncJob extends PersistedJob<GroupSyncPersistedData> {
} catch (e) { } catch (e) {
throw e; throw e;
} finally { } finally {
window.log.debug(`ConfigurationSyncJob run() took ${Date.now() - start}ms`); window.log.debug(`UserSyncJob run() took ${Date.now() - start}ms`);
// this is a simple way to make sure whatever happens here, we update the lastest timestamp. // this is a simple way to make sure whatever happens here, we update the lastest timestamp.
// (a finally statement is always executed (no matter if exception or returns in other try/catch block) // (a finally statement is always executed (no matter if exception or returns in other try/catch block)

@ -1,5 +1,5 @@
export type JobRunnerType = export type JobRunnerType =
| 'ConfigurationSyncJob' | 'UserSyncJob'
| 'GroupSyncJob' | 'GroupSyncJob'
| 'FakeSleepForJob' | 'FakeSleepForJob'
| 'FakeSleepForMultiJob' | 'FakeSleepForMultiJob'

@ -4,7 +4,7 @@ import { isArray, isEmpty, isNumber } from 'lodash';
import { v4 } from 'uuid'; import { v4 } from 'uuid';
import { UserUtils } from '../..'; import { UserUtils } from '../..';
import { ConfigDumpData } from '../../../../data/configDump/configDump'; import { ConfigDumpData } from '../../../../data/configDump/configDump';
import { ConfigurationSyncJobDone } from '../../../../shims/events'; import { UserSyncJobDone } from '../../../../shims/events';
import { isSignInByLinking } from '../../../../util/storage'; import { isSignInByLinking } from '../../../../util/storage';
import { GenericWrapperActions } from '../../../../webworker/workers/browser/libsession_worker_interface'; import { GenericWrapperActions } from '../../../../webworker/workers/browser/libsession_worker_interface';
import { StoreOnNodeData } from '../../../apis/snode_api/SnodeRequestTypes'; import { StoreOnNodeData } from '../../../apis/snode_api/SnodeRequestTypes';
@ -17,7 +17,7 @@ import { LibSessionUtil, UserSuccessfulChange } from '../../libsession/libsessio
import { runners } from '../JobRunner'; import { runners } from '../JobRunner';
import { import {
AddJobCheckReturn, AddJobCheckReturn,
ConfigurationSyncPersistedData, UserSyncPersistedData,
PersistedJob, PersistedJob,
RunJobResult, RunJobResult,
} from '../PersistedJob'; } from '../PersistedJob';
@ -58,7 +58,7 @@ async function confirmPushedAndDump(
} }
function triggerConfSyncJobDone() { function triggerConfSyncJobDone() {
window.Whisper.events.trigger(ConfigurationSyncJobDone); window.Whisper.events.trigger(UserSyncJobDone);
} }
function isPubkey(us: string): us is PubkeyType { function isPubkey(us: string): us is PubkeyType {
@ -98,7 +98,7 @@ async function pushChangesToUserSwarmIfNeeded() {
// we do a sequence call here. If we do not have the right expected number of results, consider it a failure // we do a sequence call here. If we do not have the right expected number of results, consider it a failure
if (!isArray(result) || result.length !== expectedReplyLength) { if (!isArray(result) || result.length !== expectedReplyLength) {
window.log.info( window.log.info(
`ConfigurationSyncJob: unexpected result length: expected ${expectedReplyLength} but got ${result?.length}` `UserSyncJob: unexpected result length: expected ${expectedReplyLength} but got ${result?.length}`
); );
// this might be a 421 error (already handled) so let's retry this request a little bit later // this might be a 421 error (already handled) so let's retry this request a little bit later
return RunJobResult.RetryJobIfPossible; return RunJobResult.RetryJobIfPossible;
@ -116,7 +116,7 @@ async function pushChangesToUserSwarmIfNeeded() {
return RunJobResult.Success; return RunJobResult.Success;
} }
class ConfigurationSyncJob extends PersistedJob<ConfigurationSyncPersistedData> { class UserSyncJob extends PersistedJob<UserSyncPersistedData> {
constructor({ constructor({
identifier, identifier,
nextAttemptTimestamp, nextAttemptTimestamp,
@ -124,12 +124,12 @@ class ConfigurationSyncJob extends PersistedJob<ConfigurationSyncPersistedData>
currentRetry, currentRetry,
}: Partial< }: Partial<
Pick< Pick<
ConfigurationSyncPersistedData, UserSyncPersistedData,
'identifier' | 'nextAttemptTimestamp' | 'currentRetry' | 'maxAttempts' 'identifier' | 'nextAttemptTimestamp' | 'currentRetry' | 'maxAttempts'
> >
>) { >) {
super({ super({
jobType: 'ConfigurationSyncJobType', jobType: 'UserSyncJobType',
identifier: identifier || v4(), identifier: identifier || v4(),
delayBetweenRetries: defaultMsBetweenRetries, delayBetweenRetries: defaultMsBetweenRetries,
maxAttempts: isNumber(maxAttempts) ? maxAttempts : defaultMaxAttempts, maxAttempts: isNumber(maxAttempts) ? maxAttempts : defaultMaxAttempts,
@ -142,7 +142,7 @@ class ConfigurationSyncJob extends PersistedJob<ConfigurationSyncPersistedData>
const start = Date.now(); const start = Date.now();
try { try {
window.log.debug(`ConfigurationSyncJob starting ${this.persistedData.identifier}`); window.log.debug(`UserSyncJob starting ${this.persistedData.identifier}`);
const us = UserUtils.getOurPubKeyStrFromCache(); const us = UserUtils.getOurPubKeyStrFromCache();
const ed25519Key = await UserUtils.getUserED25519KeyPairBytes(); const ed25519Key = await UserUtils.getUserED25519KeyPairBytes();
@ -158,7 +158,7 @@ class ConfigurationSyncJob extends PersistedJob<ConfigurationSyncPersistedData>
} catch (e) { } catch (e) {
throw e; throw e;
} finally { } finally {
window.log.debug(`ConfigurationSyncJob run() took ${Date.now() - start}ms`); window.log.debug(`UserSyncJob run() took ${Date.now() - start}ms`);
// this is a simple way to make sure whatever happens here, we update the lastest timestamp. // this is a simple way to make sure whatever happens here, we update the lastest timestamp.
// (a finally statement is always executed (no matter if exception or returns in other try/catch block) // (a finally statement is always executed (no matter if exception or returns in other try/catch block)
@ -166,12 +166,12 @@ class ConfigurationSyncJob extends PersistedJob<ConfigurationSyncPersistedData>
} }
} }
public serializeJob(): ConfigurationSyncPersistedData { public serializeJob(): UserSyncPersistedData {
const fromParent = super.serializeBase(); const fromParent = super.serializeBase();
return fromParent; return fromParent;
} }
public addJobCheck(jobs: Array<ConfigurationSyncPersistedData>): AddJobCheckReturn { public addJobCheck(jobs: Array<UserSyncPersistedData>): AddJobCheckReturn {
return this.addJobCheckSameTypePresent(jobs); return this.addJobCheckSameTypePresent(jobs);
} }
@ -180,7 +180,7 @@ class ConfigurationSyncJob extends PersistedJob<ConfigurationSyncPersistedData>
* We never want to add a new sync configuration job if there is already one in the queue. * We never want to add a new sync configuration job if there is already one in the queue.
* This is done by the `addJobCheck` method above * This is done by the `addJobCheck` method above
*/ */
public nonRunningJobsToRemove(_jobs: Array<ConfigurationSyncPersistedData>) { public nonRunningJobsToRemove(_jobs: Array<UserSyncPersistedData>) {
return []; return [];
} }
@ -195,7 +195,7 @@ class ConfigurationSyncJob extends PersistedJob<ConfigurationSyncPersistedData>
/** /**
* Queue a new Sync Configuration if needed job. * Queue a new Sync Configuration if needed job.
* A ConfigurationSyncJob can only be added if there is none of the same type queued already. * A UserSyncJob can only be added if there is none of the same type queued already.
*/ */
async function queueNewJobIfNeeded() { async function queueNewJobIfNeeded() {
if (isSignInByLinking()) { if (isSignInByLinking()) {
@ -210,8 +210,8 @@ async function queueNewJobIfNeeded() {
// window.log.debug('Scheduling ConfSyncJob: ASAP'); // window.log.debug('Scheduling ConfSyncJob: ASAP');
// we postpone by 1000ms to make sure whoever is adding this job is done with what is needs to do first // we postpone by 1000ms to make sure whoever is adding this job is done with what is needs to do first
// this call will make sure that there is only one configuration sync job at all times // this call will make sure that there is only one configuration sync job at all times
await runners.configurationSyncRunner.addJob( await runners.userSyncRunner.addJob(
new ConfigurationSyncJob({ nextAttemptTimestamp: Date.now() + 1000 }) new UserSyncJob({ nextAttemptTimestamp: Date.now() + 1000 })
); );
} else { } else {
// if we did run at t=100, and it is currently t=110, the difference is 10 // if we did run at t=100, and it is currently t=110, the difference is 10
@ -220,14 +220,13 @@ async function queueNewJobIfNeeded() {
const leftBeforeNextTick = Math.max(defaultMsBetweenRetries - diff, 1000); const leftBeforeNextTick = Math.max(defaultMsBetweenRetries - diff, 1000);
// window.log.debug('Scheduling ConfSyncJob: LATER'); // window.log.debug('Scheduling ConfSyncJob: LATER');
await runners.configurationSyncRunner.addJob( await runners.userSyncRunner.addJob(
new ConfigurationSyncJob({ nextAttemptTimestamp: Date.now() + leftBeforeNextTick }) new UserSyncJob({ nextAttemptTimestamp: Date.now() + leftBeforeNextTick })
); );
} }
} }
export const ConfigurationSync = { export const UserSync = {
ConfigurationSyncJob, UserSyncJob,
queueNewJobIfNeeded: () => queueNewJobIfNeeded: () => allowOnlyOneAtATime('UserSyncJob-oneAtAtTime', queueNewJobIfNeeded),
allowOnlyOneAtATime('ConfigurationSyncJob-oneAtAtTime', queueNewJobIfNeeded),
}; };

@ -19,7 +19,7 @@ import {
import { SnodeNamespaces, UserConfigNamespaces } from '../../apis/snode_api/namespaces'; import { SnodeNamespaces, UserConfigNamespaces } from '../../apis/snode_api/namespaces';
import { ed25519Str } from '../../onions/onionPath'; import { ed25519Str } from '../../onions/onionPath';
import { PubKey } from '../../types'; import { PubKey } from '../../types';
import { ConfigurationSync } from '../job_runners/jobs/ConfigurationSyncJob'; import { UserSync } from '../job_runners/jobs/UserSyncJob';
import { import {
BatchResultEntry, BatchResultEntry,
NotEmptyArrayOfBatchResults, NotEmptyArrayOfBatchResults,
@ -39,7 +39,7 @@ async function initializeLibSessionUtilWrappers() {
} }
const privateKeyEd25519 = keypair.privKeyBytes; const privateKeyEd25519 = keypair.privKeyBytes;
// let's plan a sync on start with some room for the app to be ready // let's plan a sync on start with some room for the app to be ready
setTimeout(() => ConfigurationSync.queueNewJobIfNeeded, 20000); setTimeout(() => UserSync.queueNewJobIfNeeded, 20000);
// fetch the dumps we already have from the database // fetch the dumps we already have from the database
const dumps = await ConfigDumpData.getAllDumpsWithData(); const dumps = await ConfigDumpData.getAllDumpsWithData();

@ -18,7 +18,7 @@ import { PubKey } from '../../types';
* *
* Also, to make sure that our wrapper is up to date, we schedule jobs to be run and fetch all contacts and update all the wrappers entries. * Also, to make sure that our wrapper is up to date, we schedule jobs to be run and fetch all contacts and update all the wrappers entries.
* This is done in the * This is done in the
* - `ConfigurationSyncJob` (sending data to the network) and the * - `UserSyncJob` (sending data to the network) and the
* *
*/ */
const mappedContactWrapperValues = new Map<string, ContactInfo>(); const mappedContactWrapperValues = new Map<string, ContactInfo>();

@ -7,7 +7,7 @@ import { OpenGroupData } from '../../../data/opengroups';
import { ConversationModel } from '../../../models/conversation'; import { ConversationModel } from '../../../models/conversation';
import { SignalService } from '../../../protobuf'; import { SignalService } from '../../../protobuf';
import { ECKeyPair } from '../../../receiver/keypairs'; import { ECKeyPair } from '../../../receiver/keypairs';
import { ConfigurationSyncJobDone } from '../../../shims/events'; import { UserSyncJobDone } from '../../../shims/events';
import { ReleasedFeatures } from '../../../util/releaseFeature'; import { ReleasedFeatures } from '../../../util/releaseFeature';
import { Storage } from '../../../util/storage'; import { Storage } from '../../../util/storage';
import { getCompleteUrlFromRoom } from '../../apis/open_group_api/utils/OpenGroupUtils'; import { getCompleteUrlFromRoom } from '../../apis/open_group_api/utils/OpenGroupUtils';
@ -30,7 +30,7 @@ import {
} from '../../messages/outgoing/visibleMessage/VisibleMessage'; } from '../../messages/outgoing/visibleMessage/VisibleMessage';
import { PubKey } from '../../types'; import { PubKey } from '../../types';
import { fromBase64ToArray, fromHexToArray } from '../String'; import { fromBase64ToArray, fromHexToArray } from '../String';
import { ConfigurationSync } from '../job_runners/jobs/ConfigurationSyncJob'; import { UserSync } from '../job_runners/jobs/UserSyncJob';
const ITEM_ID_LAST_SYNC_TIMESTAMP = 'lastSyncedTimestamp'; const ITEM_ID_LAST_SYNC_TIMESTAMP = 'lastSyncedTimestamp';
@ -44,7 +44,7 @@ const writeLastSyncTimestampToDb = async (timestamp: number) =>
* Conditionally Syncs user configuration with other devices linked. * Conditionally Syncs user configuration with other devices linked.
*/ */
export const syncConfigurationIfNeeded = async () => { export const syncConfigurationIfNeeded = async () => {
await ConfigurationSync.queueNewJobIfNeeded(); await UserSync.queueNewJobIfNeeded();
const userConfigLibsession = await ReleasedFeatures.checkIsUserConfigFeatureReleased(); const userConfigLibsession = await ReleasedFeatures.checkIsUserConfigFeatureReleased();
if (!userConfigLibsession) { if (!userConfigLibsession) {
@ -84,16 +84,16 @@ export const forceSyncConfigurationNowIfNeeded = async (waitForMessageSent = fal
resolve(false); resolve(false);
}, 20000); }, 20000);
// the ConfigurationSync also handles dumping in to the DB if we do not need to push the data, but the dumping needs to be done even before the feature flag is true. // the UserSync also handles dumping in to the DB if we do not need to push the data, but the dumping needs to be done even before the feature flag is true.
void ConfigurationSync.queueNewJobIfNeeded().catch(e => { void UserSync.queueNewJobIfNeeded().catch(e => {
window.log.warn( window.log.warn(
'forceSyncConfigurationNowIfNeeded scheduling of jobs ConfigurationSync.queueNewJobIfNeeded failed with: ', 'forceSyncConfigurationNowIfNeeded scheduling of jobs UserSync.queueNewJobIfNeeded failed with: ',
e.message e.message
); );
}); });
if (ReleasedFeatures.isUserConfigFeatureReleasedCached()) { if (ReleasedFeatures.isUserConfigFeatureReleasedCached()) {
if (waitForMessageSent) { if (waitForMessageSent) {
window.Whisper.events.once(ConfigurationSyncJobDone, () => { window.Whisper.events.once(UserSyncJobDone, () => {
resolve(true); resolve(true);
}); });
return; return;

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

@ -13,7 +13,7 @@ import { ConvoHub } from '../../../../session/conversations';
import { PubKey } from '../../../../session/types'; import { PubKey } from '../../../../session/types';
import { UserUtils } from '../../../../session/utils'; import { UserUtils } from '../../../../session/utils';
import { sleepFor } from '../../../../session/utils/Promise'; import { sleepFor } from '../../../../session/utils/Promise';
import { ConfigurationSync } from '../../../../session/utils/job_runners/jobs/ConfigurationSyncJob'; import { UserSync } from '../../../../session/utils/job_runners/jobs/UserSyncJob';
import { TestUtils } from '../../../test-utils'; import { TestUtils } from '../../../test-utils';
import { generateFakeSnodes, stubData } from '../../../test-utils/utils'; import { generateFakeSnodes, stubData } from '../../../test-utils/utils';
@ -52,7 +52,7 @@ describe('SwarmPolling:pollForAllKeys', () => {
ConvoHub.use().reset(); ConvoHub.use().reset();
TestUtils.stubWindowFeatureFlags(); TestUtils.stubWindowFeatureFlags();
TestUtils.stubWindowLog(); TestUtils.stubWindowLog();
Sinon.stub(ConfigurationSync, 'queueNewJobIfNeeded').resolves(); Sinon.stub(UserSync, 'queueNewJobIfNeeded').resolves();
// Utils Stubs // Utils Stubs
Sinon.stub(UserUtils, 'getOurPubKeyStrFromCache').returns(ourNumber); Sinon.stub(UserUtils, 'getOurPubKeyStrFromCache').returns(ourNumber);

@ -1,5 +1,5 @@
import { GetNetworkTime } from '../session/apis/snode_api/getNetworkTime'; import { GetNetworkTime } from '../session/apis/snode_api/getNetworkTime';
import { ConfigurationSync } from '../session/utils/job_runners/jobs/ConfigurationSyncJob'; import { UserSync } from '../session/utils/job_runners/jobs/UserSyncJob';
import { assertUnreachable } from '../types/sqlSharedTypes'; import { assertUnreachable } from '../types/sqlSharedTypes';
import { Storage } from './storage'; import { Storage } from './storage';
@ -87,7 +87,7 @@ async function checkIsFeatureReleased(featureName: FeatureNameTracked): Promise<
await Storage.put(featureStorageItemId(featureName), true); await Storage.put(featureStorageItemId(featureName), true);
setIsFeatureReleasedCached(featureName, true); setIsFeatureReleasedCached(featureName, true);
// trigger a sync right away so our user data is online // trigger a sync right away so our user data is online
await ConfigurationSync.queueNewJobIfNeeded(); await UserSync.queueNewJobIfNeeded();
} }
const isReleased = Boolean(getIsFeatureReleasedCached(featureName)); const isReleased = Boolean(getIsFeatureReleasedCached(featureName));

Loading…
Cancel
Save