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 { ThemeStateType } from '../../themes/constants/colors';
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 ourNumber = useSelector(getOurNumber);
@ -212,7 +212,7 @@ const doAppStartUp = async () => {
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
void ConfigurationSync.queueNewJobIfNeeded();
void UserSync.queueNewJobIfNeeded();
}, 20000);
};

@ -10,7 +10,7 @@ import { SpacerLG } from '../../basic/Text';
import { TypingBubble } from '../../conversation/TypingBubble';
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 {
useHasBlindedMsgRequestsEnabled,
@ -98,7 +98,7 @@ export const SettingsCategoryPrivacy = (props: {
await SessionUtilUserProfile.insertUserProfileIntoWrapper(
UserUtils.getOurPubKeyStrFromCache()
);
await ConfigurationSync.queueNewJobIfNeeded();
await UserSync.queueNewJobIfNeeded();
forceUpdate();
}}
title={window.i18n('blindedMsgReqsSettingTitle')}

@ -15,7 +15,7 @@ import { getSodiumRenderer } from '../session/crypto';
import { getDecryptedMediaUrl } from '../session/crypto/DecryptedAttachmentsManager';
import { perfEnd, perfStart } from '../session/utils/Performance';
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 { forceSyncConfigurationNowIfNeeded } from '../session/utils/sync/syncUtils';
import {
@ -466,7 +466,7 @@ export async function uploadOurAvatar(newAvatarDecrypted?: ArrayBuffer) {
if (newAvatarDecrypted) {
await setLastProfileUpdateTimestamp(Date.now());
await ConfigurationSync.queueNewJobIfNeeded();
await UserSync.queueNewJobIfNeeded();
const userConfigLibsession = await ReleasedFeatures.checkIsUserConfigFeatureReleased();
if (!userConfigLibsession) {

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

@ -78,7 +78,7 @@ import {
MessageRequestResponseParams,
} from '../session/messages/outgoing/controlMessage/MessageRequestResponse';
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 { SessionUtilConvoInfoVolatile } from '../session/utils/libsession/libsession_utils_convo_info_volatile';
import { SessionUtilUserGroups } from '../session/utils/libsession/libsession_utils_user_groups';
@ -2386,7 +2386,7 @@ async function commitConversationAndRefreshWrapper(id: string) {
if (Registration.isDone()) {
// 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())
await ConfigurationSync.queueNewJobIfNeeded();
await UserSync.queueNewJobIfNeeded();
}
convo.triggerUIRefresh();
}

@ -16,7 +16,7 @@ import { ProfileManager } from '../session/profile_manager/ProfileManager';
import { PubKey } from '../session/types';
import { StringUtils, UserUtils } from '../session/utils';
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 { SessionUtilContact } from '../session/utils/libsession/libsession_utils_contacts';
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
// pending updates and properly update the state)
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 { ed25519Str } from '../onions/onionPath';
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 { SessionUtilContact } from '../utils/libsession/libsession_utils_contacts';
import { SessionUtilConvoInfoVolatile } from '../utils/libsession/libsession_utils_convo_info_volatile';
@ -227,7 +227,7 @@ class ConvoController {
}
if (!options.fromSyncMessage) {
await ConfigurationSync.queueNewJobIfNeeded();
await UserSync.queueNewJobIfNeeded();
}
}
@ -246,7 +246,7 @@ class ConvoController {
await this.removeGroupOrCommunityFromDBAndRedux(conversation.id);
if (!options.fromSyncMessage) {
await ConfigurationSync.queueNewJobIfNeeded();
await UserSync.queueNewJobIfNeeded();
}
}
@ -291,7 +291,7 @@ class ConvoController {
}
if (!options.fromSyncMessage) {
await ConfigurationSync.queueNewJobIfNeeded();
await UserSync.queueNewJobIfNeeded();
}
}

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

@ -1,17 +1,17 @@
import { cloneDeep, compact, isArray, isString } from 'lodash';
import { Data } from '../../../data/data';
import { Storage } from '../../../util/storage';
import { timeout } from '../Promise';
import { persistedJobFromData } from './JobDeserialization';
import { JobRunnerType } from './jobs/JobRunnerType';
import {
AvatarDownloadPersistedData,
ConfigurationSyncPersistedData,
GroupSyncPersistedData,
PersistedJob,
RunJobResult,
TypeOfPersistedData,
UserSyncPersistedData,
} from './PersistedJob';
import { Storage } from '../../../util/storage';
import { JobRunnerType } from './jobs/JobRunnerType';
/**
* '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>(
'ConfigurationSyncJob',
null
);
const userSyncRunner = new PersistedJobRunner<UserSyncPersistedData>('UserSyncJob', null);
const groupSyncRunner = new PersistedJobRunner<GroupSyncPersistedData>('GroupSyncJob', null);
const avatarDownloadRunner = new PersistedJobRunner<AvatarDownloadPersistedData>(
@ -363,7 +360,7 @@ const avatarDownloadRunner = new PersistedJobRunner<AvatarDownloadPersistedData>
);
export const runners = {
configurationSyncRunner,
userSyncRunner,
groupSyncRunner,
avatarDownloadRunner,
};

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

@ -162,7 +162,7 @@ class GroupSyncJob extends PersistedJob<GroupSyncPersistedData> {
} catch (e) {
throw e;
} 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.
// (a finally statement is always executed (no matter if exception or returns in other try/catch block)

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

@ -4,7 +4,7 @@ import { isArray, isEmpty, isNumber } from 'lodash';
import { v4 } from 'uuid';
import { UserUtils } from '../..';
import { ConfigDumpData } from '../../../../data/configDump/configDump';
import { ConfigurationSyncJobDone } from '../../../../shims/events';
import { UserSyncJobDone } from '../../../../shims/events';
import { isSignInByLinking } from '../../../../util/storage';
import { GenericWrapperActions } from '../../../../webworker/workers/browser/libsession_worker_interface';
import { StoreOnNodeData } from '../../../apis/snode_api/SnodeRequestTypes';
@ -17,7 +17,7 @@ import { LibSessionUtil, UserSuccessfulChange } from '../../libsession/libsessio
import { runners } from '../JobRunner';
import {
AddJobCheckReturn,
ConfigurationSyncPersistedData,
UserSyncPersistedData,
PersistedJob,
RunJobResult,
} from '../PersistedJob';
@ -58,7 +58,7 @@ async function confirmPushedAndDump(
}
function triggerConfSyncJobDone() {
window.Whisper.events.trigger(ConfigurationSyncJobDone);
window.Whisper.events.trigger(UserSyncJobDone);
}
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
if (!isArray(result) || result.length !== expectedReplyLength) {
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
return RunJobResult.RetryJobIfPossible;
@ -116,7 +116,7 @@ async function pushChangesToUserSwarmIfNeeded() {
return RunJobResult.Success;
}
class ConfigurationSyncJob extends PersistedJob<ConfigurationSyncPersistedData> {
class UserSyncJob extends PersistedJob<UserSyncPersistedData> {
constructor({
identifier,
nextAttemptTimestamp,
@ -124,12 +124,12 @@ class ConfigurationSyncJob extends PersistedJob<ConfigurationSyncPersistedData>
currentRetry,
}: Partial<
Pick<
ConfigurationSyncPersistedData,
UserSyncPersistedData,
'identifier' | 'nextAttemptTimestamp' | 'currentRetry' | 'maxAttempts'
>
>) {
super({
jobType: 'ConfigurationSyncJobType',
jobType: 'UserSyncJobType',
identifier: identifier || v4(),
delayBetweenRetries: defaultMsBetweenRetries,
maxAttempts: isNumber(maxAttempts) ? maxAttempts : defaultMaxAttempts,
@ -142,7 +142,7 @@ class ConfigurationSyncJob extends PersistedJob<ConfigurationSyncPersistedData>
const start = Date.now();
try {
window.log.debug(`ConfigurationSyncJob starting ${this.persistedData.identifier}`);
window.log.debug(`UserSyncJob starting ${this.persistedData.identifier}`);
const us = UserUtils.getOurPubKeyStrFromCache();
const ed25519Key = await UserUtils.getUserED25519KeyPairBytes();
@ -158,7 +158,7 @@ class ConfigurationSyncJob extends PersistedJob<ConfigurationSyncPersistedData>
} catch (e) {
throw e;
} 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.
// (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();
return fromParent;
}
public addJobCheck(jobs: Array<ConfigurationSyncPersistedData>): AddJobCheckReturn {
public addJobCheck(jobs: Array<UserSyncPersistedData>): AddJobCheckReturn {
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.
* This is done by the `addJobCheck` method above
*/
public nonRunningJobsToRemove(_jobs: Array<ConfigurationSyncPersistedData>) {
public nonRunningJobsToRemove(_jobs: Array<UserSyncPersistedData>) {
return [];
}
@ -195,7 +195,7 @@ class ConfigurationSyncJob extends PersistedJob<ConfigurationSyncPersistedData>
/**
* 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() {
if (isSignInByLinking()) {
@ -210,8 +210,8 @@ async function queueNewJobIfNeeded() {
// 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
// this call will make sure that there is only one configuration sync job at all times
await runners.configurationSyncRunner.addJob(
new ConfigurationSyncJob({ nextAttemptTimestamp: Date.now() + 1000 })
await runners.userSyncRunner.addJob(
new UserSyncJob({ nextAttemptTimestamp: Date.now() + 1000 })
);
} else {
// 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);
// window.log.debug('Scheduling ConfSyncJob: LATER');
await runners.configurationSyncRunner.addJob(
new ConfigurationSyncJob({ nextAttemptTimestamp: Date.now() + leftBeforeNextTick })
await runners.userSyncRunner.addJob(
new UserSyncJob({ nextAttemptTimestamp: Date.now() + leftBeforeNextTick })
);
}
}
export const ConfigurationSync = {
ConfigurationSyncJob,
queueNewJobIfNeeded: () =>
allowOnlyOneAtATime('ConfigurationSyncJob-oneAtAtTime', queueNewJobIfNeeded),
export const UserSync = {
UserSyncJob,
queueNewJobIfNeeded: () => allowOnlyOneAtATime('UserSyncJob-oneAtAtTime', queueNewJobIfNeeded),
};

@ -19,7 +19,7 @@ import {
import { SnodeNamespaces, UserConfigNamespaces } from '../../apis/snode_api/namespaces';
import { ed25519Str } from '../../onions/onionPath';
import { PubKey } from '../../types';
import { ConfigurationSync } from '../job_runners/jobs/ConfigurationSyncJob';
import { UserSync } from '../job_runners/jobs/UserSyncJob';
import {
BatchResultEntry,
NotEmptyArrayOfBatchResults,
@ -39,7 +39,7 @@ async function initializeLibSessionUtilWrappers() {
}
const privateKeyEd25519 = keypair.privKeyBytes;
// 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
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.
* 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>();

@ -7,7 +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 { UserSyncJobDone } from '../../../shims/events';
import { ReleasedFeatures } from '../../../util/releaseFeature';
import { Storage } from '../../../util/storage';
import { getCompleteUrlFromRoom } from '../../apis/open_group_api/utils/OpenGroupUtils';
@ -30,7 +30,7 @@ import {
} from '../../messages/outgoing/visibleMessage/VisibleMessage';
import { PubKey } from '../../types';
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';
@ -44,7 +44,7 @@ const writeLastSyncTimestampToDb = async (timestamp: number) =>
* Conditionally Syncs user configuration with other devices linked.
*/
export const syncConfigurationIfNeeded = async () => {
await ConfigurationSync.queueNewJobIfNeeded();
await UserSync.queueNewJobIfNeeded();
const userConfigLibsession = await ReleasedFeatures.checkIsUserConfigFeatureReleased();
if (!userConfigLibsession) {
@ -84,16 +84,16 @@ export const forceSyncConfigurationNowIfNeeded = async (waitForMessageSent = fal
resolve(false);
}, 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.
void ConfigurationSync.queueNewJobIfNeeded().catch(e => {
// 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 UserSync.queueNewJobIfNeeded().catch(e => {
window.log.warn(
'forceSyncConfigurationNowIfNeeded scheduling of jobs ConfigurationSync.queueNewJobIfNeeded failed with: ',
'forceSyncConfigurationNowIfNeeded scheduling of jobs UserSync.queueNewJobIfNeeded failed with: ',
e.message
);
});
if (ReleasedFeatures.isUserConfigFeatureReleasedCached()) {
if (waitForMessageSent) {
window.Whisper.events.once(ConfigurationSyncJobDone, () => {
window.Whisper.events.once(UserSyncJobDone, () => {
resolve(true);
});
return;

@ -3,4 +3,4 @@ export function trigger(name: string, param1?: any, param2?: any) {
}
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 { UserUtils } from '../../../../session/utils';
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 { generateFakeSnodes, stubData } from '../../../test-utils/utils';
@ -52,7 +52,7 @@ describe('SwarmPolling:pollForAllKeys', () => {
ConvoHub.use().reset();
TestUtils.stubWindowFeatureFlags();
TestUtils.stubWindowLog();
Sinon.stub(ConfigurationSync, 'queueNewJobIfNeeded').resolves();
Sinon.stub(UserSync, 'queueNewJobIfNeeded').resolves();
// Utils Stubs
Sinon.stub(UserUtils, 'getOurPubKeyStrFromCache').returns(ourNumber);

@ -1,5 +1,5 @@
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 { Storage } from './storage';
@ -87,7 +87,7 @@ async function checkIsFeatureReleased(featureName: FeatureNameTracked): Promise<
await Storage.put(featureStorageItemId(featureName), true);
setIsFeatureReleasedCached(featureName, true);
// trigger a sync right away so our user data is online
await ConfigurationSync.queueNewJobIfNeeded();
await UserSync.queueNewJobIfNeeded();
}
const isReleased = Boolean(getIsFeatureReleasedCached(featureName));

Loading…
Cancel
Save