Skip to content

Commit

Permalink
feat(mail): prioritize personnal address books in autocompletion
Browse files Browse the repository at this point in the history
  • Loading branch information
cgx committed Oct 18, 2021
1 parent e79b01e commit 8065091
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
26 changes: 21 additions & 5 deletions UI/Contacts/UIxContactFoldersView.m
Expand Up @@ -154,15 +154,16 @@ - (BOOL) hasContactSelectionButtons
NSMutableArray *sortedFolders;
NSMutableDictionary *contact, *uniqueContacts;
unsigned int i, j, max;
NSSortDescriptor *commonNameDescriptor;
BOOL excludeGroups, excludeLists;
NSSortDescriptor *containerTypeDescriptor, *commonNameDescriptor;
BOOL excludeGroups, excludeLists, priorityGcs;

searchText = [self queryParameterForKey: @"search"];
if ([searchText length] >= [self minimumSearchLength])
{
// NSLog(@"Search all contacts: %@", searchText);
excludeGroups = [[self queryParameterForKey: @"excludeGroups"] boolValue];
excludeLists = [[self queryParameterForKey: @"excludeLists"] boolValue];
priorityGcs = [[self queryParameterForKey: @"priority"] isEqualToString: @"gcs"];
domain = [[context activeUser] domain];
folders = nil;
NS_DURING
Expand All @@ -183,11 +184,13 @@ - (BOOL) hasContactSelectionButtons
{
folder = [folders objectAtIndex: i];
/* We first search in LDAP folders (in case of duplicated entries in GCS folders) */
if ([folder isKindOfClass: SOGoContactSourceFolderK])
if (([folder isKindOfClass: SOGoContactSourceFolderK] && !priorityGcs) ||
([folder isKindOfClass: SOGoGCSFolderK] && priorityGcs))
[sortedFolders insertObject: folder atIndex: 0];
else
[sortedFolders addObject: folder];
}
NSLog(@"sortedFolders = %@", sortedFolders);
for (i = 0; i < max; i++)
{
folder = [sortedFolders objectAtIndex: i];
Expand All @@ -202,6 +205,16 @@ - (BOOL) hasContactSelectionButtons
contact = [contacts objectAtIndex: j];
[contact setObject: [folder displayName]
forKey: @"containerName"];
if (priorityGcs)
{
// Add the container type for sorting
if ([folder isKindOfClass: SOGoContactSourceFolderK])
[contact setObject: @"source"
forKey: @"containerType"];
else
[contact setObject: @"gcs"
forKey: @"containerType"];
}
//NSLog(@" found %@ (%@) ? %@", [contact objectForKey: @"c_name"], mail,
// [contact description]);
if (!excludeLists && [[contact objectForKey: @"c_component"]
Expand All @@ -227,10 +240,13 @@ - (BOOL) hasContactSelectionButtons
}
if ([uniqueContacts count] > 0)
{
// Optionally return contacts from GCS address books first
containerTypeDescriptor = [[NSSortDescriptor alloc] initWithKey: @"containerType"
ascending: priorityGcs?YES:NO];
// Sort the contacts by display name
commonNameDescriptor = [[NSSortDescriptor alloc] initWithKey: @"c_cn"
ascending:YES];
descriptors = [NSArray arrayWithObjects: commonNameDescriptor, nil];
ascending: YES];
descriptors = [NSArray arrayWithObjects: containerTypeDescriptor, commonNameDescriptor, nil];
[commonNameDescriptor release];
sortedContacts = [[uniqueContacts allValues]
sortedArrayUsingDescriptors: descriptors];
Expand Down
7 changes: 3 additions & 4 deletions UI/WebServerResources/js/Mailer/MessageEditorController.js
Expand Up @@ -17,7 +17,6 @@
this.autosave = null;
this.autosaveDrafts = autosaveDrafts;
this.cancel = cancel;
this.contactFilter = contactFilter;
this.isFullscreen = false;
this.hideBcc = (stateMessage.editable.bcc.length === 0);
this.hideCc = (stateMessage.editable.cc.length === 0);
Expand Down Expand Up @@ -273,8 +272,8 @@
vm.isFullscreen = !vm.isFullscreen;
}

function contactFilter($query) {
return AddressBook.$filterAll($query).then(function(cards) {
this.contactFilter = function ($query) {
return AddressBook.$filterAll($query, [], {priority: 'gcs'}).then(function(cards) {
// Divide the matching cards by email addresses so the user can select
// the recipient address of her choice
var explodedCards = [];
Expand All @@ -288,7 +287,7 @@
return card.$$fullname + ' ' + card.$$email;
});
});
}
};

this.addRecipient = function (contact, field) {
var recipients, recipient, list, i, address;
Expand Down

0 comments on commit 8065091

Please sign in to comment.