diff --git a/ts/components/session/ActionsPanel.tsx b/ts/components/session/ActionsPanel.tsx index c45cb1d6b..5d8f0eefb 100644 --- a/ts/components/session/ActionsPanel.tsx +++ b/ts/components/session/ActionsPanel.tsx @@ -15,7 +15,11 @@ import { getOurNumber } from '../../state/selectors/user'; import { UserUtils } from '../../session/utils'; import { syncConfigurationIfNeeded } from '../../session/utils/syncUtils'; import { DAYS } from '../../session/utils/Number'; -import { removeItemById } from '../../data/data'; +import { + getItemById, + hasSyncedInitialConfigurationItem, + removeItemById, +} from '../../data/data'; import { OnionPaths } from '../../session/onions'; import { getMessageQueue } from '../../session/sending'; import { AccountManager } from '../../util'; @@ -77,8 +81,19 @@ class ActionsPanelPrivate extends React.Component { // remove existing prekeys, sign prekeys and sessions void AccountManager.clearSessionsAndPreKeys(); + // Do this only if we created a new Session ID, or if we already received the initial configuration message + + const syncConfiguration = async () => { + const didWeHandleAConfigurationMessageAlready = + (await getItemById(hasSyncedInitialConfigurationItem))?.value || false; + if (didWeHandleAConfigurationMessageAlready) { + await syncConfigurationIfNeeded(); + } + }; + // trigger a sync message if needed for our other devices - void syncConfigurationIfNeeded(); + + void syncConfiguration(); this.syncInterval = global.setInterval(() => { void syncConfigurationIfNeeded(); diff --git a/ts/components/session/registration/RegistrationTabs.tsx b/ts/components/session/registration/RegistrationTabs.tsx index 46818ebc5..935fcee15 100644 --- a/ts/components/session/registration/RegistrationTabs.tsx +++ b/ts/components/session/registration/RegistrationTabs.tsx @@ -7,7 +7,7 @@ import { UserUtils, } from '../../../session/utils'; import { ConversationController } from '../../../session/conversations'; -import { removeAll } from '../../../data/data'; +import { createOrUpdateItem, removeAll } from '../../../data/data'; import { SignUpTab } from './SignUpTab'; import { SignInTab } from './SignInTab'; import { TabLabel, TabType } from './TabLabel'; @@ -142,7 +142,6 @@ export async function signUp(signUpDetails: { 'english', trimName ); - await UserUtils.setLastProfileUpdateTimestamp(Date.now()); trigger('openInbox'); } catch (e) { await resetRegistration(); @@ -186,8 +185,10 @@ export async function signInWithRecovery(signInDetails: { try { await resetRegistration(); await window.setPassword(password); - await UserUtils.setLastProfileUpdateTimestamp(Date.now()); - + await createOrUpdateItem({ + id: 'hasSyncedInitialConfigurationItem', + value: true, + }); await AccountManager.registerSingleDevice( userRecoveryPhrase, 'english', diff --git a/ts/data/data.ts b/ts/data/data.ts index 8785c7412..0234c68a5 100644 --- a/ts/data/data.ts +++ b/ts/data/data.ts @@ -63,6 +63,9 @@ export type ServerToken = { token: string; }; +export const hasSyncedInitialConfigurationItem = + 'hasSyncedInitialConfigurationItem'; + const channelsToMake = { shutdown, close, diff --git a/ts/receiver/contentMessage.ts b/ts/receiver/contentMessage.ts index bc645f25e..fda3a3afa 100644 --- a/ts/receiver/contentMessage.ts +++ b/ts/receiver/contentMessage.ts @@ -12,17 +12,15 @@ import { fromHexToArray, toHex } from '../session/utils/String'; import { concatUInt8Array, getSodium } from '../session/crypto'; import { ConversationController } from '../session/conversations'; import { - createOrUpdateItem, getAllEncryptionKeyPairsForGroup, getItemById, + hasSyncedInitialConfigurationItem, } from '../../ts/data/data'; import { ECKeyPair } from './keypairs'; import { handleNewClosedGroup } from './closedGroups'; import { KeyPairRequestManager } from './keyPairRequestManager'; import { requestEncryptionKeyPair } from '../session/group'; -import { ConfigurationMessage } from '../session/messages/outgoing/content/ConfigurationMessage'; import { configurationMessageReceived, trigger } from '../shims/events'; -import _ from 'lodash'; export async function handleContentMessage(envelope: EnvelopePlus) { try { @@ -561,7 +559,7 @@ async function handleOurProfileUpdate( profilePicture, }; await updateProfile(ourConversation, lokiProfile, profileKey); - UserUtils.setLastProfileUpdateTimestamp(_.toNumber(sentAt)); + UserUtils.setLastProfileUpdateTimestamp(Lodash.toNumber(sentAt)); trigger(configurationMessageReceived, displayName); } } @@ -570,11 +568,8 @@ async function handleGroupsAndContactsFromConfigMessage( envelope: EnvelopePlus, configMessage: SignalService.ConfigurationMessage ) { - const ITEM_ID_PROCESSED_CONFIGURATION_MESSAGE = - 'ITEM_ID_PROCESSED_CONFIGURATION_MESSAGE'; const didWeHandleAConfigurationMessageAlready = - (await getItemById(ITEM_ID_PROCESSED_CONFIGURATION_MESSAGE))?.value || - false; + (await getItemById(hasSyncedInitialConfigurationItem))?.value || false; if (didWeHandleAConfigurationMessageAlready) { window?.log?.warn( 'Dropping configuration change as we already handled one... ' diff --git a/ts/util/accountManager.ts b/ts/util/accountManager.ts index 781e45cc5..c079ed681 100644 --- a/ts/util/accountManager.ts +++ b/ts/util/accountManager.ts @@ -9,6 +9,7 @@ import { import { getOurPubKeyStrFromCache } from '../session/utils/User'; import { trigger } from '../shims/events'; import { + createOrUpdateItem, removeAllContactPreKeys, removeAllContactSignedPreKeys, removeAllPreKeys, @@ -136,9 +137,12 @@ export class AccountManager { generatedMnemonic, mnemonicLanguage ); + await AccountManager.createAccount(identityKeyPair); UserUtils.saveRecoveryPhrase(generatedMnemonic); await AccountManager.clearSessionsAndPreKeys(); + await UserUtils.setLastProfileUpdateTimestamp(Date.now()); + const pubKeyString = toHex(identityKeyPair.pubKey); await AccountManager.registrationDone(pubKeyString, profileName); }