Do not sync configurationMessage on app load if restored from seed

pull/1528/head
Audric Ackermann 4 years ago
parent 9586c3a06a
commit 853222d25b

@ -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<Props> {
// 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();

@ -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',

@ -63,6 +63,9 @@ export type ServerToken = {
token: string;
};
export const hasSyncedInitialConfigurationItem =
'hasSyncedInitialConfigurationItem';
const channelsToMake = {
shutdown,
close,

@ -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... '

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

Loading…
Cancel
Save