浏览代码

Prevent double-download of audio messages

Previously, when clicking on the play button of an already downloaded
audio message, the player would appear, disappear, and reappear because
the download command was sent twice.
Danilo Bargen 7 年之前
父节点
当前提交
14a620b2b1
共有 3 个文件被更改,包括 8 次插入4 次删除
  1. 1 1
      src/directives/message_media.html
  2. 6 2
      src/directives/message_media.ts
  3. 1 1
      src/services/webclient.ts

+ 1 - 1
src/directives/message_media.html

@@ -47,7 +47,7 @@
             <div class="loading" ng-class="{active: ctrl.isDownloading()}"></div>
         </div>
         <!-- Play Indicator -->
-        <div class="circle" ng-click="ctrl.download()" ng-if="ctrl.downloaded">
+        <div class="circle" ng-if="ctrl.downloaded">
             <i class="material-icons md-24">play_arrow</i>
         </div>
         <div class="info" translate>messageTypes.AUDIO_MESSAGE</div>

+ 6 - 2
src/directives/message_media.ts

@@ -50,6 +50,7 @@ export default [
             },
             controllerAs: 'ctrl',
             controller: [function() {
+                this.logTag = '[MessageMedia]';
                 this.type = this.message.type;
                 this.downloading = false;
                 this.thumbnailDownloading = false;
@@ -170,8 +171,9 @@ export default [
 
                 // Download function
                 this.download = () => {
+                    $log.debug(this.logTag, 'Download blob');
                     if (this.downloading) {
-                        $log.debug('download already in progress...');
+                        $log.debug(this.logTag, 'Download already in progress...');
                         return;
                     }
                     const message: threema.Message = this.message;
@@ -180,6 +182,7 @@ export default [
                     webClientService.requestBlob(message.id, receiver)
                         .then((blobInfo: threema.BlobInfo) => {
                             $rootScope.$apply(() => {
+                                $log.debug(this.logTag, 'Blob loaded');
                                 this.downloading = false;
                                 this.downloaded = true;
 
@@ -211,7 +214,8 @@ export default [
                                         this.playAudio(blobInfo);
                                         break;
                                     default:
-                                        $log.warn('Ignored download request for message type', this.message.type);
+                                        $log.warn(this.logTag,
+                                            'Ignored download request for message type', this.message.type);
                                 }
                             });
                         })

+ 1 - 1
src/services/webclient.ts

@@ -1057,7 +1057,7 @@ export class WebClientService {
 
         if (cached !== undefined) {
 
-            this.$log.debug('Use cached blob');
+            this.$log.debug(this.logTag, 'Use cached blob');
             return new Promise((resolve) => {
                 resolve(cached);
             });