From 40d269c504309ab9e9108a799663266f8355fcbe Mon Sep 17 00:00:00 2001
From: Ludovic Marcotte
Date: Fri, 31 Jul 2015 13:32:14 -0400
Subject: [PATCH] (feat) unseen count support folder all accounts/mailboxes
---
UI/MailerUI/UIxMailFolderActions.m | 48 -------------
UI/MailerUI/UIxMailMainFrame.m | 71 ++++++++++++++++++-
UI/MailerUI/product.plist | 10 +--
UI/Templates/MailerUI/UIxMailMainFrame.wox | 5 +-
.../js/Mailer/Mailbox.service.js | 3 +
.../js/Mailer/MailboxesController.js | 39 +++++++++-
6 files changed, 119 insertions(+), 57 deletions(-)
diff --git a/UI/MailerUI/UIxMailFolderActions.m b/UI/MailerUI/UIxMailFolderActions.m
index c324a18ca..6184931f0 100644
--- a/UI/MailerUI/UIxMailFolderActions.m
+++ b/UI/MailerUI/UIxMailFolderActions.m
@@ -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;
diff --git a/UI/MailerUI/UIxMailMainFrame.m b/UI/MailerUI/UIxMailMainFrame.m
index 6e22e4e6b..7bd027606 100644
--- a/UI/MailerUI/UIxMailMainFrame.m
+++ b/UI/MailerUI/UIxMailMainFrame.m
@@ -33,6 +33,9 @@
#import
#import
#import
+#import
+#import
+#import
#import
#import
@@ -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]];
}
}
}
diff --git a/UI/MailerUI/product.plist b/UI/MailerUI/product.plist
index 8cfe30d7d..24ab2aacb 100644
--- a/UI/MailerUI/product.plist
+++ b/UI/MailerUI/product.plist
@@ -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";
diff --git a/UI/Templates/MailerUI/UIxMailMainFrame.wox b/UI/Templates/MailerUI/UIxMailMainFrame.wox
index 80b64c245..1f9af989b 100644
--- a/UI/Templates/MailerUI/UIxMailMainFrame.wox
+++ b/UI/Templates/MailerUI/UIxMailMainFrame.wox
@@ -258,7 +258,10 @@
ui-sref-active="sg-active">
{{app.metadataForFolder(folder).icon}}
{{app.metadataForFolder(folder).name}}
+ ng-show="app.editMode != folder.path">
+ {{app.metadataForFolder(folder).name}}
+ ({{folder.unseenCount}})
+
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