ソースを参照

Don't reset state after push service init

Danilo Bargen 7 年 前
コミット
c5bca54e78
2 ファイル変更15 行追加10 行削除
  1. 14 10
      src/partials/welcome.ts
  2. 1 0
      src/services/webclient.ts

+ 14 - 10
src/partials/welcome.ts

@@ -302,14 +302,8 @@ class WelcomeController {
         // Set up the broadcast channel that checks whether we're already connected in another tab
         this.setupBroadcastChannel(keyStore.publicKeyHex);
 
-        // Initialize push service
-        if (decrypted.pushToken !== null && decrypted.pushTokenType !== null) {
-            this.webClientService.updatePushToken(decrypted.pushToken, decrypted.pushTokenType);
-            this.pushService.init(decrypted.pushToken, decrypted.pushTokenType);
-        }
-
         // Reconnect
-        this.reconnect(keyStore, decrypted.peerPublicKey);
+        this.reconnect(keyStore, decrypted);
     }
 
     /**
@@ -381,19 +375,29 @@ class WelcomeController {
     }
 
     /**
-     * Reconnect using a specific keypair and peer public key.
+     * Reconnect using a specific keypair and the decrypted data from the trusted keystore.
      */
-    private reconnect(keyStore: saltyrtc.KeyStore, peerTrustedKey: Uint8Array): void {
+    private reconnect(keyStore: saltyrtc.KeyStore, decrypted: threema.TrustedKeyStoreData): void {
+        // Reset state
         this.webClientService.stop({
             reason: DisconnectReason.SessionStopped,
             send: false,
             close: 'welcome',
         });
+
+        // Initialize push service
+        if (decrypted.pushToken !== null && decrypted.pushTokenType !== null) {
+            this.webClientService.updatePushToken(decrypted.pushToken, decrypted.pushTokenType);
+            this.pushService.init(decrypted.pushToken, decrypted.pushTokenType);
+        }
+
+        // Initialize webclient service
         this.webClientService.init({
             keyStore: keyStore,
-            peerTrustedKey: peerTrustedKey,
+            peerTrustedKey: decrypted.peerPublicKey,
             resume: false,
         });
+
         this.start();
     }
 

+ 1 - 0
src/services/webclient.ts

@@ -1086,6 +1086,7 @@ export class WebClientService {
         // Clear stored data (trusted key, push token, etc) if deleting the session
         if (remove) {
             this.trustedKeyStore.clearTrustedKey();
+            this.pushService.reset();
         }
 
         // Invalidate and clear caches