diff --git a/libtextsecure/storage/user.js b/libtextsecure/storage/user.js index 64e0cac7d..091f1a805 100644 --- a/libtextsecure/storage/user.js +++ b/libtextsecure/storage/user.js @@ -24,6 +24,18 @@ return textsecure.utils.unencodeNumber(numberId)[0]; }, + isRestoringFromSeed() { + const isRestoring = textsecure.storage.get('is_restoring_from_seed'); + if (isRestoring === undefined) { + return false; + } + return isRestoring; + }, + + setRestoringFromSeed(isRestoringFromSeed) { + textsecure.storage.put('is_restoring_from_seed', isRestoringFromSeed); + }, + getDeviceId() { const numberId = textsecure.storage.get('number_id'); if (numberId === undefined) { diff --git a/preload.js b/preload.js index 6718aff28..88671d9db 100644 --- a/preload.js +++ b/preload.js @@ -517,9 +517,12 @@ window.deleteAccount = async reason => { try { window.log.info('DeleteAccount => Sending a last SyncConfiguration'); // be sure to wait for the message being effectively sent. Otherwise we won't be able to encrypt it for our devices ! + window.log.info('Sending one last configuration message.') await window.libsession.Utils.SyncUtils.forceSyncConfigurationNowIfNeeded( true ); + window.log.info('Last configuration message sent!') + await syncedMessageSent(); } catch (error) { window.log.error( diff --git a/ts/components/session/RegistrationTabs.tsx b/ts/components/session/RegistrationTabs.tsx index cf739629e..6b7a128e0 100644 --- a/ts/components/session/RegistrationTabs.tsx +++ b/ts/components/session/RegistrationTabs.tsx @@ -10,7 +10,7 @@ import { import { trigger } from '../../shims/events'; import { SessionHtmlRenderer } from './SessionHTMLRenderer'; import { SessionIdEditable } from './SessionIdEditable'; -import { StringUtils, ToastUtils } from '../../session/utils'; +import { StringUtils, ToastUtils, UserUtils } from '../../session/utils'; import { lightTheme } from '../../state/ducks/SessionTheme'; import { ConversationController } from '../../session/conversations'; import { PasswordUtil } from '../../util'; @@ -702,12 +702,24 @@ export class RegistrationTabs extends React.Component { await this.resetRegistration(); await window.setPassword(password); + const isRestoringFromSeed = signInMode === SignInMode.UsingRecoveryPhrase; + UserUtils.setRestoringFromSeed(isRestoringFromSeed); + await this.accountManager.registerSingleDevice( seedToUse, language, trimName ); - trigger('openInbox'); + // if we are just creating a new account, no need to wait for a configuration message + if (!isRestoringFromSeed) { + trigger('openInbox'); + } else { + // We have to pull for all messages of the user of this menmonic + // We are looking for the most recent ConfigurationMessage he sent to himself. + // When we find it, we can just get the displayName, avatar and groups saved in it. + // If we do not find one, we will need to ask for a display name. + window.log.warn('isRestoringFromSeed'); + } } catch (e) { ToastUtils.pushToastError( 'registrationError', diff --git a/ts/receiver/contentMessage.ts b/ts/receiver/contentMessage.ts index 8e621dd57..6a2d2377c 100644 --- a/ts/receiver/contentMessage.ts +++ b/ts/receiver/contentMessage.ts @@ -390,7 +390,7 @@ export async function innerHandleContentMessage( 'private' ); - if (content.dataMessage) { + if (content.dataMessage && !UserUtils.isRestoringFromSeed()) { if ( content.dataMessage.profileKey && content.dataMessage.profileKey.length === 0 @@ -401,15 +401,16 @@ export async function innerHandleContentMessage( return; } - if (content.receiptMessage) { + if (content.receiptMessage && !UserUtils.isRestoringFromSeed()) { await handleReceiptMessage(envelope, content.receiptMessage); return; } - if (content.typingMessage) { + if (content.typingMessage && !UserUtils.isRestoringFromSeed()) { await handleTypingMessage(envelope, content.typingMessage); return; } + // Be sure to check for the UserUtils.isRestoringFromSeed() if you add another if here if (content.configurationMessage) { await handleConfigurationMessage( envelope, @@ -417,6 +418,7 @@ export async function innerHandleContentMessage( ); return; } + // Be sure to check for the UserUtils.isRestoringFromSeed() if you add another if here } catch (e) { window.log.warn(e); } diff --git a/ts/session/utils/User.ts b/ts/session/utils/User.ts index d71a51d31..cf418e146 100644 --- a/ts/session/utils/User.ts +++ b/ts/session/utils/User.ts @@ -69,3 +69,18 @@ export async function getUserED25519KeyPair(): Promise { } return undefined; } + +/** + * Returns the public key of this current device as a STRING, or throws an error + */ +export function isRestoringFromSeed(): boolean { + const ourNumber = window.textsecure.storage.user.isRestoringFromSeed(); + if (!ourNumber) { + throw new Error('ourNumber is not set'); + } + return ourNumber; +} + +export function setRestoringFromSeed(isRestoring: boolean) { + window.textsecure.storage.user.setRestoringFromSeed(isRestoring); +} diff --git a/ts/session/utils/syncUtils.ts b/ts/session/utils/syncUtils.ts index e9ab76191..7d3cb17f7 100644 --- a/ts/session/utils/syncUtils.ts +++ b/ts/session/utils/syncUtils.ts @@ -49,6 +49,8 @@ export const forceSyncConfigurationNowIfNeeded = async ( async function waitForMessageSentEvent(message: RawMessage) { return new Promise(resolve => { if (message.identifier === configMessage.identifier) { + // might have fail in fact + debugger; resolve(true); } }); @@ -61,10 +63,9 @@ export const forceSyncConfigurationNowIfNeeded = async ( configMessage, waitForMessageSentEvent as any ); - return Promise.resolve(); + return waitForMessageSentEvent; } else { await getMessageQueue().sendSyncMessage(configMessage); - return waitForMessageSentEvent; } } catch (e) { window.log.warn(