Skip to content

Commit

Permalink
feature(contact): Show 100 first results for global address book
Browse files Browse the repository at this point in the history
  • Loading branch information
WoodySlum committed Dec 18, 2023
1 parent 26c7462 commit 17eca6f
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 29 deletions.
5 changes: 5 additions & 0 deletions Documentation/SOGoInstallationGuide.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,11 @@ specified as an array of dictionaries.
|D |SOGoCreateIdentitiesDisabled
|Disable identity creation for users in preferences. If `YES`, users won't be able to add new identities and will allow to change only full name, signature and default identity. Default value is `NO`. Note : If this settings is set to `YES`, it will not be possible to crete auxiliary mail accounts.
|S |SOGoGlobalAddressBookFirstEntries
|Display first entries in Global Address Book. Default value is `NO`. If source is LDAP, the LDAP overlay `sssvlv` must be enabled on the system for server side sorting.
|S |SOGoGlobalAddressBookFirstEntriesCount
|Number of entries displayed when `SOGoGlobalAddressBookFirstEntries` is enabled. Default value is `100`.
|=======================================================================
Expand Down
45 changes: 31 additions & 14 deletions SoObjects/Contacts/SOGoContactSourceFolder.m
Original file line number Diff line number Diff line change
Expand Up @@ -434,26 +434,43 @@ - (NSArray *) lookupContactsWithFilter: (NSString *) filter
{
NSArray *records, *result;
EOSortOrdering *ordering;
BOOL processed;

result = nil;
processed = NO;

if ([filter length] > 0 || ![source listRequiresDot])
[source setListRequiresDot: NO];
if ( ![source listRequiresDot])
{
records = [source fetchContactsMatching: filter
if ([filter length] > 0) {
records = [source fetchContactsMatching: filter
withCriteria: criteria
inDomain: domain];
[childRecords setObjects: records
forKeys: [records objectsForKey: @"c_name"
notFoundMarker: nil]];
records = [self _flattenedRecords: records];
ordering
= [EOSortOrdering sortOrderingWithKey: sortKey
selector: ((sortOrdering == NSOrderedDescending)
? EOCompareCaseInsensitiveDescending
: EOCompareCaseInsensitiveAscending)];
result
= [records sortedArrayUsingKeyOrderArray:
[NSArray arrayWithObject: ordering]];
processed = YES;
} else if ([[SOGoSystemDefaults sharedSystemDefaults] globalAddressBookFirstEntriesEnabled]) {
records = [source fetchContactsMatching: filter
withCriteria: criteria
inDomain: domain
limit: [[SOGoSystemDefaults sharedSystemDefaults] globalAddressBookFirstEntriesCount]];
processed = YES;
}

if (processed) {
[childRecords setObjects: records
forKeys: [records objectsForKey: @"c_name"
notFoundMarker: nil]];
records = [self _flattenedRecords: records];
ordering
= [EOSortOrdering sortOrderingWithKey: sortKey
selector: ((sortOrdering == NSOrderedDescending)
? EOCompareCaseInsensitiveDescending
: EOCompareCaseInsensitiveAscending)];
result
= [records sortedArrayUsingKeyOrderArray:
[NSArray arrayWithObject: ordering]];
}


}

return result;
Expand Down
73 changes: 60 additions & 13 deletions SoObjects/SOGo/LDAPSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,21 @@ - (NSDictionary *) _convertLDAPEntryToContact: (NGLdapEntry *) ldapEntry
- (NSArray *) fetchContactsMatching: (NSString *) match
withCriteria: (NSArray *) criteria
inDomain: (NSString *) theDomain
{
if ([match length] > 0) {
return [self fetchContactsMatching: (NSString *) match
withCriteria: (NSArray *) criteria
inDomain: (NSString *) theDomain
limit: -1];
} else {
return [NSMutableArray array];
}
}

- (NSArray *) fetchContactsMatching: (NSString *) match
withCriteria: (NSArray *) criteria
inDomain: (NSString *) theDomain
limit: (int) limit
{
NSAutoreleasePool *pool;
NGLdapConnection *ldapConnection;
Expand All @@ -1392,26 +1407,58 @@ - (NSArray *) fetchContactsMatching: (NSString *) match
NSMutableArray *contacts;
EOQualifier *qualifier;
unsigned int i;
NSString *sortAttribute;
BOOL sortReverse;

contacts = [NSMutableArray array];

if ([match length] > 0 || !_listRequiresDot)
if (!_listRequiresDot)
{
ldapConnection = [self _ldapConnection];
qualifier = [self _qualifierForFilter: match onCriteria: criteria];

if ([_scope caseInsensitiveCompare: @"BASE"] == NSOrderedSame)
entries = [ldapConnection baseSearchAtBaseDN: _baseDN
qualifier: qualifier
attributes: _lookupFields];
else if ([_scope caseInsensitiveCompare: @"ONE"] == NSOrderedSame)
entries = [ldapConnection flatSearchAtBaseDN: _baseDN
qualifier: qualifier
attributes: _lookupFields];
else /* we do it like before */
entries = [ldapConnection deepSearchAtBaseDN: _baseDN
qualifier: qualifier
attributes: _lookupFields];
if (limit > 0) {
[ldapConnection setQuerySizeLimit: limit];
}

if (limit > 0) {
// Sort results
sortAttribute = @"cn";
sortReverse = NO;
if ([_scope caseInsensitiveCompare: @"BASE"] == NSOrderedSame)
entries = [ldapConnection baseSearchAtBaseDN: _baseDN
qualifier: qualifier
attributes: _lookupFields
sortAttribute: sortAttribute
sortReverse: sortReverse];
else if ([_scope caseInsensitiveCompare: @"ONE"] == NSOrderedSame)
entries = [ldapConnection flatSearchAtBaseDN: _baseDN
qualifier: qualifier
attributes: _lookupFields
sortAttribute: sortAttribute
sortReverse: sortReverse];
else /* we do it like before */
entries = [ldapConnection deepSearchAtBaseDN: _baseDN
qualifier: qualifier
attributes: _lookupFields
sortAttribute: sortAttribute
sortReverse: sortReverse];
} else {
// No sort results
if ([_scope caseInsensitiveCompare: @"BASE"] == NSOrderedSame)
entries = [ldapConnection baseSearchAtBaseDN: _baseDN
qualifier: qualifier
attributes: _lookupFields];
else if ([_scope caseInsensitiveCompare: @"ONE"] == NSOrderedSame)
entries = [ldapConnection flatSearchAtBaseDN: _baseDN
qualifier: qualifier
attributes: _lookupFields];
else /* we do it like before */
entries = [ldapConnection deepSearchAtBaseDN: _baseDN
qualifier: qualifier
attributes: _lookupFields];
}


i = 0;
pool = [NSAutoreleasePool new];
Expand Down
5 changes: 5 additions & 0 deletions SoObjects/SOGo/SOGoSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@
- (NSArray *) fetchContactsMatching: (NSString *) filter
withCriteria: (NSArray *) criteria
inDomain: (NSString *) domain;
- (NSArray *)fetchContactsMatching:(NSString *)filter
withCriteria:(NSArray *)criteria
inDomain:(NSString *)domain
limit:(int)limit;

- (NSArray *) lookupContactsWithQualifier: (EOQualifier *) qualifier
andSortOrdering: (EOSortOrdering *) ordering
inDomain: (NSString *) domain;
Expand Down
3 changes: 3 additions & 0 deletions SoObjects/SOGo/SOGoSystemDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ NSComparisonResult languageSort(id el1, id el2, void *context);
- (NSArray *) disableSharingAnyAuthUser;
- (NSArray *) disableExport;

- (BOOL) enableGlobalAddressBookFirstEntries;
- (int) globalAddressBookFirstEntriesCount;

@end

#endif /* SOGOSYSTEMDEFAULTS_H */
19 changes: 19 additions & 0 deletions SoObjects/SOGo/SOGoSystemDefaults.m
Original file line number Diff line number Diff line change
Expand Up @@ -845,4 +845,23 @@ - (NSArray *) disableExport
return disableExport;
}

- (BOOL) globalAddressBookFirstEntriesEnabled
{
return [self boolForKey: @"SOGoGlobalAddressBookFirstEntries"];
}

- (int) globalAddressBookFirstEntriesCount
{
int v;

v = [self integerForKey: @"SOGoGlobalAddressBookFirstEntriesCount"];

if (!v)
v = 100;

return v;
}



@end
20 changes: 19 additions & 1 deletion SoObjects/SOGo/SQLSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,22 @@ - (NSArray *) allEntryIDs
- (NSArray *) fetchContactsMatching: (NSString *) filter
withCriteria: (NSArray *) criteria
inDomain: (NSString *) domain

{
if ([filter length] > 0) {
return [self fetchContactsMatching: (NSString *) filter
withCriteria: (NSArray *) criteria
inDomain: (NSString *) domain
limit: -1];
} else {
return [NSMutableArray array];
}
}

- (NSArray *)fetchContactsMatching: (NSString *)filter
withCriteria: (NSArray *)criteria
inDomain: (NSString *)domain
limit: (int)limit
{
EOAdaptorChannel *channel;
NSEnumerator *criteriaList;
Expand All @@ -935,7 +951,7 @@ - (NSArray *) fetchContactsMatching: (NSString *) filter

results = [NSMutableArray array];

if ([filter length] > 0 || !_listRequiresDot)
if (!_listRequiresDot)
{
cm = [GCSChannelManager defaultChannelManager];
channel = [cm acquireOpenChannelForURL: _viewURL];
Expand Down Expand Up @@ -994,6 +1010,8 @@ - (NSArray *) fetchContactsMatching: (NSString *) filter
[sql appendFormat: @" AND %@ IS NULL", _domainField];
}

if (limit > 0)
[sql appendFormat: @" ORDER BY c_cn ASC LIMIT %i", limit];
ex = [channel evaluateExpressionX: sql];
if (!ex)
{
Expand Down
3 changes: 2 additions & 1 deletion UI/Templates/ContactsUI/UIxContactFoldersView.wox
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@
<!-- Remote/domain addressbooks -->
<section>
<md-subheader class="sg-md-subheader--with-secondary-icon"
md-colors="::{background: 'default-background-300'}">
md-colors="::{background: 'default-background-300'}"
ng-if="app.service.$remotes.length > 0">
<var:string label:value="Global Addressbooks"/>
</md-subheader>
<md-list>
Expand Down

0 comments on commit 17eca6f

Please sign in to comment.