diff --git a/preload.js b/preload.js index 9ede62bd2..8958a37ba 100644 --- a/preload.js +++ b/preload.js @@ -237,7 +237,6 @@ const { setupi18n } = require('./ts/util/i18n'); window.Signal = data.initData(); const { getConversationController } = require('./ts/session/conversations/ConversationController'); -const { isEmpty } = require('lodash'); window.getConversationController = getConversationController; // Linux seems to periodically let the event loop stop, so this is a global workaround setInterval(() => { diff --git a/ts/receiver/configMessage.ts b/ts/receiver/configMessage.ts index a20592d51..d69c4e212 100644 --- a/ts/receiver/configMessage.ts +++ b/ts/receiver/configMessage.ts @@ -24,6 +24,7 @@ import { toHex } from '../session/utils/String'; import { configurationMessageReceived, trigger } from '../shims/events'; import { assertUnreachable } from '../types/sqlSharedTypes'; import { BlockedNumberController } from '../util'; +import { Registration } from '../util/registration'; import { getLastProfileUpdateTimestamp, setLastProfileUpdateTimestamp } from '../util/storage'; import { ConfigWrapperObjectTypes } from '../webworker/workers/browser/libsession_worker_functions'; import { @@ -654,8 +655,8 @@ async function handleOurProfileUpdateLegacy( sentAt: number | Long, configMessage: SignalService.ConfigurationMessage ) { - // this call won't be needed with the new sharedUtilLibrary - if (window.sessionFeatureFlags.useSharedUtilForUserConfig) { + // we want to allow if we are not registered, as we might need to fetch an old config message (can be removed once we released for a weeks the libsession util) + if (window.sessionFeatureFlags.useSharedUtilForUserConfig && Registration.isDone()) { return; } const latestProfileUpdateTimestamp = getLastProfileUpdateTimestamp(); @@ -678,7 +679,7 @@ async function handleGroupsAndContactsFromConfigMessageLegacy( envelope: EnvelopePlus, configMessage: SignalService.ConfigurationMessage ) { - if (window.sessionFeatureFlags.useSharedUtilForUserConfig) { + if (window.sessionFeatureFlags.useSharedUtilForUserConfig && Registration.isDone()) { return; } const envelopeTimestamp = toNumber(envelope.timestamp); @@ -718,7 +719,7 @@ async function handleGroupsAndContactsFromConfigMessageLegacy( * @param openGroups string array of open group urls */ const handleOpenGroupsFromConfig = (openGroups: Array) => { - if (window.sessionFeatureFlags.useSharedUtilForUserConfig) { + if (window.sessionFeatureFlags.useSharedUtilForUserConfig && Registration.isDone()) { return; } const numberOpenGroup = openGroups?.length || 0; @@ -746,7 +747,7 @@ const handleClosedGroupsFromConfigLegacy = async ( closedGroups: Array, envelope: EnvelopePlus ) => { - if (window.sessionFeatureFlags.useSharedUtilForUserConfig) { + if (window.sessionFeatureFlags.useSharedUtilForUserConfig && Registration.isDone()) { return; } const numberClosedGroup = closedGroups?.length || 0; @@ -781,7 +782,7 @@ const handleContactFromConfigLegacy = async ( contactReceived: SignalService.ConfigurationMessage.IContact, envelope: EnvelopePlus ) => { - if (window.sessionFeatureFlags.useSharedUtilForUserConfig) { + if (window.sessionFeatureFlags.useSharedUtilForUserConfig && Registration.isDone()) { return; } try { @@ -845,7 +846,11 @@ async function handleConfigurationMessageLegacy( envelope: EnvelopePlus, configurationMessage: SignalService.ConfigurationMessage ): Promise { - if (window.sessionFeatureFlags.useSharedUtilForUserConfig) { + // when the useSharedUtilForUserConfig flag is ON, we want only allow a legacy config message if we are registering a new user. + // this is to allow users linking a device to find their config message if they do not have a shared config message yet. + // the process of those messages is always done after the process of the shared config messages, so that's only a fallback. + + if (window.sessionFeatureFlags.useSharedUtilForUserConfig && Registration.isDone()) { window?.log?.info( 'useSharedUtilForUserConfig is set, not handling config messages with "handleConfigurationMessageLegacy()"' ); diff --git a/ts/util/accountManager.ts b/ts/util/accountManager.ts index 63f4b3c4f..8ed77e10d 100644 --- a/ts/util/accountManager.ts +++ b/ts/util/accountManager.ts @@ -181,6 +181,8 @@ async function registrationDone(ourPubkey: string, displayName: string) { // initializeLibSessionUtilWrappers needs our publicKey to be set await Storage.put('primaryDevicePubKey', ourPubkey); + await Registration.markDone(); + try { await LibSessionUtil.initializeLibSessionUtilWrappers(); } catch (e) { @@ -203,8 +205,6 @@ async function registrationDone(ourPubkey: string, displayName: string) { }; window.inboxStore?.dispatch(userActions.userChanged(user)); - await Registration.markDone(); - window?.log?.info('dispatching registration event'); trigger('registration_done'); }