Expunge mailbox on specific actions

Current mailbox is now expunged when leaving the Mail module. The drafts
mailbox is also expunged when a message is sent.
This commit is contained in:
Francis Lachapelle
2016-07-27 11:56:28 -04:00
parent f1d2bcffc8
commit 80338daf91
3 changed files with 27 additions and 6 deletions
@@ -6,11 +6,11 @@
/**
* @ngInject
*/
MailboxController.$inject = ['$window', '$timeout', '$q', '$state', '$mdDialog', '$mdToast', 'stateAccounts', 'stateAccount', 'stateMailbox', 'encodeUriFilter', 'sgFocus', 'Dialog', 'Account', 'Mailbox'];
function MailboxController($window, $timeout, $q, $state, $mdDialog, $mdToast, stateAccounts, stateAccount, stateMailbox, encodeUriFilter, focus, Dialog, Account, Mailbox) {
MailboxController.$inject = ['$window', '$scope', '$timeout', '$q', '$state', '$mdDialog', '$mdToast', 'stateAccounts', 'stateAccount', 'stateMailbox', 'encodeUriFilter', 'sgFocus', 'Dialog', 'Account', 'Mailbox'];
function MailboxController($window, $scope, $timeout, $q, $state, $mdDialog, $mdToast, stateAccounts, stateAccount, stateMailbox, encodeUriFilter, focus, Dialog, Account, Mailbox) {
var vm = this, messageDialog = null;
// Expose controller
// Expose controller for eventual popup windows
$window.$mailboxController = vm;
stateMailbox.selectFolder();
@@ -36,6 +36,16 @@
vm.selectAll = selectAll;
vm.unselectMessages = unselectMessages;
// Expunge mailbox when leaving the Mail module
angular.element($window).on('beforeunload', _compactBeforeUnload);
$scope.$on('$destroy', function() {
angular.element($window).off('beforeunload', _compactBeforeUnload);
});
function _compactBeforeUnload(event) {
return vm.selectedFolder.$compact();
}
function sort(field) {
vm.selectedFolder.$filter({ sort: field });
}