Explorar o código

Support success flag in blob response

Danilo Bargen %!s(int64=7) %!d(string=hai) anos
pai
achega
fa9f243eb3

+ 3 - 1
public/i18n/de.json

@@ -205,7 +205,9 @@
         "TEXT_TOO_LONG": "Diese Nachricht ist zu lang und kann nicht gesendet werden (Maximale Länge {max} Zeichen).",
         "NOTIFICATION_PERMISSION_DENIED": "Sie müssen die Benachrichtigungsberechtigung für Threema Web manuell erteilen, um Desktopbenachrichtigungen erhalten zu können.",
         "NOTIFICATION_PERMISSION_DENIED_LEARN_MORE": "Mehr erfahren.",
-        "NOTIFICATION_API_NOT_AVAILABLE": "Ihr Browser unterstützt keine Desktopbenachrichtigungen."
+        "NOTIFICATION_API_NOT_AVAILABLE": "Ihr Browser unterstützt keine Desktopbenachrichtigungen.",
+        "BLOB_DOWNLOAD_FAILED": "Datei konnte nicht heruntergeladen werden",
+        "BLOB_DECRYPT_FAILED": "Datei konnte nicht entschlüsselt werden"
     },
     "mimeTypes": {
         "apk": "Android-Paket",

+ 3 - 1
public/i18n/en.json

@@ -205,7 +205,9 @@
         "TEXT_TOO_LONG": "This message is too long and cannot be sent (Max length {max} characters).",
         "NOTIFICATION_PERMISSION_DENIED": "You have to grant the notification permission for Threema Web manually in order to receive desktop notifications.",
         "NOTIFICATION_PERMISSION_DENIED_LEARN_MORE": "Learn more.",
-        "NOTIFICATION_API_NOT_AVAILABLE": "Your browser does not support desktop notifications."
+        "NOTIFICATION_API_NOT_AVAILABLE": "Your browser does not support desktop notifications.",
+        "BLOB_DOWNLOAD_FAILED": "Could not download file.",
+        "BLOB_DECRYPT_FAILED": "Could not decrypt file."
     },
     "mimeTypes": {
         "apk": "Android package",

+ 0 - 2
src/directives/message.ts

@@ -111,7 +111,6 @@ export default [
                         .then((buffer: ArrayBuffer) => {
                             $rootScope.$apply(() => {
                                 this.downloading = false;
-                                // this.downloaded = true;
 
                                 switch (this.message.type) {
                                     case 'image':
@@ -128,7 +127,6 @@ export default [
                         .catch((error) => {
                             $log.error('error downloading blob ', error);
                             this.downloading = false;
-                            // this.downloaded = true;
                         });
                 };
 

+ 22 - 2
src/directives/message_media.ts

@@ -26,6 +26,7 @@ export default [
     '$rootScope',
     '$mdDialog',
     '$timeout',
+    '$translate',
     '$log',
     '$filter',
     '$window',
@@ -35,6 +36,7 @@ export default [
              $rootScope: ng.IRootScopeService,
              $mdDialog: ng.material.IDialogService,
              $timeout: ng.ITimeoutService,
+             $translate: ng.translate.ITranslateService,
              $log: ng.ILogService,
              $filter: ng.IFilterService,
              $window: ng.IWindowService) {
@@ -201,8 +203,26 @@ export default [
                         })
                         .catch((error) => {
                             $log.error('error downloading blob ', error);
-                            this.downloading = false;
-                            this.downloaded = true;
+                            $rootScope.$apply(() => {
+                                this.downloading = false;
+                                let contentString;
+                                switch (error) {
+                                    case 'blobDownloadFailed':
+                                        contentString = 'error.BLOB_DOWNLOAD_FAILED';
+                                        break;
+                                    case 'blobDecryptFailed':
+                                        contentString = 'error.BLOB_DECRYPT_FAILED';
+                                        break;
+                                    default:
+                                        contentString = 'error.ERROR_OCCURRED';
+                                        break;
+                                }
+                                const confirm = $mdDialog.alert()
+                                    .title($translate.instant('common.ERROR'))
+                                    .textContent($translate.instant(contentString))
+                                    .ok($translate.instant('common.OK'));
+                                $mdDialog.show(confirm);
+                            });
                         });
                 };
 

+ 17 - 17
src/services/webclient.ts

@@ -1504,10 +1504,7 @@ export class WebClientService {
                     data: contactReceiver,
                 };
             case false:
-                return {
-                    success: false,
-                    error: args[WebClientService.ARGUMENT_ERROR],
-                };
+                return this.promiseRequestError(args[WebClientService.ARGUMENT_ERROR]);
             default:
                 this.$log.error('Invalid contact response, success field is not a boolean');
                 return this.promiseRequestError('invalidResponse');
@@ -1861,7 +1858,8 @@ export class WebClientService {
 
         return {
             success: true,
-            data: data};
+            data: data,
+        };
     }
 
     private _receiveResponseBlob(message: threema.WireMessage): threema.PromiseRequestResult<ArrayBuffer> {
@@ -1870,31 +1868,33 @@ export class WebClientService {
         // Unpack data and arguments
         const args = message.args;
         const data = message.data;
-        if (args === undefined || data === undefined) {
-            this.$log.warn('Invalid message response, data or arguments missing');
-            return {
-                success: false,
-            };
+        if (args === undefined ) {
+            this.$log.warn('Invalid message response, arguments missing');
+            return this.promiseRequestError('invalidResponse');
         }
 
         // Unpack required argument fields
         const receiverType = args[WebClientService.ARGUMENT_RECEIVER_TYPE];
         const receiverId = args[WebClientService.ARGUMENT_RECEIVER_ID];
         const msgId: string = args[WebClientService.ARGUMENT_MESSAGE_ID];
-        if (receiverType === undefined || receiverId === undefined || msgId === undefined) {
+        const temporaryId: string = args[WebClientService.ARGUMENT_TEMPORARY_ID];
+        const success: boolean = args[WebClientService.ARGUMENT_SUCCESS];
+        if (receiverType === undefined || receiverId === undefined
+            || msgId === undefined || temporaryId === undefined || success === undefined) {
             this.$log.warn('Invalid blob response, argument field missing');
-            return {
-                success: false,
-            };
+            return this.promiseRequestError('invalidResponse');
+        }
+
+        // Check success flag
+        if (success === false) {
+            return this.promiseRequestError(args[WebClientService.ARGUMENT_ERROR]);
         }
 
         // Unpack data
         const buffer: ArrayBuffer = data[WebClientService.DATA_FIELD_BLOB_BLOB];
         if (buffer === undefined) {
             this.$log.warn('Invalid blob response, data field missing');
-            return {
-                success: false,
-            };
+            return this.promiseRequestError('invalidResponse');
         }
 
         this.blobCache.set(msgId + receiverType, buffer);