Skip to content

Commit

Permalink
feat(addressbook): Add global address book autocomplete on vlist
Browse files Browse the repository at this point in the history
  • Loading branch information
WoodySlum committed Nov 8, 2023
1 parent 0560efd commit 0b1f2b0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
19 changes: 16 additions & 3 deletions UI/Contacts/UIxContactsListActions.m
Expand Up @@ -189,14 +189,26 @@ - (NSArray *) contactInfos
}
}

// Flatten email for global address book instead of array
// Process for global address book instead of array
if (globalAddressBookResults) {
for (i = 0 ; i < [globalAddressBookResults count] ; i++) {
tmpDict = [NSMutableDictionary dictionaryWithDictionary: [globalAddressBookResults objectAtIndex: i]];
if ([tmpDict objectForKey: @"c_mail"] && [[tmpDict objectForKey: @"c_mail"] isKindOfClass:[NSArray class]] && [[tmpDict objectForKey: @"c_mail"] count] > 0) {
[tmpDict setObject:[[tmpDict objectForKey: @"c_mail"] componentsJoinedByString: @","] forKey:@"c_mail"];
[globalAddressBookResults replaceObjectAtIndex:i withObject: tmpDict];
// Flatten emails
[tmpDict setObject:[[tmpDict objectForKey: @"c_mail"] componentsJoinedByString: @","] forKey:@"c_mail"];
}

if ((![tmpDict objectForKey:@"c_cn"] || [tmpDict objectForKey:@"c_cn"] == [NSNull null]) && [tmpDict objectForKey:@"c_name"]) {
// Replace c_cn if not filled
[tmpDict setObject:[tmpDict objectForKey:@"c_name"] forKey:@"c_cn"];
}

if ((![tmpDict objectForKey:@"c_uid"] || [tmpDict objectForKey:@"c_uid"] == [NSNull null]) && [tmpDict objectForKey:@"c_id"]) {
// Replace c_uid if not filled
[tmpDict setObject:[tmpDict objectForKey:@"c_uid"] forKey:@"c_id"];
}

[globalAddressBookResults replaceObjectAtIndex:i withObject: tmpDict];
}
}

Expand All @@ -211,6 +223,7 @@ - (NSArray *) contactInfos
// Add sourceid for current AB
for (i = 0 ; i < [results count] ; i++) {
tmpDict = [NSMutableDictionary dictionaryWithDictionary: [results objectAtIndex: i]];
// Add sourceid
[tmpDict setObject:[folder nameInContainer] forKey:@"sourceid"];
[results replaceObjectAtIndex:i withObject: tmpDict];
}
Expand Down
19 changes: 17 additions & 2 deletions UI/Contacts/UIxListEditor.m
Expand Up @@ -35,6 +35,8 @@
#import <SOGo/NSDictionary+Utilities.h>
#import <SOGo/NSString+Utilities.h>

#import <SoObjects/Contacts/SOGoContactSourceFolder.h>

#import <Contacts/SOGoContactGCSEntry.h>
#import <Contacts/SOGoContactGCSFolder.h>

Expand Down Expand Up @@ -173,12 +175,14 @@ - (void) setReferences: (NSArray *) references
{
NSAutoreleasePool *pool;
NSDictionary *values;
NSArray *initialReferences, *refs, *emails;
NSArray *initialReferences, *refs, *emails, *folders;
NSDictionary *currentReference;
NSString *uid, *workMail, *fn, *newUID;
int i, count;
NGVCardReference *cardReference;
SOGoContactGCSFolder *folder;
NSMutableArray *publicSourceIDs;
id f;

folder = [co container];

Expand All @@ -200,6 +204,15 @@ - (void) setReferences: (NSArray *) references
count = [references count];
pool = [[NSAutoreleasePool alloc] init];

// List container name of global AB
folders = [[[co lookupUserFolder] privateContacts: @"Contacts" inContext: nil] subFolders];
publicSourceIDs = [[NSMutableArray alloc] init];
for (f in folders) {
if ([f isKindOfClass:[SOGoContactSourceFolder class]]) {
[publicSourceIDs addObject: [f nameInContainer]];
}
}


for (i = 0; i < count; i++)
{
Expand All @@ -226,7 +239,7 @@ - (void) setReferences: (NSArray *) references

[list addCardReference: cardReference];
}
else if ([currentReference objectForKey:@"sourceid"] && [[currentReference objectForKey:@"sourceid"] isEqualToString: @"public"]) {
else if ([currentReference objectForKey:@"sourceid"] && [publicSourceIDs containsObject:[currentReference objectForKey:@"sourceid"]]) {
// Create reference for shared AB (public)
uid = [currentReference objectForKey: @"id"];
emails = [[currentReference objectForKey: @"c_mail"] componentsSeparatedByString: @","];
Expand Down Expand Up @@ -278,6 +291,8 @@ - (void) setReferences: (NSArray *) references
pool = [[NSAutoreleasePool alloc] init];
}
}

[publicSourceIDs release];
}

- (BOOL) cardReferences: (NSArray *) references
Expand Down

0 comments on commit 0b1f2b0

Please sign in to comment.