Browse Source

Clear mediabox on state transitions

Danilo Bargen 6 năm trước cách đây
mục cha
commit
56940818e8
2 tập tin đã thay đổi với 18 bổ sung6 xóa
  1. 10 6
      src/directives/mediabox.ts
  2. 8 0
      src/directives/message_media.ts

+ 10 - 6
src/directives/mediabox.ts

@@ -60,12 +60,16 @@ export default [
                 // Listen to Mediabox service events
                 mediaboxService.evtMediaChanged.attach((dataAvailable: boolean) => {
                     $rootScope.$apply(() => {
-                        this.imageDataUrl = bufferToUrl(
-                            mediaboxService.data,
-                            mediaboxService.mimetype,
-                            logAdapter($log.debug, this.logTag),
-                        );
-                        this.caption = mediaboxService.caption || mediaboxService.filename;
+                        if (dataAvailable) {
+                            this.imageDataUrl = bufferToUrl(
+                                mediaboxService.data,
+                                mediaboxService.mimetype,
+                                logAdapter($log.debug, this.logTag),
+                            );
+                            this.caption = mediaboxService.caption || mediaboxService.filename;
+                        } else {
+                            this.close();
+                        }
                     });
                 });
             }],

+ 8 - 0
src/directives/message_media.ts

@@ -15,6 +15,7 @@
  * along with Threema Web. If not, see <http://www.gnu.org/licenses/>.
  */
 
+import {Transition as UiTransition, TransitionService as UiTransitionService} from '@uirouter/angularjs';
 import {saveAs} from 'file-saver';
 
 import {bufferToUrl, hasValue, logAdapter} from '../helpers';
@@ -69,6 +70,7 @@ export default [
     '$rootScope',
     '$mdDialog',
     '$timeout',
+    '$transitions',
     '$translate',
     '$log',
     '$filter',
@@ -80,6 +82,7 @@ export default [
              $rootScope: ng.IRootScopeService,
              $mdDialog: ng.material.IDialogService,
              $timeout: ng.ITimeoutService,
+             $transitions: UiTransitionService,
              $translate: ng.translate.ITranslateService,
              $log: ng.ILogService,
              $filter: ng.IFilterService,
@@ -96,6 +99,11 @@ export default [
             controller: [function() {
                 this.logTag = '[MessageMedia]';
 
+                // On state transitions, clear mediabox
+                $transitions.onStart({}, function(trans: UiTransition) {
+                    mediaboxService.clearMedia();
+                });
+
                 this.$onInit = function() {
                     this.type = this.message.type;