fix a bug preventing our avatar to be updated on restore from seed

this was due to the fact that the redux was not ready when our
conversation is created. so the events were not linked
pull/1528/head
Audric Ackermann 4 years ago
parent 05e9c936ff
commit db167eaf1b

@ -50,7 +50,6 @@ class ActionsPanelPrivate extends React.Component<Props> {
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);
this.editProfileHandle = this.editProfileHandle.bind(this);
// we consider people had the time to upgrade, so remove this id from the db // 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 // it was used to display a dialog when we added the light mode auto-enabled
void removeItemById('hasSeenLightModeDialog'); void removeItemById('hasSeenLightModeDialog');
@ -66,6 +65,14 @@ class ActionsPanelPrivate extends React.Component<Props> {
// Initialize paths for onion requests // Initialize paths for onion requests
void OnionPaths.getInstance().buildNewOnionPaths(); 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 // 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 // this call does nothing except calling the constructor, which will continue sending message in the pipeline
void getMessageQueue().processAllPending(); void getMessageQueue().processAllPending();
@ -125,7 +132,7 @@ class ActionsPanelPrivate extends React.Component<Props> {
? () => { ? () => {
/* tslint:disable:no-void-expression */ /* tslint:disable:no-void-expression */
if (type === SectionType.Profile) { if (type === SectionType.Profile) {
this.editProfileHandle(); window.showEditProfileDialog();
} else if (type === SectionType.Moon) { } else if (type === SectionType.Moon) {
const theme = window.Events.getThemeSetting(); const theme = window.Events.getThemeSetting();
const updatedTheme = theme === 'dark' ? 'light' : 'dark'; const updatedTheme = theme === 'dark' ? 'light' : 'dark';
@ -191,10 +198,6 @@ class ActionsPanelPrivate extends React.Component<Props> {
); );
}; };
public editProfileHandle() {
window.showEditProfileDialog();
}
public render(): JSX.Element { public render(): JSX.Element {
const { const {
selectedSection, selectedSection,

@ -10,9 +10,10 @@ import {
ConversationModel, ConversationModel,
} from '../../models/conversation'; } from '../../models/conversation';
import { BlockedNumberController } from '../../util'; import { BlockedNumberController } from '../../util';
import { getSnodesFor } from '../snode_api/snodePool';
import { PubKey } from '../types'; 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 { export class ConversationController {
private static instance: ConversationController | null; private static instance: ConversationController | null;
private readonly conversations: any; private readonly conversations: any;
@ -137,7 +138,7 @@ export class ConversationController {
await Promise.all([ await Promise.all([
conversation.updateProfileAvatar(), conversation.updateProfileAvatar(),
// NOTE: we request snodes updating the cache, but ignore the result // 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([]); 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) { private updateReduxConvoChanged(convo: ConversationModel) {
if (window.inboxStore) { if (window.inboxStore) {
window.inboxStore.dispatch( window.inboxStore.dispatch(

@ -21,9 +21,11 @@ const mapStateToProps = (state: StateType) => {
const leftPaneList = getLeftPaneLists(state); const leftPaneList = getLeftPaneLists(state);
const lists = showSearch ? undefined : leftPaneList; const lists = showSearch ? undefined : leftPaneList;
const searchResults = showSearch ? getSearchResults(state) : undefined; const searchResults = showSearch ? getSearchResults(state) : undefined;
const ourPrimaryConversation = getOurPrimaryConversation(state);
return { return {
...lists, ...lists,
ourPrimaryConversation: getOurPrimaryConversation(state), // used in actionPanel ourPrimaryConversation, // used in actionPanel
searchTerm: getQuery(state), searchTerm: getQuery(state),
ourNumber: getOurNumber(state), ourNumber: getOurNumber(state),
searchResults, searchResults,

@ -56,8 +56,6 @@ const generateKeypair = async (mnemonic: string, mnemonicLanguage: string) => {
seedHex = seedHex.substring(0, privKeyHexLength); seedHex = seedHex.substring(0, privKeyHexLength);
} }
const seed = fromHex(seedHex); const seed = fromHex(seedHex);
console.warn('generateKeypair seedHex', seedHex);
console.warn('generateKeypair seed', seed);
return sessionGenerateKeyPair(seed); return sessionGenerateKeyPair(seed);
}; };
@ -204,14 +202,17 @@ export class AccountManager {
await window.textsecure.storage.user.setNumberAndDeviceId(pubKeyString, 1); 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.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 // Ensure that we always have a conversation for ourself
const conversation = await ConversationController.getInstance().getOrCreateAndWait( const conversation = await ConversationController.getInstance().getOrCreateAndWait(
number, ourPubkey,
'private' 'private'
); );
await conversation.setLokiProfile({ displayName }); await conversation.setLokiProfile({ displayName });

Loading…
Cancel
Save