diff --git a/ts/background.ts b/ts/background.ts index 13e065f73..25f5b43be 100644 --- a/ts/background.ts +++ b/ts/background.ts @@ -515,7 +515,7 @@ export async function startApp(): Promise { accountManager = new window.textsecure.AccountManager(server); accountManager.addEventListener('registration', () => { - window.Whisper.events.trigger('userChanged'); + window.Whisper.events.trigger('userChanged', false); window.Signal.Util.Registration.markDone(); window.log.info('dispatching registration event'); @@ -1057,7 +1057,7 @@ export async function startApp(): Promise { }); convoCollection.on('reset', removeAllConversations); - window.Whisper.events.on('userChanged', () => { + window.Whisper.events.on('userChanged', (reconnect = false) => { const newDeviceId = window.textsecure.storage.user.getDeviceId(); const newNumber = window.textsecure.storage.user.getNumber(); const newUuid = window.textsecure.storage.user.getUuid(); @@ -1074,6 +1074,11 @@ export async function startApp(): Promise { ourUuid: newUuid, regionCode: window.storage.get('regionCode'), }); + + if (reconnect) { + window.log.info('background: reconnecting websocket on user change'); + enqueueReconnectToWebSocket(); + } }); let shortcutGuideView: WhatIsThis | null = null; diff --git a/ts/textsecure/storage/User.ts b/ts/textsecure/storage/User.ts index b04f4f03f..ca99eae2a 100644 --- a/ts/textsecure/storage/User.ts +++ b/ts/textsecure/storage/User.ts @@ -47,7 +47,7 @@ export class User { ]); // Notify redux about phone number change - window.Whisper.events.trigger('userChanged'); + window.Whisper.events.trigger('userChanged', true); } public getNumber(): string | undefined {