瀏覽代碼

Show disconnect reason

Danilo Bargen 7 年之前
父節點
當前提交
cf6d9b29c5
共有 4 個文件被更改,包括 57 次插入4 次删除
  1. 7 0
      public/i18n/de.json
  2. 7 0
      public/i18n/en.json
  3. 30 4
      src/services/webclient.ts
  4. 13 0
      src/threema.d.ts

+ 7 - 0
public/i18n/de.json

@@ -300,5 +300,12 @@
             "NOV": "Nov.",
             "DEC": "Dez."
         }
+    },
+    "connection": {
+        "SESSION_CLOSED_TITLE": "Sitzung Geschlossen",
+        "SESSION_STOPPED": "Die Sitzung wurde auf Ihrem Gerät gestoppt.",
+        "SESSION_DELETED": "Die Sitzung wurde auf Ihrem Gerät gelöscht.",
+        "WEBCLIENT_DISABLED": "Threema Web wurde auf Ihrem Gerät deaktiviert.",
+        "SESSION_REPLACED": "Die Sitzung wurde beendet, weil Sie eine andere Sitzung gestartet haben."
     }
 }

+ 7 - 0
public/i18n/en.json

@@ -299,5 +299,12 @@
             "NOV": "Nov.",
             "DEC": "Dec."
         }
+    },
+    "connection": {
+        "SESSION_CLOSED_TITLE": "Session Closed",
+        "SESSION_STOPPED": "The session was stopped on your device.",
+        "SESSION_DELETED": "The session was deleted on your device.",
+        "WEBCLIENT_DISABLED": "Threema Web was disabled on your device.",
+        "SESSION_REPLACED": "This session was stopped because you started a Threema Web session in another browser window."
     }
 }

+ 30 - 4
src/services/webclient.ts

@@ -461,7 +461,7 @@ export class WebClientService {
         // Handle a disconnect request
         this.salty.on('application', (applicationData: any) => {
             if (applicationData.data.type === 'disconnect') {
-                this.onApplicationDisconnect(applicationData);
+                this.onApplicationDisconnect(applicationData.data);
             }
         });
 
@@ -631,12 +631,38 @@ export class WebClientService {
     /**
      * An 'application' message with type 'disconnect' arrived.
      */
-    private onApplicationDisconnect(applicationData: any) {
-        this.$log.debug(this.logTag, 'Disconnecting requested');
-        const deleteStoredData = applicationData.data.forget === true;
+    private onApplicationDisconnect(data: threema.DisconnectMessage) {
+        this.$log.debug(this.logTag, 'Disconnecting requested:', data);
+
+        const deleteStoredData = data.forget === true;
         const resetPush = true;
         const redirect = true;
         this.stop(false, deleteStoredData, resetPush, redirect);
+
+        let message: string;
+        switch (data.reason) {
+            case threema.DisconnectReason.SessionStopped:
+                message = 'connection.SESSION_STOPPED';
+                break;
+            case threema.DisconnectReason.SessionDeleted:
+                message = 'connection.SESSION_DELETED';
+                break;
+            case threema.DisconnectReason.WebclientDisabled:
+                message = 'connection.WEBCLIENT_DISABLED';
+                break;
+            case threema.DisconnectReason.SessionReplaced:
+                message = 'connection.SESSION_REPLACED';
+                break;
+            default:
+                this.$log.warn(this.logTag, 'Unknown disconnect reason:', data.reason);
+        }
+
+        if (message !== undefined) {
+            this.$mdDialog.show(this.$mdDialog.alert()
+                .title(this.$translate.instant('connection.SESSION_CLOSED_TITLE'))
+                .textContent(this.$translate.instant(message))
+                .ok(this.$translate.instant('common.OK')));
+        }
     }
 
     /**

+ 13 - 0
src/threema.d.ts

@@ -714,6 +714,19 @@ declare namespace threema {
         RelayedData,
     }
 
+    interface DisconnectMessage {
+        type: 'disconnect';
+        forget: boolean;
+        reason: DisconnectReason;
+    }
+
+    const enum DisconnectReason {
+        SessionStopped = 1,
+        SessionDeleted = 2,
+        WebclientDisabled = 3,
+        SessionReplaced = 4,
+    }
+
     namespace Container {
         interface ReceiverData {
             contacts: ContactReceiver[];