diff --git a/ts/components/session/ActionsPanel.tsx b/ts/components/session/ActionsPanel.tsx index 5d8f0eefb..ba54fe1c1 100644 --- a/ts/components/session/ActionsPanel.tsx +++ b/ts/components/session/ActionsPanel.tsx @@ -50,7 +50,6 @@ class ActionsPanelPrivate extends React.Component { constructor(props: Props) { super(props); - this.editProfileHandle = this.editProfileHandle.bind(this); // we consider people had the time to upgrade, so remove this id from the db // it was used to display a dialog when we added the light mode auto-enabled void removeItemById('hasSeenLightModeDialog'); @@ -66,6 +65,14 @@ class ActionsPanelPrivate extends React.Component { // Initialize paths for onion requests void OnionPaths.getInstance().buildNewOnionPaths(); } + + // This is not ideal, but on the restore from seed, our conversation will be created before the + // redux store is ready. + // If that's the case, the save events on our conversation won't be triggering redux updates. + // So changes to our conversation won't make a change on the UI. + // Calling this makes sure that our own conversation is registered to redux. + ConversationController.getInstance().registerOurPrimaryConvoOnRedux(); + // init the messageQueue. In the constructor, we had all not send messages // this call does nothing except calling the constructor, which will continue sending message in the pipeline void getMessageQueue().processAllPending(); @@ -125,7 +132,7 @@ class ActionsPanelPrivate extends React.Component { ? () => { /* tslint:disable:no-void-expression */ if (type === SectionType.Profile) { - this.editProfileHandle(); + window.showEditProfileDialog(); } else if (type === SectionType.Moon) { const theme = window.Events.getThemeSetting(); const updatedTheme = theme === 'dark' ? 'light' : 'dark'; @@ -191,10 +198,6 @@ class ActionsPanelPrivate extends React.Component { ); }; - public editProfileHandle() { - window.showEditProfileDialog(); - } - public render(): JSX.Element { const { selectedSection, diff --git a/ts/session/conversations/index.ts b/ts/session/conversations/index.ts index d0ab1897f..bd924d947 100644 --- a/ts/session/conversations/index.ts +++ b/ts/session/conversations/index.ts @@ -10,9 +10,10 @@ import { ConversationModel, } from '../../models/conversation'; import { BlockedNumberController } from '../../util'; +import { getSnodesFor } from '../snode_api/snodePool'; import { PubKey } from '../types'; +import { UserUtils } from '../utils'; -// It's not only data from the db which is stored on the MessageController entries, we could fetch this again. What we cannot fetch from the db and which is stored here is all listeners a particular messages is linked to for instance. We will be able to get rid of this once we don't use backbone models at all export class ConversationController { private static instance: ConversationController | null; private readonly conversations: any; @@ -137,7 +138,7 @@ export class ConversationController { await Promise.all([ conversation.updateProfileAvatar(), // NOTE: we request snodes updating the cache, but ignore the result - window.SnodePool.getSnodesFor(id), + void getSnodesFor(id), ]); } }); @@ -315,6 +316,22 @@ export class ConversationController { this.conversations.reset([]); } + public registerOurPrimaryConvoOnRedux() { + if (window.inboxStore) { + const ourPubkey = UserUtils.getOurPubKeyStrFromCache(); + const ourConversation = this.conversations.get(ourPubkey); + if (!ourConversation) { + window.log.warn( + 'Cannot register ourPrimary convo to redux, our convo does not exist' + ); + return; + } + // make sure our conversation is registered to forward it's commit events to redux + ourConversation.off('change', this.updateReduxConvoChanged); + ourConversation.on('change', this.updateReduxConvoChanged); + } + } + private updateReduxConvoChanged(convo: ConversationModel) { if (window.inboxStore) { window.inboxStore.dispatch( diff --git a/ts/state/smart/LeftPane.tsx b/ts/state/smart/LeftPane.tsx index 47562b82a..0768233a3 100644 --- a/ts/state/smart/LeftPane.tsx +++ b/ts/state/smart/LeftPane.tsx @@ -21,9 +21,11 @@ const mapStateToProps = (state: StateType) => { const leftPaneList = getLeftPaneLists(state); const lists = showSearch ? undefined : leftPaneList; const searchResults = showSearch ? getSearchResults(state) : undefined; + const ourPrimaryConversation = getOurPrimaryConversation(state); + return { ...lists, - ourPrimaryConversation: getOurPrimaryConversation(state), // used in actionPanel + ourPrimaryConversation, // used in actionPanel searchTerm: getQuery(state), ourNumber: getOurNumber(state), searchResults, diff --git a/ts/util/accountManager.ts b/ts/util/accountManager.ts index c079ed681..5be45714c 100644 --- a/ts/util/accountManager.ts +++ b/ts/util/accountManager.ts @@ -56,8 +56,6 @@ const generateKeypair = async (mnemonic: string, mnemonicLanguage: string) => { seedHex = seedHex.substring(0, privKeyHexLength); } const seed = fromHex(seedHex); - console.warn('generateKeypair seedHex', seedHex); - console.warn('generateKeypair seed', seed); return sessionGenerateKeyPair(seed); }; @@ -204,14 +202,17 @@ export class AccountManager { await window.textsecure.storage.user.setNumberAndDeviceId(pubKeyString, 1); } - private static async registrationDone(number: string, displayName: string) { + private static async registrationDone( + ourPubkey: string, + displayName: string + ) { window.log.info('registration done'); - window.textsecure.storage.put('primaryDevicePubKey', number); + window.textsecure.storage.put('primaryDevicePubKey', ourPubkey); // Ensure that we always have a conversation for ourself const conversation = await ConversationController.getInstance().getOrCreateAndWait( - number, + ourPubkey, 'private' ); await conversation.setLokiProfile({ displayName });