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 d163405 commit 0560efd
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 19 deletions.
3 changes: 3 additions & 0 deletions SoObjects/Contacts/SOGoContactGCSFolder.m
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ - (void) fixupContactRecord: (NSMutableDictionary *) contactRecord
if ([data length])
[contactRecord setObject: data forKey: @"id"];

// Container name
[contactRecord setObject: [self displayName] forKey: @"containerName"];

// c_cn
data = [contactRecord objectForKey: @"c_cn"];
if (![data length])
Expand Down
4 changes: 4 additions & 0 deletions SoObjects/Contacts/SOGoContactSourceFolder.m
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ - (NSDictionary *) _flattenedRecord: (NSDictionary *) oldRecord
//source id
[newRecord setObject: [source sourceID] forKey: @"sourceID"];

//source display name
[newRecord setObject: [self displayName]
forKey: @"containerName"];

// c_name => id
[newRecord setObject: [oldRecord objectForKey: @"c_name"]
forKey: @"c_name"];
Expand Down
67 changes: 62 additions & 5 deletions UI/Contacts/UIxContactsListActions.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

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

#import "UIxContactsListActions.h"

Expand Down Expand Up @@ -140,17 +141,18 @@ - (NSArray *) contactInfos
{
id <SOGoContactFolder> folder;
NSString *ascending, *valueText;
NSArray *results, *searchFields, *fields;
NSMutableArray *filteredContacts, *headers;
NSArray *searchFields, *fields, *folders, *tmpGlobalAddressBookResults;
NSMutableArray *filteredContacts, *headers, *results, *globalAddressBookResults;
NSDictionary *data, *contact;
BOOL excludeLists;
NSComparisonResult ordering;
NSUInteger max, count;
unsigned int i;
NSSortDescriptor *descriptor;
NSMutableDictionary *tmpDict;

if (!contactInfos)
{
folder = [self clientObject];
data = [self requestData];

ascending = [data objectForKey: @"asc"];
Expand All @@ -167,11 +169,65 @@ - (NSArray *) contactInfos
excludeLists = [[data objectForKey: @"excludeLists"] boolValue];

[contactInfos release];
results = [folder lookupContactsWithFilter: valueText
onCriteria: searchFields

folders = [[[self clientObject] container] subFolders];

globalAddressBookResults = nil;
for (folder in folders) {
// Global AB
if ([folder isKindOfClass: [SOGoContactSourceFolder class]]) {
tmpGlobalAddressBookResults = [folder lookupContactsWithFilter: valueText
onCriteria: nil
sortBy: [self sortKey]
ordering: ordering
inDomain: [[context activeUser] domain]];
if (globalAddressBookResults) {
globalAddressBookResults = [globalAddressBookResults arrayByAddingObjectsFromArray: tmpGlobalAddressBookResults];
} else {
globalAddressBookResults = [NSMutableArray arrayWithArray: tmpGlobalAddressBookResults];
}
}
}

// Flatten email 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];
}
}
}

// Current AB
folder = [self clientObject];
results = [NSMutableArray arrayWithArray: [folder lookupContactsWithFilter: valueText
onCriteria: searchFields
sortBy: [self sortKey]
ordering: ordering
inDomain: [[context activeUser] domain]]];

// Add sourceid for current AB
for (i = 0 ; i < [results count] ; i++) {
tmpDict = [NSMutableDictionary dictionaryWithDictionary: [results objectAtIndex: i]];
[tmpDict setObject:[folder nameInContainer] forKey:@"sourceid"];
[results replaceObjectAtIndex:i withObject: tmpDict];
}

if (globalAddressBookResults && results) { // Both results, merge arrays
// Results in personal folder will appear first
results = [results arrayByAddingObjectsFromArray: globalAddressBookResults];
} else if (globalAddressBookResults) { // No results in personal AB
results = globalAddressBookResults;
}

// Sort the results
descriptor = [[NSSortDescriptor alloc] initWithKey: [self sortKey]
ascending: ordering];
results = [results sortedArrayUsingDescriptors: [NSArray arrayWithObjects: descriptor, nil]];
[descriptor release];

