mirror of
https://github.com/moparisthebest/mail
synced 2024-11-04 16:25:07 -05:00
[WO-29] delete messages asynchronously
This commit is contained in:
parent
d4398ebbb8
commit
9d1b2e33ef
@ -50,10 +50,33 @@ define(function(require) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
$scope.remove = function(email) {
|
$scope.remove = function(email) {
|
||||||
|
if (!email) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var index;
|
||||||
|
removeLocalAndShowNext();
|
||||||
|
removeRemote();
|
||||||
|
|
||||||
|
function removeLocalAndShowNext() {
|
||||||
|
index = $scope.emails.indexOf(email);
|
||||||
|
// show the next mail
|
||||||
|
if ($scope.emails.length > 1) {
|
||||||
|
// if we're about to delete the last entry of the array, show the previous (i.e. the one below in the list),
|
||||||
|
// otherwise show the next one (i.e. the one above in the list)
|
||||||
|
$scope.select(_.last($scope.emails) === email ? $scope.emails[index - 1] : $scope.emails[index + 1]);
|
||||||
|
} else {
|
||||||
|
// if we have only one email in the array, show nothing
|
||||||
|
$scope.select();
|
||||||
|
$scope.selected = undefined;
|
||||||
|
}
|
||||||
|
$scope.emails.splice(index, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeRemote() {
|
||||||
var trashFolder = _.findWhere($scope.folders, {
|
var trashFolder = _.findWhere($scope.folders, {
|
||||||
type: 'Trash'
|
type: 'Trash'
|
||||||
});
|
});
|
||||||
|
|
||||||
if ($scope.currentFolder === trashFolder) {
|
if ($scope.currentFolder === trashFolder) {
|
||||||
emailDao.imapDeleteMessage({
|
emailDao.imapDeleteMessage({
|
||||||
folder: $scope.currentFolder.path,
|
folder: $scope.currentFolder.path,
|
||||||
@ -67,28 +90,15 @@ define(function(require) {
|
|||||||
uid: email.uid,
|
uid: email.uid,
|
||||||
destination: trashFolder.path
|
destination: trashFolder.path
|
||||||
}, moved);
|
}, moved);
|
||||||
|
}
|
||||||
|
|
||||||
function moved(err) {
|
function moved(err) {
|
||||||
var index;
|
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
$scope.emails.splice(index, 0, email);
|
||||||
|
$scope.$apply();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
index = $scope.emails.indexOf(email);
|
|
||||||
// show the next mail
|
|
||||||
if ($scope.emails.length > 1) {
|
|
||||||
// if we're about to delete the last entry of the array, show the previous (i.e. the one below in the list),
|
|
||||||
// otherwise show the next one (i.e. the one above in the list)
|
|
||||||
$scope.select(_.last($scope.emails) === email ? $scope.emails[index - 1] : $scope.emails[index + 1]);
|
|
||||||
} else {
|
|
||||||
// if we have only one email in the array, show nothing
|
|
||||||
$scope.select();
|
|
||||||
$scope.selected = undefined;
|
|
||||||
}
|
|
||||||
$scope.emails.splice(index, 1);
|
|
||||||
$scope.$apply();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user