Skip to content

Commit

Permalink
fix(addressbook): keep folders order in matching contacts
Browse files Browse the repository at this point in the history
This will ensure sources (LDAP/SQL) entries are returned first.
  • Loading branch information
cgx committed Mar 23, 2022
1 parent b37e68b commit ec7199e
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions SoObjects/Contacts/SOGoContactFolders.m
@@ -1,6 +1,6 @@
/* SOGoContactFolders.m - this file is part of SOGo
*
* Copyright (C) 2006-2017 Inverse inc.
* Copyright (C) 2006-2022 Inverse inc.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -423,7 +423,7 @@ - (NSArray *) allContactsFromFilter: (NSString *) theFilter
{
NSArray *folders, *contacts, *descriptors, *sortedContacts;
NSMutableDictionary *contact, *uniqueContacts;
NSMutableArray *sortedFolders;
NSMutableArray *sortedFolders, *allContacts;
SOGoFolder <SOGoContactFolder> *folder;
NSString *mail, *domain;

Expand All @@ -432,6 +432,10 @@ - (NSArray *) allContactsFromFilter: (NSString *) theFilter

domain = [[context activeUser] domain];
folders = nil;
commonNameDescriptor = [[NSSortDescriptor alloc] initWithKey: @"c_cn"
ascending: YES];
descriptors = [NSArray arrayWithObjects: commonNameDescriptor, nil];
[commonNameDescriptor release];

NS_DURING
{
Expand All @@ -451,7 +455,7 @@ - (NSArray *) allContactsFromFilter: (NSString *) theFilter

max = [folders count];
sortedFolders = [NSMutableArray arrayWithCapacity: max];
uniqueContacts = [NSMutableDictionary dictionary];
allContacts = [NSMutableArray array];

for (i = 0; i < max; i++)
{
Expand All @@ -471,6 +475,7 @@ - (NSArray *) allContactsFromFilter: (NSString *) theFilter
sortBy: @"c_cn"
ordering: NSOrderedAscending
inDomain: domain];
uniqueContacts = [NSMutableDictionary dictionary];
for (j = 0; j < [contacts count]; j++)
{
contact = [contacts objectAtIndex: j];
Expand All @@ -487,20 +492,15 @@ - (NSArray *) allContactsFromFilter: (NSString *) theFilter
&& !(excludeGroups && [contact objectForKey: @"isGroup"]))
[uniqueContacts setObject: contact forKey: mail];
}
if ([uniqueContacts count] > 0)
{
// Sort the matching contacts by display name for the current folder
sortedContacts = [[uniqueContacts allValues] sortedArrayUsingDescriptors: descriptors];
[allContacts addObjectsFromArray: sortedContacts];
}
}
if ([uniqueContacts count] > 0)
{
// Sort the contacts by display name
commonNameDescriptor = [[NSSortDescriptor alloc] initWithKey: @"c_cn"
ascending: YES];
descriptors = [NSArray arrayWithObjects: commonNameDescriptor, nil];
[commonNameDescriptor release];
sortedContacts = [[uniqueContacts allValues] sortedArrayUsingDescriptors: descriptors];
}
else
sortedContacts = [NSArray array];

return sortedContacts;
return allContacts;
}

- (id<SOGoContactObject>) contactForEmail: (NSString *) theEmail
Expand Down

0 comments on commit ec7199e

Please sign in to comment.