mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-07-05 16:35:10 +00:00
(feat) unseen count support folder all accounts/mailboxes
This commit is contained in:
@@ -728,54 +728,6 @@
|
||||
return [self _subscriptionStubAction];
|
||||
}
|
||||
|
||||
- (NSDictionary *) _unseenCount
|
||||
{
|
||||
EOQualifier *searchQualifier;
|
||||
NSArray *searchResult;
|
||||
NSDictionary *imapResult;
|
||||
// NSMutableDictionary *data;
|
||||
NGImap4Connection *connection;
|
||||
NGImap4Client *client;
|
||||
int unseen;
|
||||
SOGoMailFolder *folder;
|
||||
|
||||
folder = [self clientObject];
|
||||
|
||||
connection = [folder imap4Connection];
|
||||
client = [connection client];
|
||||
|
||||
if ([connection selectFolder: [folder imap4URL]])
|
||||
{
|
||||
searchQualifier
|
||||
= [EOQualifier qualifierWithQualifierFormat: @"flags = %@ AND not flags = %@",
|
||||
@"unseen", @"deleted"];
|
||||
imapResult = [client searchWithQualifier: searchQualifier];
|
||||
searchResult = [[imapResult objectForKey: @"RawResponse"] objectForKey: @"search"];
|
||||
unseen = [searchResult count];
|
||||
}
|
||||
else
|
||||
unseen = 0;
|
||||
|
||||
return [NSDictionary
|
||||
dictionaryWithObject: [NSNumber numberWithInt: unseen]
|
||||
forKey: @"unseen"];
|
||||
}
|
||||
|
||||
- (WOResponse *) unseenCountAction
|
||||
{
|
||||
WOResponse *response;
|
||||
NSDictionary *data;
|
||||
|
||||
response = [self responseWithStatus: 200];
|
||||
data = [self _unseenCount];
|
||||
|
||||
[response setHeader: @"text/plain; charset=utf-8"
|
||||
forKey: @"content-type"];
|
||||
[response appendContentString: [data jsonRepresentation]];
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
- (WOResponse *) addOrRemoveLabelAction
|
||||
{
|
||||
WOResponse *response;
|
||||
|
||||
@@ -33,6 +33,9 @@
|
||||
#import <NGObjWeb/SoComponent.h>
|
||||
#import <NGExtensions/NSObject+Logs.h>
|
||||
#import <NGExtensions/NSString+misc.h>
|
||||
#import <NGImap4/NGImap4Connection.h>
|
||||
#import <NGImap4/NGImap4Client.h>
|
||||
#import <NGImap4/NSString+Imap4.h>
|
||||
|
||||
#import <Contacts/SOGoContactObject.h>
|
||||
#import <Contacts/SOGoContactGCSList.h>
|
||||
@@ -621,6 +624,72 @@
|
||||
return [self labelForKey: [currentColumn objectForKey: @"value"]];
|
||||
}
|
||||
|
||||
- (unsigned int) _unseenCountForFolder: (NSString *) theFolder
|
||||
{
|
||||
EOQualifier *searchQualifier;
|
||||
NSArray *searchResult, *pathComponents;
|
||||
NSDictionary *imapResult;
|
||||
NGImap4Connection *connection;
|
||||
NGImap4Client *client;
|
||||
unsigned int unseen;
|
||||
|
||||
SOGoMailAccount *account;
|
||||
SOGoMailFolder *folder;
|
||||
|
||||
pathComponents = [theFolder pathComponents];
|
||||
account = [[self clientObject] lookupName: [pathComponents objectAtIndex: 0]
|
||||
inContext: context
|
||||
acquire: YES];
|
||||
|
||||
folder = [account lookupName: [NSString pathWithComponents: [pathComponents subarrayWithRange: NSMakeRange(1, [pathComponents count]-1)]]
|
||||
inContext: context
|
||||
acquire: YES];
|
||||
|
||||
connection = [folder imap4Connection];
|
||||
client = [connection client];
|
||||
|
||||
if ([connection selectFolder: [folder imap4URL]])
|
||||
{
|
||||
searchQualifier
|
||||
= [EOQualifier qualifierWithQualifierFormat: @"flags = %@ AND not flags = %@",
|
||||
@"unseen", @"deleted"];
|
||||
imapResult = [client searchWithQualifier: searchQualifier];
|
||||
searchResult = [[imapResult objectForKey: @"RawResponse"] objectForKey: @"search"];
|
||||
unseen = [searchResult count];
|
||||
}
|
||||
else
|
||||
unseen = 0;
|
||||
|
||||
return unseen;
|
||||
}
|
||||
|
||||
- (WOResponse *) unseenCountAction
|
||||
{
|
||||
NSMutableDictionary *data;
|
||||
WOResponse *response;
|
||||
NSArray *folders;
|
||||
NSString *folder;
|
||||
int i;
|
||||
|
||||
folders = [[[[context request] contentAsString] objectFromJSONString] objectForKey: @"mailboxes"];
|
||||
data = [NSMutableDictionary dictionary];
|
||||
|
||||
for (i = 0; i < [folders count]; i++)
|
||||
{
|
||||
folder = [folders objectAtIndex: i];
|
||||
[data setObject: [NSNumber numberWithUnsignedInt: [self _unseenCountForFolder: folder]]
|
||||
forKey: folder];
|
||||
}
|
||||
|
||||
response = [self responseWithStatus: 200];
|
||||
|
||||
[response setHeader: @"text/plain; charset=utf-8"
|
||||
forKey: @"content-type"];
|
||||
[response appendContentString: [data jsonRepresentation]];
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
- (NSString *) unseenCountFolders
|
||||
{
|
||||
NSArray *pathComponents, *filters, *actions;
|
||||
@@ -670,7 +739,7 @@
|
||||
[path appendString: @"/"];
|
||||
}
|
||||
|
||||
[folders addObject: [NSString stringWithFormat: @"/0/%@", path]];
|
||||
[folders addObject: [NSString stringWithFormat: @"0/%@", path]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,11 +167,6 @@
|
||||
actionClass = "UIxMailFolderActions";
|
||||
actionName = "setAsTrashFolder";
|
||||
};
|
||||
unseenCount = {
|
||||
protectedBy = "View";
|
||||
actionClass = "UIxMailFolderActions";
|
||||
actionName = "unseenCount";
|
||||
};
|
||||
UIxMailUserRightsEditor = {
|
||||
protectedBy = "ReadAcls";
|
||||
pageName = "UIxMailUserRightsEditor";
|
||||
@@ -342,6 +337,11 @@
|
||||
protectedBy = "View";
|
||||
pageName = "UIxMailSearch";
|
||||
};
|
||||
unseenCount = {
|
||||
protectedBy = "View";
|
||||
actionClass = "UIxMailMainFrame";
|
||||
actionName = "unseenCount";
|
||||
};
|
||||
// viewerTemplate = {
|
||||
// protectedBy = "View";
|
||||
// pageName = "UIxMailViewTemplate";
|
||||
|
||||
@@ -258,7 +258,10 @@
|
||||
ui-sref-active="sg-active">
|
||||
<md-icon ng-class="'sg-child-level-' + folder.level">{{app.metadataForFolder(folder).icon}}</md-icon>
|
||||
<p class="sg-item-name"
|
||||
ng-show="app.editMode != folder.path">{{app.metadataForFolder(folder).name}}</p>
|
||||
ng-show="app.editMode != folder.path">
|
||||
{{app.metadataForFolder(folder).name}}
|
||||
<span ng-show="folder.unseenCount"> ({{folder.unseenCount}})</span>
|
||||
</p>
|
||||
<md-input-container class="md-flex md-tile-content"
|
||||
ng-show="app.editMode == folder.path">
|
||||
<input class="folder-name" type="text"
|
||||
|
||||
@@ -210,6 +210,9 @@
|
||||
Mailbox.prototype.$filter = function(sortingAttributes, filters) {
|
||||
var _this = this, options = {};
|
||||
|
||||
if (!angular.isDefined(this.unseenCount))
|
||||
this.unseenCount = 0;
|
||||
|
||||
this.$isLoading = true;
|
||||
|
||||
return Mailbox.$Preferences.ready().then(function() {
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
/**
|
||||
* @ngInject
|
||||
*/
|
||||
MailboxesController.$inject = ['$state', '$timeout', '$mdDialog', 'sgFocus', 'encodeUriFilter', 'Dialog', 'sgSettings', 'Account', 'Mailbox', 'User', 'stateAccounts'];
|
||||
function MailboxesController($state, $timeout, $mdDialog, focus, encodeUriFilter, Dialog, Settings, Account, Mailbox, User, stateAccounts) {
|
||||
MailboxesController.$inject = ['$state', '$timeout', '$mdDialog', 'sgFocus', 'encodeUriFilter', 'Dialog', 'sgSettings', 'Account', 'Mailbox', 'User', 'Preferences', 'stateAccounts'];
|
||||
function MailboxesController($state, $timeout, $mdDialog, focus, encodeUriFilter, Dialog, Settings, Account, Mailbox, User, Preferences, stateAccounts) {
|
||||
var vm = this,
|
||||
account,
|
||||
mailbox;
|
||||
@@ -28,6 +28,7 @@
|
||||
vm.share = share;
|
||||
vm.metadataForFolder = metadataForFolder;
|
||||
vm.setFolderAs = setFolderAs;
|
||||
vm.refreshUnseenCount = refreshUnseenCount;
|
||||
|
||||
if ($state.current.name == 'mail' && vm.accounts.length > 0 && vm.accounts[0].$mailboxes.length > 0) {
|
||||
// Redirect to first mailbox of first account if no mailbox is selected
|
||||
@@ -221,6 +222,40 @@
|
||||
Dialog.alert(l('Warning'), error);
|
||||
});
|
||||
}
|
||||
|
||||
function refreshUnseenCount() {
|
||||
var unseenCountFolders = window.unseenCountFolders;
|
||||
|
||||
_.forEach(vm.accounts, function(account) {
|
||||
|
||||
// Always include the INBOX
|
||||
if (!_.includes(unseenCountFolders, account.id + '/folderINBOX'))
|
||||
unseenCountFolders.push(account.id + '/folderINBOX');
|
||||
|
||||
_.forEach(account.$mailboxes, function(mailbox) {
|
||||
if (angular.isDefined(mailbox.unseenCount) &&
|
||||
!_.includes(unseenCountFolders, mailbox.id))
|
||||
unseenCountFolders.push(mailbox.id);
|
||||
});
|
||||
});
|
||||
|
||||
Account.$$resource.post('', 'unseenCount', {mailboxes: unseenCountFolders}).then(function(data) {
|
||||
_.forEach(vm.accounts, function(account) {
|
||||
_.forEach(account.$mailboxes, function(mailbox) {
|
||||
if (data[mailbox.id])
|
||||
mailbox.unseenCount = data[mailbox.id];
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Preferences.ready().then(function() {
|
||||
var refreshViewCheck = Preferences.defaults.SOGoRefreshViewCheck;
|
||||
if (refreshViewCheck && refreshViewCheck != 'manually')
|
||||
$timeout(vm.refreshUnseenCount, refreshViewCheck.timeInterval()*1000);
|
||||
});
|
||||
}
|
||||
|
||||
vm.refreshUnseenCount();
|
||||
}
|
||||
|
||||
angular
|
||||
|
||||
Reference in New Issue
Block a user