ソースを参照

Update format of clientInfo response

Danilo Bargen 7 年 前
コミット
30b2ac4818
2 ファイル変更61 行追加8 行削除
  1. 34 6
      src/services/webclient.ts
  2. 27 2
      src/threema.d.ts

+ 34 - 6
src/services/webclient.ts

@@ -2118,12 +2118,42 @@ export class WebClientService {
             return;
         }
 
-        this.clientInfo = data as threema.ClientInfo;
+        /**
+         * Return the field if it's not undefined, otherwise return the default.
+         */
+        function getOrDefault<T>(field: T, defaultVal: T): T {
+            if (field === undefined) {
+                return defaultVal;
+            }
+            return field;
+        }
+
+        // Set clientInfo attribute
+        this.clientInfo = {
+            device: data.device,
+            os: data.os,
+            osVersion: data.osVersion,
+            isWork: data.isWork,
+            pushToken: data.pushToken,
+            configuration: {
+                showLocationPreview: getOrDefault<boolean>(data.configuration.showLocationPreview, false),
+                voipEnabled: getOrDefault<boolean>(data.configuration.voipEnabled, true),
+                voipForceTurn: getOrDefault<boolean>(data.configuration.voipForceTurn, false),
+                largeSingleEmoji: getOrDefault<boolean>(data.configuration.largeSingleEmoji, true),
+                showInactiveIds: getOrDefault<boolean>(data.configuration.showInactiveIds, true),
+            },
+            capabilities: {
+                maxGroupSize: getOrDefault<number>(data.capabilities.maxGroupSize, 50),
+                distributionLists: getOrDefault<boolean>(data.capabilities.distributionLists, true),
+                mdm: data.capabilities.mdm,
+            },
+        };
+
         this.$log.debug('Client device:', this.clientInfo.device);
 
         // Store push token
-        if (this.clientInfo.myPushToken) {
-            this.pushToken = this.clientInfo.myPushToken;
+        if (this.clientInfo.pushToken) {
+            this.pushToken = this.clientInfo.pushToken;
             this.pushService.init(this.pushToken);
         }
 
@@ -2169,7 +2199,6 @@ export class WebClientService {
 
     /**
      * Return the max text length
-     * @returns {number}
      */
     public getMaxTextLength(): number {
         return WebClientService.MAX_TEXT_LENGTH;
@@ -2177,10 +2206,9 @@ export class WebClientService {
 
     /**
      * Returns the max group member size
-     * @returns {number}
      */
     public getMaxGroupMemberSize(): number {
-        return this.clientInfo && this.clientInfo.maxGroupSize ? this.clientInfo.maxGroupSize : 50;
+        return this.clientInfo.capabilities.maxGroupSize;
     }
 
     /**

+ 27 - 2
src/threema.d.ts

@@ -561,8 +561,33 @@ declare namespace threema {
         os: string;
         osVersion: string;
         isWork: boolean;
-        myPushToken?: string;
-        maxGroupSize?: number;
+        pushToken?: string;
+        configuration: AppConfig;
+        capabilities: AppCapabilities;
+    }
+
+    interface AppConfig {
+        showLocationPreview: boolean;
+        voipEnabled: boolean;
+        voipForceTurn: boolean;
+        largeSingleEmoji: boolean;
+        showInactiveIds: boolean;
+    }
+
+    interface AppCapabilities {
+        maxGroupSize: number;
+        distributionLists: boolean;
+        mdm?: MdmRestrictions;
+    }
+
+    interface MdmRestrictions {
+        disableAddContact?: boolean;
+        disableCreateGroup?: boolean;
+        disableSaveToGallery?: boolean;
+        disableExport?: boolean;
+        disableMessagePreview?: boolean;
+        disableCalls?: boolean;
+        readonlyProfile?: boolean;
     }
 
     interface Mention {