Browse Source

Send outgoing update/connectionDisconnect messages

Danilo Bargen 7 years ago
parent
commit
84f6997ede
4 changed files with 12 additions and 20 deletions
  1. 2 4
      src/controllers/status.ts
  2. 2 4
      src/partials/messenger.ts
  3. 1 2
      src/partials/welcome.ts
  4. 7 10
      src/services/webclient.ts

+ 2 - 4
src/controllers/status.ts

@@ -197,10 +197,9 @@ export class StatusController {
 
         // Function to soft-reconnect. Does not reset the loaded data.
         const doSoftReconnect = () => {
-            const deleteStoredData = false;
             const resetPush = false;
             const redirect = false;
-            this.webClientService.stop(true, deleteStoredData, resetPush, redirect);
+            this.webClientService.stop(true, threema.DisconnectReason.SessionStopped, resetPush, redirect);
             this.webClientService.init(originalKeyStore, originalPeerPermanentKeyBytes, false);
             this.webClientService.start().then(
                 () => {
@@ -265,13 +264,12 @@ export class StatusController {
             });
         };
 
-        const deleteStoredData = false;
         const resetPush = false;
         const skipPush = true;
         const redirect = false;
         const startTimeout = 500; // Delay connecting a bit to wait for old websocket to close
         this.$log.debug(this.logTag, 'Stopping old connection');
-        this.webClientService.stop(true, deleteStoredData, resetPush, redirect);
+        this.webClientService.stop(true, threema.DisconnectReason.SessionStopped, resetPush, redirect);
         this.$timeout(() => {
             this.$log.debug(this.logTag, 'Starting new connection');
             this.webClientService.init(originalKeyStore, originalPeerPermanentKeyBytes, false);

+ 2 - 4
src/partials/messenger.ts

@@ -1001,10 +1001,9 @@ class NavigationController {
             .ok(this.$translate.instant('common.YES'))
             .cancel(this.$translate.instant('common.CANCEL'));
         this.$mdDialog.show(confirm).then(() => {
-            const deleteStoredData = false;
             const resetPush = true;
             const redirect = true;
-            this.webClientService.stop(true, deleteStoredData, resetPush, redirect);
+            this.webClientService.stop(true, threema.DisconnectReason.SessionStopped, resetPush, redirect);
             this.receiverService.setActive(undefined);
         }, () => {
             // do nothing
@@ -1022,10 +1021,9 @@ class NavigationController {
             .ok(this.$translate.instant('common.YES'))
             .cancel(this.$translate.instant('common.CANCEL'));
         this.$mdDialog.show(confirm).then(() => {
-            const deleteStoredData = true;
             const resetPush = true;
             const redirect = true;
-            this.webClientService.stop(true, deleteStoredData, resetPush, redirect);
+            this.webClientService.stop(true, threema.DisconnectReason.SessionDeleted, resetPush, redirect);
             this.receiverService.setActive(undefined);
         }, () => {
             // do nothing

+ 1 - 2
src/partials/welcome.ts

@@ -464,10 +464,9 @@ class WelcomeController {
 
         this.$mdDialog.show(confirm).then(() =>  {
             // Force-stop the webclient
-            const deleteStoredData = true;
             const resetPush = true;
             const redirect = false;
-            this.webClientService.stop(true, deleteStoredData, resetPush, redirect);
+            this.webClientService.stop(true, threema.DisconnectReason.SessionDeleted, resetPush, redirect);
 
             // Reset state
             this.stateService.updateConnectionBuildupState('new');

+ 7 - 10
src/services/webclient.ts

@@ -722,19 +722,20 @@ export class WebClientService {
      * Parameters:
      *
      * - `requestedByUs`: Set this to `false` if the app requested to close the session.
-     * - `deleteStoredData`: Whether to clear any trusted key or push token from the keystore.
+     * - `reason`: The disconnect reason. When this is `SessionDeleted`, the function
+     *             will clear any trusted key or push token from the keystore.
      * - `resetPush`: Whether to reset the push service.
      * - `redirect`: Whether to redirect to the welcome page.
      */
     public stop(requestedByUs: boolean,
-                deleteStoredData: boolean = false,
+                reason: threema.DisconnectReason,
                 resetPush: boolean = true,
                 redirect: boolean = false): void {
         this.$log.info(this.logTag, 'Disconnecting...');
 
         if (requestedByUs && this.stateService.state === threema.GlobalConnectionState.Ok) {
             // Ask peer to disconnect too
-            this.salty.sendApplicationMessage({type: 'disconnect', forget: deleteStoredData});
+            this._sendUpdate(WebClientService.SUB_TYPE_CONNECTION_DISCONNECT, undefined, {reason: reason});
         }
 
         this.stateService.reset();
@@ -743,6 +744,7 @@ export class WebClientService {
         this.resetUnreadCount();
 
         // Clear stored data (trusted key, push token, etc)
+        const deleteStoredData = reason === threema.DisconnectReason.SessionDeleted;
         if (deleteStoredData === true) {
             this.trustedKeyStore.clearTrustedKey();
         }
@@ -779,7 +781,7 @@ export class WebClientService {
             this.pcHelper.close()
                 .then(
                     () => this.$log.debug(this.logTag, 'Peer connection was closed'),
-                    (reason: string) => this.$log.warn(this.logTag, 'Peer connection could not be closed:', reason),
+                    (msg: string) => this.$log.warn(this.logTag, 'Peer connection could not be closed:', msg),
                 )
                 .finally(() => redirectToWelcome());
         } else {
@@ -1718,22 +1720,17 @@ export class WebClientService {
         this.$log.debug(this.logTag, 'Disconnecting requested: reason=', reason);
 
         let alertMessage: string;
-        let deleteStoredData: boolean;
         switch (reason) {
             case threema.DisconnectReason.SessionStopped:
-                deleteStoredData = false;
                 alertMessage = 'connection.SESSION_STOPPED';
                 break;
             case threema.DisconnectReason.SessionDeleted:
-                deleteStoredData = true;
                 alertMessage = 'connection.SESSION_DELETED';
                 break;
             case threema.DisconnectReason.WebclientDisabled:
-                deleteStoredData = false;
                 alertMessage = 'connection.WEBCLIENT_DISABLED';
                 break;
             case threema.DisconnectReason.SessionReplaced:
-                deleteStoredData = false;
                 alertMessage = 'connection.SESSION_REPLACED';
                 break;
             default:
@@ -1741,7 +1738,7 @@ export class WebClientService {
         }
         const resetPush = true;
         const redirect = true;
-        this.stop(false, deleteStoredData, resetPush, redirect);
+        this.stop(false, reason, resetPush, redirect);
 
         if (alertMessage !== undefined) {
             this.$mdDialog.show(this.$mdDialog.alert()