diff --git a/NEWS b/NEWS index fd7da7661..7a596a0c7 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,7 @@ Bug fixes - SmartReply improvements for missing body attributes - do not use syncKey from cache when davCollectionTag = -1 - use correct mail attachment elements for EAS 2.5 clients + - fixed contacts lookup by UID in freebusy 2.2.16 (2015-02-12) ------------------- diff --git a/SoObjects/Appointments/SOGoFreeBusyObject.m b/SoObjects/Appointments/SOGoFreeBusyObject.m index 6624a2cfe..ff8ee6263 100644 --- a/SoObjects/Appointments/SOGoFreeBusyObject.m +++ b/SoObjects/Appointments/SOGoFreeBusyObject.m @@ -62,17 +62,14 @@ SOGoUserManager *um; NSString *domain; NSDictionary *contactInfos; - NSArray *contacts; um = [SOGoUserManager sharedUserManager]; contactInfos = [um contactInfosForUserWithUIDorEmail: uid]; if (contactInfos == nil) { + // Search among global addressbooks domain = [[context activeUser] domain]; - [um fetchContactsMatching: uid inDomain: domain]; - contacts = [um fetchContactsMatching: uid inDomain: domain]; - if ([contacts count] == 1) - contactInfos = [contacts lastObject]; + contactInfos = [um fetchContactWithUID: uid inDomain: domain]; } /* iCal.app compatibility: @@ -279,7 +276,6 @@ if ([uid length]) { SOGoUserManager *um; - NSArray *contacts; NSString *domain, *email; NSDictionary *contact; MSExchangeFreeBusy *exchangeFreeBusy; @@ -287,10 +283,9 @@ um = [SOGoUserManager sharedUserManager]; domain = [[context activeUser] domain]; - contacts = [um fetchContactsMatching: uid inDomain: domain]; - if ([contacts count] == 1) + contact = [um fetchContactWithUID: uid inDomain: domain]; + if (contact) { - contact = [contacts lastObject]; email = [contact valueForKey: @"c_email"]; source = [contact objectForKey: @"source"]; if ([email length] diff --git a/SoObjects/SOGo/SOGoUserManager.h b/SoObjects/SOGo/SOGoUserManager.h index 237347053..d30821108 100644 --- a/SoObjects/SOGo/SOGoUserManager.h +++ b/SoObjects/SOGo/SOGoUserManager.h @@ -65,10 +65,13 @@ - (NSDictionary *) contactInfosForUserWithUIDorEmail: (NSString *) uid; - (NSDictionary *) contactInfosForUserWithUIDorEmail: (NSString *) uid inDomain: (NSString *) domain; +- (NSDictionary *) fetchContactWithUID: (NSString *) uid + inDomain: (NSString *) domain; - (NSArray *) fetchContactsMatching: (NSString *) match inDomain: (NSString *) domain; - (NSArray *) fetchUsersMatching: (NSString *) filter inDomain: (NSString *) domain; +- (NSArray *) _compactAndCompleteContacts: (NSEnumerator *) contacts; - (NSString *) getCNForUID: (NSString *) uid; - (NSString *) getEmailForUID: (NSString *) uid; diff --git a/SoObjects/SOGo/SOGoUserManager.m b/SoObjects/SOGo/SOGoUserManager.m index de7c7296c..0c6280112 100644 --- a/SoObjects/SOGo/SOGoUserManager.m +++ b/SoObjects/SOGo/SOGoUserManager.m @@ -915,6 +915,28 @@ static Class NSNullK; return currentUser; } +/** + * Fetch the contact information identified by the specified UID in the global addressbooks. + */ +- (NSDictionary *) fetchContactWithUID: (NSString *) uid + inDomain: (NSString *) domain +{ + NSMutableArray *contacts; + NSEnumerator *sources; + NSString *sourceID; + id currentSource; + + contacts = [NSMutableArray array]; + sources = [[self addressBookSourceIDsInDomain: domain] objectEnumerator]; + while ((sourceID = [sources nextObject])) + { + currentSource = [_sources objectForKey: sourceID]; + [contacts addObject: [currentSource lookupContactEntry: uid]]; + } + + return [[self _compactAndCompleteContacts: [contacts objectEnumerator]] lastObject]; +} + - (NSArray *) _compactAndCompleteContacts: (NSEnumerator *) contacts { NSMutableDictionary *compactContacts, *returnContact;