(feat) added IMAP folders subscriptions management (fixes #255)

This commit is contained in:
Ludovic Marcotte
2016-09-14 15:57:49 -04:00
parent 49d58b436e
commit 42127c51ab
17 changed files with 362 additions and 104 deletions
@@ -8,7 +8,7 @@
* @constructor
* @param {object} futureAccountData
*/
function Account(futureAccountData) {
function Account(futureAccountData, fetchAll) {
// Data is immediately available
if (typeof futureAccountData.then !== 'function') {
angular.extend(this, futureAccountData);
@@ -24,6 +24,14 @@
// The promise will be unwrapped first
//this.$unwrap(futureAccountData);
}
this.fetchAll = false;
// Check if we're displaying the IMAP subscription management dialog
if (angular.isDefined(fetchAll) && fetchAll) {
this.fetchAll = true;
this.$getMailboxes();
}
}
/**
@@ -84,7 +84,10 @@
Mailbox.$find = function(account) {
var path, futureMailboxData;
futureMailboxData = this.$$resource.fetch(account.id.toString(), 'view');
if (account.fetchAll)
futureMailboxData = this.$$resource.fetch(account.id.toString(), 'viewAll');
else
futureMailboxData = this.$$resource.fetch(account.id.toString(), 'view');
return Mailbox.$unwrapCollection(account, futureMailboxData); // a collection of mailboxes
};
@@ -890,4 +893,15 @@
});
};
/**
* @function $toggleSubscribe
* @memberof Mailbox.prototype
* @desc Subscribe or unsubscribe to a mailbox
*/
Mailbox.prototype.$toggleSubscribe = function() {
if (this.subscribed)
return Mailbox.$$resource.post(this.id, 'subscribe');
return Mailbox.$$resource.post(this.id, 'unsubscribe');
};
})();
@@ -15,6 +15,7 @@
vm.service = Mailbox;
vm.accounts = stateAccounts;
vm.toggleAccountState = toggleAccountState;
vm.subscribe = subscribe;
vm.newFolder = newFolder;
vm.delegate = delegate;
vm.editFolder = editFolder;
@@ -54,6 +55,10 @@
params: []
};
Preferences.ready().then(function() {
vm.showSubscribedOnly = Preferences.defaults.SOGoMailShowSubscribedFoldersOnly;
});
vm.refreshUnseenCount();
function showAdvancedSearch(path) {
@@ -146,6 +151,40 @@
}, 150);
}
function subscribe(account) {
$mdDialog.show({
templateUrl: account.id + '/subscribe',
controller: SubscriptionsDialogController,
controllerAs: 'subscriptions',
clickOutsideToClose: true,
escapeToClose: true,
locals: {
srcApp: vm,
srcAccount: account
}
}).finally(function() {
account.$getMailboxes({reload: true});
});
/**
* @ngInject
*/
SubscriptionsDialogController.$inject = ['$scope', '$mdDialog', 'srcApp', 'srcAccount'];
function SubscriptionsDialogController($scope, $mdDialog, srcApp, srcAccount) {
var vm = this;
vm.app = srcApp;
vm.account = new Account({id: srcAccount.id,
name: srcAccount.name},
true);
vm.close = close;
function close() {
$mdDialog.cancel();
}
}
}
function newFolder(parentFolder) {
Dialog.prompt(l('New folder'),
l('Enter the new name of your folder :'))
@@ -305,19 +344,19 @@
function metadataForFolder(folder) {
if (folder.type == 'inbox')
return {name: folder.name, icon:'inbox'};
return {name: folder.name, icon:'inbox', special: true};
else if (folder.type == 'draft')
return {name: l('DraftsFolderName'), icon: 'drafts'};
return {name: l('DraftsFolderName'), icon: 'drafts', special: true};
else if (folder.type == 'sent')
return {name: l('SentFolderName'), icon: 'send'};
return {name: l('SentFolderName'), icon: 'send', special: true};
else if (folder.type == 'trash')
return {name: l('TrashFolderName'), icon: 'delete'};
return {name: l('TrashFolderName'), icon: 'delete', special: true};
else if (folder.type == 'junk')
return {name: l('JunkFolderName'), icon: 'thumb_down'};
return {name: l('JunkFolderName'), icon: 'thumb_down', special: true};
else if (folder.type == 'additional')
return {name: folder.name, icon: 'folder_shared'};
return {name: folder.name, icon: 'folder_shared', special: true};
return {name: folder.name, icon: 'folder_open'};
return {name: folder.name, icon: 'folder_open', special: false};
}
function setFolderAs(folder, type) {