(js) Simplify Account and Message services

pull/105/head
Francis Lachapelle 2015-08-28 15:15:40 -04:00
parent 624833eca9
commit 8f7334f11d
2 changed files with 15 additions and 27 deletions

View File

@ -96,21 +96,18 @@
* @returns a promise of the HTTP operation
*/
Account.prototype.$getMailboxes = function(options) {
var _this = this,
deferred = Account.$q.defer();
var _this = this;
if (this.$mailboxes && !(options && options.reload)) {
deferred.resolve(this.$mailboxes);
return Account.$q.when(this.$mailboxes);
}
else {
Account.$Mailbox.$find(this).then(function(data) {
return Account.$Mailbox.$find(this).then(function(data) {
_this.$mailboxes = data;
_this.$flattenMailboxes({reload: true});
deferred.resolve(_this.$mailboxes);
return _this.$mailboxes;
});
}
return deferred.promise;
};
/**

View File

@ -561,22 +561,12 @@
* @param {promise} futureMessageData - a promise of some of the Message's data
*/
Message.prototype.$unwrap = function(futureMessageData) {
var _this = this,
deferred = Message.$q.defer();
var _this = this;
// Expose the promise
this.$futureMessageData = futureMessageData;
// Resolve the promise
this.$futureMessageData.then(function(data) {
// Resolve and expose the promise
this.$futureMessageData = futureMessageData.then(function(data) {
// Calling $timeout will force Angular to refresh the view
Message.$timeout(function() {
angular.extend(_this, data);
_this.$formatFullAddresses();
_this.$loadUnsafeContent = false;
deferred.resolve(_this);
});
if (!_this.isread) {
if (_this.isread === 0) {
Message.$$resource.fetch(_this.$absolutePath(), 'markMessageRead').then(function() {
Message.$timeout(function() {
_this.isread = true;
@ -584,14 +574,15 @@
});
});
}
}, function(data) {
angular.extend(_this, data);
_this.isError = true;
Message.$log.error(_this.error);
deferred.reject();
return Message.$timeout(function() {
angular.extend(_this, data);
_this.$formatFullAddresses();
_this.$loadUnsafeContent = false;
return _this;
});
});
return deferred.promise;
return this.$futureMessageData;
};
/**