if (excludeLists)
{
filteredContacts = [NSMutableArray array];
Expand All @@ -198,6 +254,7 @@ - (NSArray *) contactInfos
count = 0;
fields = [[contactInfos objectAtIndex: 0] allKeys];
[headers addObject: fields];

while (count < max)
{
[headers addObject: [[contactInfos objectAtIndex: count] objectsForKeys: fields
Expand Down
18 changes: 16 additions & 2 deletions UI/Contacts/UIxListEditor.m
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,16 @@ - (void) setReferences: (NSArray *) references
count = [references count];
pool = [[NSAutoreleasePool alloc] init];


for (i = 0; i < count; i++)
{
if ([[references objectAtIndex: i] isKindOfClass: [NSDictionary class]])
{
currentReference = [references objectAtIndex: i];

uid = [currentReference objectForKey: @"id"];


if (![self cardReferences: [list cardReferences]
contain: uid])
{
Expand All @@ -222,8 +226,18 @@ - (void) setReferences: (NSArray *) references

[list addCardReference: cardReference];
}
else
{
else if ([currentReference objectForKey:@"sourceid"] && [[currentReference objectForKey:@"sourceid"] isEqualToString: @"public"]) {
// Create reference for shared AB (public)
uid = [currentReference objectForKey: @"id"];
emails = [[currentReference objectForKey: @"c_mail"] componentsSeparatedByString: @","];
cardReference = [NGVCardReference elementWithTag: @"card"];
[cardReference setFn: [currentReference objectForKey: @"c_cn"]];
if ([emails count])
[cardReference setEmail: [emails objectAtIndex: 0]];
[cardReference setReference: uid];

[list addCardReference: cardReference];
} else {
// Invalid UID or no UID
NGVCard *newCard;
CardElement *newWorkMail;
Expand Down
20 changes: 19 additions & 1 deletion UI/Contacts/UIxListView.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#import <SOGo/NSArray+Utilities.h>
#import <SOGo/NSDictionary+Utilities.h>

#import <SoObjects/Contacts/SOGoContactSourceFolder.h>

#import "UIxListView.h"

@implementation UIxListView
Expand All @@ -36,6 +38,7 @@ - (void) checkListReferences
NGVCardReference *card, *cardCopy;
int i, count;
id test;
NSArray *folders;

invalid = [NSMutableArray array];

Expand All @@ -46,7 +49,22 @@ - (void) checkListReferences
test = [[co container] lookupName: [card reference]
inContext: context
acquire: NO];
if ([test isKindOfClass: [NSException class]])
if ([test isKindOfClass: [NSException class]]) {
folders = [[[co lookupUserFolder] privateContacts: @"Contacts" inContext: nil] subFolders];
id <SOGoContactFolder> folder;
for (folder in folders) {
// Global AB
if ([folder isKindOfClass: [SOGoContactSourceFolder class]]) {
test = [folder lookupName: [card reference]
inContext: context
acquire: NO];
if (test && ![test isKindOfClass: [NSException class]]) break;
}
}
}


if (test && [test isKindOfClass: [NSException class]])
{
//NSLog (@"%@ not found", [card reference]);
cardCopy = [card copy];
Expand Down
42 changes: 31 additions & 11 deletions UI/Templates/ContactsUI/UIxContactEditorTemplate.wox
Original file line number Diff line number Diff line change
Expand Up @@ -468,17 +468,37 @@
<label class="pseudo-input-label">
<var:string label:value="Members"/>
</label>
<md-contact-chips
class="sg-chips-autocomplete"
ng-model="editor.card.refs"
ng-change="contactForm.$setDirty()"
md-contacts="editor.userFilter($query, editor.card.refs)"
md-contact-name="$$fullname"
md-contact-image="$$image"
md-contact-email="$$email"
md-require-match="true"
filter-selected="false"
label:placeholder="Add Member"><!-- members --></md-contact-chips>
<md-chips ng-model="editor.card.refs"
md-separator-keys="editor.recipientSeparatorKeys"
md-add-on-blur="true"
md-autocomplete-snap="width">
<md-autocomplete
class="md-flex"
ng-model="editor.card.refs"
sg-enter="contactForm.$setDirty()"
md-menu-class="md-2-line"
md-search-text="editor.searchText"
md-items="card in editor.userFilter(editor.searchText, editor.card.refs)"
md-item-text="card.empty"
md-autoselect="true"
var:md-min-length="2"
md-delay="150"
md-no-cache="true">
<md-item-template>
<div class="sg-tile-content">
<div class="sg-tile-content">
<div class="sg-md-subhead md-block" md-highlight-text="editor.searchText" md-highlight-flags="gi">{{ card.$shortFormat(editor.searchText) }}</div>
<div class="sg-md-body" md-colors="::{color: 'default-background-500'}">{{ card.containername }}</div>
</div>
</div>
</md-item-template>
</md-autocomplete>
<md-chip-template>
<div class="sg-tile-content">
{{$chip.c_cn}}
</div>
</md-chip-template>
</md-chips>
</div>
</div>
</form>
Expand Down

0 comments on commit 0560efd

Please sign in to comment.