|
@@ -28,7 +28,6 @@ import {bufferToUrl, hasValue, logAdapter, supportsPassive, throttle, u8aToHex}
|
|
|
import {ContactService} from '../services/contact';
|
|
|
import {ControllerService} from '../services/controller';
|
|
|
import {ControllerModelService} from '../services/controller_model';
|
|
|
-import {ExecuteService} from '../services/execute';
|
|
|
import {FingerPrintService} from '../services/fingerprint';
|
|
|
import {TrustedKeyStoreService} from '../services/keystore';
|
|
|
import {MimeService} from '../services/mime';
|
|
@@ -1423,25 +1422,26 @@ class ReceiverEditController {
|
|
|
private logTag: string = '[ReceiverEditController]';
|
|
|
|
|
|
public $mdDialog: any;
|
|
|
+ private $scope: ng.IScope;
|
|
|
public $state: UiStateService;
|
|
|
private $translate: ng.translate.ITranslateService;
|
|
|
|
|
|
public title: string;
|
|
|
private $timeout: ng.ITimeoutService;
|
|
|
- private execute: ExecuteService;
|
|
|
- public loading = false;
|
|
|
+ private future: Future<threema.Receiver>;
|
|
|
|
|
|
private controllerModel: threema.ControllerModel<threema.Receiver>;
|
|
|
public type: string;
|
|
|
|
|
|
public static $inject = [
|
|
|
- '$log', '$stateParams', '$state', '$mdDialog',
|
|
|
+ '$log', '$scope', '$stateParams', '$state', '$mdDialog',
|
|
|
'$timeout', '$translate', 'WebClientService', 'ControllerModelService',
|
|
|
];
|
|
|
- constructor($log: ng.ILogService, $stateParams, $state: UiStateService,
|
|
|
+ constructor($log: ng.ILogService, $scope: ng.IScope, $stateParams, $state: UiStateService,
|
|
|
$mdDialog, $timeout: ng.ITimeoutService, $translate: ng.translate.ITranslateService,
|
|
|
webClientService: WebClientService, controllerModelService: ControllerModelService) {
|
|
|
|
|
|
+ this.$scope = $scope;
|
|
|
this.$mdDialog = $mdDialog;
|
|
|
this.$state = $state;
|
|
|
this.$timeout = $timeout;
|
|
@@ -1480,8 +1480,6 @@ class ReceiverEditController {
|
|
|
return;
|
|
|
}
|
|
|
this.type = receiver.type;
|
|
|
-
|
|
|
- this.execute = new ExecuteService($log, $timeout, 1000);
|
|
|
}
|
|
|
|
|
|
public keypress($event: KeyboardEvent): void {
|
|
@@ -1491,22 +1489,22 @@ class ReceiverEditController {
|
|
|
}
|
|
|
|
|
|
public save(): void {
|
|
|
- // show loading
|
|
|
- this.loading = true;
|
|
|
-
|
|
|
- // validate first
|
|
|
- this.execute.execute(this.controllerModel.save())
|
|
|
- .then((receiver: threema.Receiver) => {
|
|
|
- this.goBack();
|
|
|
+ this.future = Future.withMinDuration(this.controllerModel.save(), 100);
|
|
|
+ this.future
|
|
|
+ .then(() => {
|
|
|
+ this.$scope.$apply(() => {
|
|
|
+ this.goBack();
|
|
|
+ });
|
|
|
})
|
|
|
.catch((errorCode) => {
|
|
|
- this.showEditError(errorCode);
|
|
|
+ this.$scope.$apply(() => {
|
|
|
+ this.showEditError(errorCode);
|
|
|
+ });
|
|
|
});
|
|
|
}
|
|
|
|
|
|
public isSaving(): boolean {
|
|
|
- return this.execute !== undefined
|
|
|
- && this.execute.isRunning();
|
|
|
+ return this.future !== undefined && !this.future.done;
|
|
|
}
|
|
|
|
|
|
private showEditError(errorCode: string): void {
|
|
@@ -1540,7 +1538,7 @@ class ReceiverCreateController {
|
|
|
private logTag: string = '[ReceiverEditController]';
|
|
|
|
|
|
public $mdDialog: any;
|
|
|
- private loading = false;
|
|
|
+ private $scope: ng.IScope;
|
|
|
private $timeout: ng.ITimeoutService;
|
|
|
private $log: ng.ILogService;
|
|
|
private $state: UiStateService;
|
|
@@ -1548,16 +1546,17 @@ class ReceiverCreateController {
|
|
|
public identity = '';
|
|
|
private $translate: any;
|
|
|
public type: string;
|
|
|
- private execute: ExecuteService;
|
|
|
+ private future: Future<threema.Receiver>;
|
|
|
|
|
|
public controllerModel: threema.ControllerModel<threema.Receiver>;
|
|
|
|
|
|
- public static $inject = ['$stateParams', '$mdDialog', '$mdToast', '$translate',
|
|
|
+ public static $inject = ['$stateParams', '$mdDialog', '$scope', '$mdToast', '$translate',
|
|
|
'$timeout', '$state', '$log', 'ControllerModelService'];
|
|
|
- constructor($stateParams: CreateReceiverStateParams, $mdDialog, $mdToast, $translate,
|
|
|
+ constructor($stateParams: CreateReceiverStateParams, $mdDialog, $scope: ng.IScope, $mdToast, $translate,
|
|
|
$timeout: ng.ITimeoutService, $state: UiStateService, $log: ng.ILogService,
|
|
|
controllerModelService: ControllerModelService) {
|
|
|
this.$mdDialog = $mdDialog;
|
|
|
+ this.$scope = $scope;
|
|
|
this.$timeout = $timeout;
|
|
|
this.$state = $state;
|
|
|
this.$log = $log;
|
|
@@ -1586,11 +1585,10 @@ class ReceiverCreateController {
|
|
|
default:
|
|
|
this.$log.error('invalid type', this.type);
|
|
|
}
|
|
|
- this.execute = new ExecuteService($log, $timeout, 1000);
|
|
|
}
|
|
|
|
|
|
public isSaving(): boolean {
|
|
|
- return this.execute.isRunning();
|
|
|
+ return this.future !== undefined && !this.future.done;
|
|
|
}
|
|
|
|
|
|
public goBack(): void {
|
|
@@ -1619,15 +1617,19 @@ class ReceiverCreateController {
|
|
|
}
|
|
|
|
|
|
public create(): void {
|
|
|
- // Show loading indicator
|
|
|
- this.loading = true;
|
|
|
-
|
|
|
// Save, then go to receiver detail page
|
|
|
- this.execute.execute(this.controllerModel.save())
|
|
|
+ this.future = Future.withMinDuration(this.controllerModel.save(), 100);
|
|
|
+ this.future
|
|
|
.then((receiver: threema.Receiver) => {
|
|
|
- this.$state.go('messenger.home.detail', receiver, {location: 'replace'});
|
|
|
+ this.$scope.$apply(() => {
|
|
|
+ this.$state.go('messenger.home.detail', receiver, {location: 'replace'});
|
|
|
+ });
|
|
|
})
|
|
|
- .catch(this.showAddError.bind(this));
|
|
|
+ .catch((errorCode) => {
|
|
|
+ this.$scope.$apply(() => {
|
|
|
+ this.showAddError(errorCode);
|
|
|
+ });
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
|