From ec7199e00f435b9084a12f49194ac60e33135d94 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Wed, 23 Mar 2022 12:00:52 -0400 Subject: [PATCH] fix(addressbook): keep folders order in matching contacts This will ensure sources (LDAP/SQL) entries are returned first. --- SoObjects/Contacts/SOGoContactFolders.m | 30 ++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/SoObjects/Contacts/SOGoContactFolders.m b/SoObjects/Contacts/SOGoContactFolders.m index df9a237ae..1cff4682f 100644 --- a/SoObjects/Contacts/SOGoContactFolders.m +++ b/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 @@ -423,7 +423,7 @@ Class SOGoContactSourceFolderK; { NSArray *folders, *contacts, *descriptors, *sortedContacts; NSMutableDictionary *contact, *uniqueContacts; - NSMutableArray *sortedFolders; + NSMutableArray *sortedFolders, *allContacts; SOGoFolder *folder; NSString *mail, *domain; @@ -432,6 +432,10 @@ Class SOGoContactSourceFolderK; domain = [[context activeUser] domain]; folders = nil; + commonNameDescriptor = [[NSSortDescriptor alloc] initWithKey: @"c_cn" + ascending: YES]; + descriptors = [NSArray arrayWithObjects: commonNameDescriptor, nil]; + [commonNameDescriptor release]; NS_DURING { @@ -451,7 +455,7 @@ Class SOGoContactSourceFolderK; max = [folders count]; sortedFolders = [NSMutableArray arrayWithCapacity: max]; - uniqueContacts = [NSMutableDictionary dictionary]; + allContacts = [NSMutableArray array]; for (i = 0; i < max; i++) { @@ -471,6 +475,7 @@ Class SOGoContactSourceFolderK; sortBy: @"c_cn" ordering: NSOrderedAscending inDomain: domain]; + uniqueContacts = [NSMutableDictionary dictionary]; for (j = 0; j < [contacts count]; j++) { contact = [contacts objectAtIndex: j]; @@ -487,20 +492,15 @@ Class SOGoContactSourceFolderK; && !(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) contactForEmail: (NSString *) theEmail