2006-06-15 21:34:10 +02:00
|
|
|
/*
|
2016-02-20 05:19:07 +01:00
|
|
|
Copyright (C) 2006-2016 Inverse inc.
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2012-11-17 23:16:00 +01:00
|
|
|
This file is part of SOGo.
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2010-03-19 14:08:15 +01:00
|
|
|
SOGo is free software; you can redistribute it and/or modify it under
|
2006-06-15 21:34:10 +02:00
|
|
|
the terms of the GNU Lesser General Public License as published by the
|
|
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
later version.
|
|
|
|
|
2010-03-19 14:08:15 +01:00
|
|
|
SOGo is distributed in the hope that it will be useful, but WITHOUT ANY
|
2006-06-15 21:34:10 +02:00
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2010-03-19 14:08:15 +01:00
|
|
|
License along with SOGo; see the file COPYING. If not, write to the
|
2006-06-15 21:34:10 +02:00
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2009-08-24 22:26:52 +02:00
|
|
|
#import <Foundation/Foundation.h>
|
2016-02-20 05:19:07 +01:00
|
|
|
#import <Foundation/NSEnumerator.h>
|
|
|
|
|
2009-08-24 22:26:52 +02:00
|
|
|
#import <SoObjects/SOGo/NSArray+Utilities.h>
|
|
|
|
#import <SoObjects/SOGo/NSDictionary+Utilities.h>
|
|
|
|
#import <SoObjects/SOGo/NSString+Utilities.h>
|
2014-11-25 15:36:24 +01:00
|
|
|
#import <SoObjects/SOGo/SOGoSystemDefaults.h>
|
2009-08-24 22:26:52 +02:00
|
|
|
|
|
|
|
#import <NGObjWeb/NSException+HTTP.h>
|
2012-02-11 08:08:02 +01:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
2007-03-21 15:28:42 +01:00
|
|
|
#import <NGObjWeb/WOResponse.h>
|
2009-09-03 16:18:13 +02:00
|
|
|
#import <NGObjWeb/WORequest.h>
|
2007-08-20 21:12:50 +02:00
|
|
|
#import <NGExtensions/NSString+misc.h>
|
2009-08-25 19:51:20 +02:00
|
|
|
#import <NGExtensions/NSNull+misc.h>
|
2007-03-21 15:28:42 +01:00
|
|
|
|
2016-02-20 05:19:07 +01:00
|
|
|
#import <EOControl/EOQualifier.h>
|
|
|
|
#import <EOControl/EOSortOrdering.h>
|
|
|
|
|
2015-08-14 21:11:07 +02:00
|
|
|
#import <SOGo/SOGoUser.h>
|
2015-08-12 20:34:32 +02:00
|
|
|
#import <SOGo/SOGoUserSettings.h>
|
|
|
|
|
2009-09-02 15:24:02 +02:00
|
|
|
#import <SoObjects/Contacts/SOGoContactGCSEntry.h>
|
2009-09-03 16:18:13 +02:00
|
|
|
#import <SoObjects/Contacts/SOGoContactGCSFolder.h>
|
2009-09-02 15:24:02 +02:00
|
|
|
|
2011-04-14 20:01:02 +02:00
|
|
|
#import "UIxContactsListActions.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2016-02-20 05:19:07 +01:00
|
|
|
// The maximum number of headers to prefetch when querying the IDs list
|
|
|
|
#define headersPrefetchMaxSize 100
|
|
|
|
|
2011-04-14 20:01:02 +02:00
|
|
|
@implementation UIxContactsListActions
|
2006-10-04 00:04:48 +02:00
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
2016-02-20 05:19:07 +01:00
|
|
|
{
|
|
|
|
contactInfos = nil;
|
|
|
|
sortedIDs = nil;
|
|
|
|
}
|
2009-07-17 23:25:38 +02:00
|
|
|
|
2006-10-04 00:04:48 +02:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2007-07-20 22:22:16 +02:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[contactInfos release];
|
2016-02-20 05:19:07 +01:00
|
|
|
[sortedIDs release];
|
2007-07-20 22:22:16 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2006-10-04 00:04:48 +02:00
|
|
|
/* accessors */
|
|
|
|
|
|
|
|
- (NSString *) defaultSortKey
|
|
|
|
{
|
2009-02-19 23:21:47 +01:00
|
|
|
return @"c_cn";
|
2006-10-04 00:04:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) sortKey
|
|
|
|
{
|
|
|
|
NSString *s;
|
2011-04-14 20:01:02 +02:00
|
|
|
WORequest *rq;
|
2006-10-04 00:04:48 +02:00
|
|
|
|
2011-04-14 20:01:02 +02:00
|
|
|
rq = [context request];
|
|
|
|
s = [rq formValueForKey: @"sort"];
|
2007-06-28 22:37:27 +02:00
|
|
|
if (![s length])
|
2006-10-04 00:04:48 +02:00
|
|
|
s = [self defaultSortKey];
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2015-08-14 21:11:07 +02:00
|
|
|
- (void) saveSortValue
|
|
|
|
{
|
2015-08-12 20:34:32 +02:00
|
|
|
NSMutableDictionary *contactSettings;
|
2015-08-14 21:11:07 +02:00
|
|
|
NSString *ascending, *sort;
|
|
|
|
SOGoUserSettings *us;
|
|
|
|
|
|
|
|
sort = [[context request] formValueForKey: @"sort"];
|
2015-08-12 20:34:32 +02:00
|
|
|
ascending = [[context request] formValueForKey: @"asc"];
|
2015-08-14 21:11:07 +02:00
|
|
|
|
2015-08-12 20:34:32 +02:00
|
|
|
if ([sort length])
|
|
|
|
{
|
2015-08-14 21:11:07 +02:00
|
|
|
us = [[context activeUser] userSettings];
|
|
|
|
contactSettings = [us objectForKey: @"Contact"];
|
|
|
|
// Must create if it doesn't exist
|
|
|
|
if (!contactSettings)
|
|
|
|
{
|
|
|
|
contactSettings = [NSMutableDictionary dictionary];
|
|
|
|
[us setObject: contactSettings forKey: @"Contact"];
|
|
|
|
}
|
|
|
|
[contactSettings setObject: [NSArray arrayWithObjects: [sort lowercaseString], [NSString stringWithFormat: @"%d", [ascending intValue]], nil]
|
2016-02-20 05:19:07 +01:00
|
|
|
forKey: @"SortingState"];
|
2015-08-14 21:11:07 +02:00
|
|
|
[us synchronize];
|
2015-08-12 20:34:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-04 00:04:48 +02:00
|
|
|
- (NSArray *) contactInfos
|
|
|
|
{
|
|
|
|
id <SOGoContactFolder> folder;
|
2007-06-28 22:37:27 +02:00
|
|
|
NSString *ascending, *searchText, *valueText;
|
2016-02-20 05:19:07 +01:00
|
|
|
NSArray *results, *fields;
|
|
|
|
NSMutableArray *filteredContacts, *headers;
|
2014-09-05 21:12:05 +02:00
|
|
|
NSDictionary *contact;
|
|
|
|
BOOL excludeLists;
|
2007-06-28 22:37:27 +02:00
|
|
|
NSComparisonResult ordering;
|
2016-02-20 05:19:07 +01:00
|
|
|
NSUInteger max, count;
|
2011-04-14 20:01:02 +02:00
|
|
|
WORequest *rq;
|
2014-09-05 21:12:05 +02:00
|
|
|
unsigned int i;
|
2006-10-04 00:04:48 +02:00
|
|
|
|
2015-08-14 21:11:07 +02:00
|
|
|
[self saveSortValue];
|
|
|
|
|
2007-07-20 22:22:16 +02:00
|
|
|
if (!contactInfos)
|
|
|
|
{
|
|
|
|
folder = [self clientObject];
|
2011-04-14 20:01:02 +02:00
|
|
|
rq = [context request];
|
2007-07-20 22:22:16 +02:00
|
|
|
|
2011-04-14 20:01:02 +02:00
|
|
|
ascending = [rq formValueForKey: @"asc"];
|
2007-07-20 22:22:16 +02:00
|
|
|
ordering = ((![ascending length] || [ascending boolValue])
|
|
|
|
? NSOrderedAscending : NSOrderedDescending);
|
|
|
|
|
2011-04-14 20:01:02 +02:00
|
|
|
searchText = [rq formValueForKey: @"search"];
|
2007-07-20 22:22:16 +02:00
|
|
|
if ([searchText length] > 0)
|
2011-04-14 20:01:02 +02:00
|
|
|
valueText = [rq formValueForKey: @"value"];
|
2007-07-20 22:22:16 +02:00
|
|
|
else
|
|
|
|
valueText = nil;
|
|
|
|
|
2014-09-05 21:12:05 +02:00
|
|
|
excludeLists = [[rq formValueForKey: @"excludeLists"] boolValue];
|
|
|
|
|
2007-07-24 21:59:49 +02:00
|
|
|
[contactInfos release];
|
2014-09-05 21:12:05 +02:00
|
|
|
results = [folder lookupContactsWithFilter: valueText
|
|
|
|
onCriteria: searchText
|
|
|
|
sortBy: [self sortKey]
|
|
|
|
ordering: ordering
|
|
|
|
inDomain: [[context activeUser] domain]];
|
|
|
|
if (excludeLists)
|
|
|
|
{
|
|
|
|
filteredContacts = [NSMutableArray array];
|
|
|
|
for (i = 0; i < [results count]; i++)
|
|
|
|
{
|
|
|
|
contact = [results objectAtIndex: i];
|
|
|
|
if (![[contact objectForKey: @"c_component"] isEqualToString: @"vlist"])
|
|
|
|
{
|
|
|
|
[filteredContacts addObject: contact];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
contactInfos = [NSArray arrayWithArray: filteredContacts];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
contactInfos = results;
|
|
|
|
}
|
2016-02-20 05:19:07 +01:00
|
|
|
|
|
|
|
// Convert array of dictionaries to array of arrays (lighter on the wire)
|
|
|
|
max = [contactInfos count];
|
|
|
|
headers = [NSMutableArray arrayWithCapacity: max];
|
|
|
|
if (max > 0)
|
|
|
|
{
|
|
|
|
count = 0;
|
|
|
|
fields = [[contactInfos objectAtIndex: 0] allKeys];
|
|
|
|
[headers addObject: fields];
|
|
|
|
while (count < max)
|
|
|
|
{
|
|
|
|
[headers addObject: [[contactInfos objectAtIndex: count] objectsForKeys: fields
|
|
|
|
notFoundMarker: [NSNull null]]];
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
contactInfos = headers;
|
|
|
|
[contactInfos retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return contactInfos;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) sortedIDs
|
|
|
|
{
|
|
|
|
id <SOGoContactFolder> folder;
|
|
|
|
NSString *ascending, *searchText, *valueText;
|
|
|
|
NSArray *fields, *records;
|
|
|
|
NSDictionary *record;
|
|
|
|
NSEnumerator *recordsList;
|
|
|
|
NSMutableArray *ids;
|
|
|
|
BOOL excludeLists;
|
|
|
|
EOKeyValueQualifier *kvQualifier;
|
|
|
|
EOSortOrdering *ordering;
|
|
|
|
EOQualifier *qualifier;
|
|
|
|
WORequest *rq;
|
|
|
|
SEL compare;
|
|
|
|
|
|
|
|
folder = [self clientObject];
|
|
|
|
|
|
|
|
if (!sortedIDs && [folder isKindOfClass: [SOGoContactGCSFolder class]])
|
|
|
|
{
|
|
|
|
fields = [NSArray arrayWithObjects: @"c_name", nil];
|
|
|
|
rq = [context request];
|
|
|
|
qualifier = nil;
|
|
|
|
|
|
|
|
// ORDER BY clause
|
|
|
|
ascending = [rq formValueForKey: @"asc"];
|
|
|
|
if (![ascending length] || [ascending boolValue])
|
|
|
|
compare = EOCompareAscending;
|
|
|
|
else
|
|
|
|
compare = EOCompareDescending;
|
|
|
|
ordering = [EOSortOrdering sortOrderingWithKey: [self sortKey]
|
|
|
|
selector: compare];
|
|
|
|
|
|
|
|
// WHERE clause
|
|
|
|
searchText = [rq formValueForKey: @"search"];
|
|
|
|
if ([searchText length] > 0)
|
|
|
|
{
|
|
|
|
valueText = [rq formValueForKey: @"value"];
|
|
|
|
qualifier = [(SOGoContactGCSFolder *) folder qualifierForFilter: valueText
|
|
|
|
onCriteria: searchText];
|
|
|
|
}
|
|
|
|
excludeLists = [[rq formValueForKey: @"excludeLists"] boolValue];
|
|
|
|
if (excludeLists)
|
|
|
|
{
|
|
|
|
kvQualifier = [[EOKeyValueQualifier alloc]
|
|
|
|
initWithKey: @"c_component"
|
|
|
|
operatorSelector: EOQualifierOperatorNotEqual
|
|
|
|
value: @"vlist"];
|
|
|
|
[kvQualifier autorelease];
|
|
|
|
if (qualifier)
|
|
|
|
qualifier = [[EOAndQualifier alloc] initWithQualifiers: kvQualifier, qualifier, nil];
|
|
|
|
else
|
|
|
|
qualifier = kvQualifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Perform lookup
|
|
|
|
records = [(SOGoContactGCSFolder *) folder lookupContactsFields: fields
|
|
|
|
withQualifier: qualifier
|
|
|
|
andOrderings: [NSArray arrayWithObject: ordering]];
|
|
|
|
|
|
|
|
// Convert records to an array of strings (c_name)
|
|
|
|
ids = [NSMutableArray arrayWithCapacity: [records count]];
|
|
|
|
recordsList = [records objectEnumerator];
|
|
|
|
while ((record = [recordsList nextObject]))
|
|
|
|
[ids addObject: [record objectForKey: @"c_name"]];
|
|
|
|
|
|
|
|
[sortedIDs release];
|
|
|
|
sortedIDs = ids;
|
|
|
|
[sortedIDs retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return sortedIDs;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) getHeadersForIDs: (NSArray *) ids
|
|
|
|
{
|
|
|
|
id <SOGoContactFolder> folder;
|
|
|
|
NSArray *results, *fields;
|
|
|
|
NSEnumerator *idsList;
|
|
|
|
NSMutableArray *qualifiers, *headers;
|
|
|
|
NSString *contactID;
|
|
|
|
EOKeyValueQualifier *kvQualifier;
|
|
|
|
EOQualifier *orQualifier;
|
|
|
|
NSUInteger max, count;
|
|
|
|
|
|
|
|
folder = [self clientObject];
|
|
|
|
|
|
|
|
if (!contactInfos && [ids count] && [folder isKindOfClass: [SOGoContactGCSFolder class]])
|
|
|
|
{
|
|
|
|
qualifiers = [NSMutableArray arrayWithCapacity: [ids count]];
|
|
|
|
idsList = [ids objectEnumerator];
|
|
|
|
|
|
|
|
while ((contactID = [idsList nextObject]))
|
|
|
|
{
|
|
|
|
kvQualifier = [[EOKeyValueQualifier alloc]
|
|
|
|
initWithKey: @"c_name"
|
|
|
|
operatorSelector: EOQualifierOperatorEqual
|
|
|
|
value: contactID];
|
|
|
|
[kvQualifier autorelease];
|
|
|
|
[qualifiers addObject: kvQualifier];
|
|
|
|
}
|
|
|
|
|
|
|
|
orQualifier = [[EOOrQualifier alloc] initWithQualifierArray: qualifiers];
|
|
|
|
[orQualifier autorelease];
|
|
|
|
|
|
|
|
results = [(SOGoContactGCSFolder *) folder lookupContactsWithQualifier: orQualifier];
|
|
|
|
max = [results count];
|
|
|
|
headers = [NSMutableArray arrayWithCapacity: max];
|
|
|
|
if (max > 0)
|
|
|
|
{
|
|
|
|
count = 0;
|
|
|
|
fields = [[results objectAtIndex: 0] allKeys];
|
|
|
|
[headers addObject: fields];
|
|
|
|
while (count < max)
|
|
|
|
{
|
|
|
|
[headers addObject: [[results objectAtIndex: count] objectsForKeys: fields
|
|
|
|
notFoundMarker: [NSNull null]]];
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[contactInfos release];
|
|
|
|
contactInfos = headers;
|
2007-07-24 21:59:49 +02:00
|
|
|
[contactInfos retain];
|
2007-07-20 22:22:16 +02:00
|
|
|
}
|
2006-10-04 00:04:48 +02:00
|
|
|
|
2007-07-20 22:22:16 +02:00
|
|
|
return contactInfos;
|
2006-10-04 00:04:48 +02:00
|
|
|
}
|
|
|
|
|
2011-04-14 20:01:02 +02:00
|
|
|
/**
|
2015-01-22 15:17:41 +01:00
|
|
|
* @api {get} /so/:username/Contacts/:addressbookId/view List cards
|
|
|
|
* @apiVersion 1.0.0
|
|
|
|
* @apiName GetContactsList
|
|
|
|
* @apiGroup Contacts
|
|
|
|
* @apiExample {curl} Example usage:
|
|
|
|
* curl -i http://localhost/SOGo/so/sogo1/Contacts/personal/view?search=name_or_address\&value=Bob
|
|
|
|
*
|
2016-02-23 16:22:12 +01:00
|
|
|
* @apiParam {Boolean} [partial] Send all contacts IDs and headers of a the first 50 contacts. Defaults to false.
|
2015-01-22 15:17:41 +01:00
|
|
|
* @apiParam {Boolean} [asc] Descending sort when false. Defaults to true (ascending).
|
|
|
|
* @apiParam {String} [sort] Sort field. Either c_cn, c_mail, c_screenname, c_o, or c_telephonenumber.
|
|
|
|
* @apiParam {String} [search] Field criteria. Either name_or_address, category, or organization.
|
|
|
|
* @apiParam {String} [value] String to match
|
|
|
|
*
|
|
|
|
* @apiSuccess (Success 200) {String} id Address book ID
|
|
|
|
* @apiSuccess (Success 200) {String} [publicCardDavURL] Public CardDAV URL of the address book
|
|
|
|
* @apiSuccess (Success 200) {String} cardDavURL CardDAV URL of the address book
|
2016-02-23 16:22:12 +01:00
|
|
|
* @apiSuccess (Success 200) {String[]} [ids] Sorted IDs when requesting partial results
|
|
|
|
* @apiSuccess (Success 200) {Object[]} headers Matching cards
|
|
|
|
* @apiSuccess (Success 200) {String} headers.id Card ID
|
|
|
|
* @apiSuccess (Success 200) {String} headers.c_name Card ID
|
|
|
|
* @apiSuccess (Success 200) {String} headers.c_component Either vcard or vlist
|
|
|
|
* @apiSuccess (Success 200) {String} headers.c_cn Fullname
|
|
|
|
* @apiSuccess (Success 200) {String} headers.c_givenname Firstname
|
|
|
|
* @apiSuccess (Success 200) {String} headers.c_sn Lastname
|
|
|
|
* @apiSuccess (Success 200) {String} headers.c_screenname Screenname
|
|
|
|
* @apiSuccess (Success 200) {String} headers.c_o Organization name
|
|
|
|
* @apiSuccess (Success 200) {Object} headers.emails Preferred email address
|
|
|
|
* @apiSuccess (Success 200) {String} headers.emails.type Type (e.g., home or work)
|
|
|
|
* @apiSuccess (Success 200) {String} headers.emails.value Email address
|
|
|
|
* @apiSuccess (Success 200) {String} headers.c_mail Preferred email address
|
|
|
|
* @apiSuccess (Success 200) {String} headers.phones Preferred telephone number
|
|
|
|
* @apiSuccess (Success 200) {String} headers.phones.type Type (e.g., home or work)
|
|
|
|
* @apiSuccess (Success 200) {String} headers.phones.value Phone number
|
|
|
|
* @apiSuccess (Success 200) {String} headers.c_telephonenumber Preferred telephone number
|
|
|
|
* @apiSuccess (Success 200) {String} headers.c_categories Comma-separated list of categories
|
2015-01-22 15:17:41 +01:00
|
|
|
*
|
|
|
|
* See [SOGoContactGCSFolder fixupContactRecord:]
|
2011-04-14 20:01:02 +02:00
|
|
|
*/
|
|
|
|
- (id <WOActionResults>) contactsListAction
|
2011-03-24 16:27:53 +01:00
|
|
|
{
|
2011-04-14 20:01:02 +02:00
|
|
|
id <WOActionResults> result;
|
2016-02-20 05:19:07 +01:00
|
|
|
id folder;
|
|
|
|
NSMutableDictionary *data;
|
|
|
|
NSArray *ids, *partialIds, *headers;
|
|
|
|
NSRange range;
|
|
|
|
NSString *partial;
|
|
|
|
|
|
|
|
folder = [self clientObject];
|
|
|
|
data = [NSMutableDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[folder nameInContainer], @"id",
|
|
|
|
[self cardDavURL], @"cardDavURL",
|
|
|
|
[self publicCardDavURL], @"publicCardDavURL",
|
|
|
|
nil];
|
|
|
|
partial = [[context request] formValueForKey: @"partial"];
|
|
|
|
|
|
|
|
if ([partial intValue] && [folder isKindOfClass: [SOGoContactGCSFolder class]])
|
|
|
|
{
|
|
|
|
// Only save sort state when performing a partial listing
|
|
|
|
[self saveSortValue];
|
2011-04-14 20:01:02 +02:00
|
|
|
|
2016-02-20 05:19:07 +01:00
|
|
|
// Fetch all sorted IDs
|
|
|
|
ids = [self sortedIDs];
|
2014-02-07 21:52:43 +01:00
|
|
|
|
2016-02-20 05:19:07 +01:00
|
|
|
// Fetch the first X entries
|
|
|
|
if ([ids count] > headersPrefetchMaxSize)
|
|
|
|
{
|
|
|
|
range = NSMakeRange(0, headersPrefetchMaxSize);
|
|
|
|
partialIds = [ids subarrayWithRange: range];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
partialIds = ids;
|
|
|
|
}
|
|
|
|
headers = [self getHeadersForIDs: partialIds];
|
|
|
|
|
|
|
|
if (ids)
|
|
|
|
[data setObject: ids forKey: @"ids"];
|
|
|
|
if (headers)
|
|
|
|
[data setObject: headers forKey: @"headers"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
headers = [self contactInfos];
|
|
|
|
if (headers)
|
|
|
|
[data setObject: headers forKey: @"headers"];
|
|
|
|
}
|
2014-06-19 21:51:57 +02:00
|
|
|
|
2011-04-14 20:01:02 +02:00
|
|
|
result = [self responseWithStatus: 200
|
2016-02-20 05:19:07 +01:00
|
|
|
andJSONRepresentation: data];
|
2011-04-14 20:01:02 +02:00
|
|
|
|
|
|
|
return result;
|
2011-03-24 16:27:53 +01:00
|
|
|
}
|
|
|
|
|
2016-02-20 05:19:07 +01:00
|
|
|
- (id <WOActionResults>) getHeadersAction
|
|
|
|
{
|
|
|
|
NSArray *ids, *headers;
|
|
|
|
NSDictionary *data;
|
|
|
|
WORequest *request;
|
|
|
|
WOResponse *response;
|
|
|
|
|
|
|
|
request = [context request];
|
|
|
|
data = [[request contentAsString] objectFromJSONString];
|
|
|
|
if (![[data objectForKey: @"ids"] isKindOfClass: [NSArray class]] ||
|
|
|
|
[[data objectForKey: @"ids"] count] == 0)
|
|
|
|
{
|
|
|
|
data = [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
@"No ID specified", @"message", nil];
|
|
|
|
response = [self responseWithStatus: 404 /* Not Found */
|
|
|
|
andJSONRepresentation: data];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
ids = [data objectForKey: @"ids"];
|
|
|
|
headers = [self getHeadersForIDs: ids];
|
|
|
|
|
|
|
|
response = [self responseWithStatus: 200
|
|
|
|
andJSONRepresentation: headers];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2009-08-24 22:26:52 +02:00
|
|
|
- (id <WOActionResults>) contactSearchAction
|
|
|
|
{
|
|
|
|
id <WOActionResults> result;
|
|
|
|
id <SOGoContactFolder> folder;
|
2014-09-05 21:12:05 +02:00
|
|
|
BOOL excludeLists;
|
2012-02-11 08:08:02 +01:00
|
|
|
NSString *searchText, *mail, *domain;
|
2009-08-24 22:26:52 +02:00
|
|
|
NSDictionary *contact, *data;
|
|
|
|
NSArray *contacts, *descriptors, *sortedContacts;
|
|
|
|
NSMutableDictionary *uniqueContacts;
|
|
|
|
unsigned int i;
|
|
|
|
NSSortDescriptor *commonNameDescriptor;
|
2011-04-14 20:01:02 +02:00
|
|
|
WORequest *rq;
|
2009-08-24 22:26:52 +02:00
|
|
|
|
2011-04-14 20:01:02 +02:00
|
|
|
rq = [context request];
|
2014-09-05 21:12:05 +02:00
|
|
|
excludeLists = [[rq formValueForKey: @"excludeLists"] boolValue];
|
2011-04-14 20:01:02 +02:00
|
|
|
searchText = [rq formValueForKey: @"search"];
|
2009-08-24 22:26:52 +02:00
|
|
|
if ([searchText length] > 0)
|
|
|
|
{
|
|
|
|
NS_DURING
|
|
|
|
folder = [self clientObject];
|
|
|
|
NS_HANDLER
|
|
|
|
if ([[localException name] isEqualToString: @"SOGoDBException"])
|
|
|
|
folder = nil;
|
|
|
|
else
|
|
|
|
[localException raise];
|
|
|
|
NS_ENDHANDLER
|
2012-02-11 08:08:02 +01:00
|
|
|
|
|
|
|
domain = [[context activeUser] domain];
|
2009-08-24 22:26:52 +02:00
|
|
|
uniqueContacts = [NSMutableDictionary dictionary];
|
|
|
|
contacts = [folder lookupContactsWithFilter: searchText
|
2010-10-26 22:19:37 +02:00
|
|
|
onCriteria: @"name_or_address"
|
2009-08-24 22:26:52 +02:00
|
|
|
sortBy: @"c_cn"
|
2012-02-11 08:08:02 +01:00
|
|
|
ordering: NSOrderedAscending
|
2012-03-21 16:50:02 +01:00
|
|
|
inDomain: domain];
|
2009-08-24 22:26:52 +02:00
|
|
|
for (i = 0; i < [contacts count]; i++)
|
|
|
|
{
|
|
|
|
contact = [contacts objectAtIndex: i];
|
2014-09-05 21:12:05 +02:00
|
|
|
if (!excludeLists || ![[contact objectForKey: @"c_component"] isEqualToString: @"vlist"])
|
|
|
|
{
|
|
|
|
mail = [contact objectForKey: @"c_mail"];
|
|
|
|
if ([mail isNotNull] && [uniqueContacts objectForKey: mail] == nil)
|
|
|
|
[uniqueContacts setObject: contact forKey: mail];
|
|
|
|
}
|
2009-08-24 22:26:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ([uniqueContacts count] > 0)
|
|
|
|
{
|
|
|
|
// Sort the contacts by display name
|
|
|
|
commonNameDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"c_cn"
|
|
|
|
ascending:YES] autorelease];
|
|
|
|
descriptors = [NSArray arrayWithObjects: commonNameDescriptor, nil];
|
|
|
|
sortedContacts = [[uniqueContacts allValues] sortedArrayUsingDescriptors: descriptors];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
sortedContacts = [NSArray array];
|
|
|
|
|
|
|
|
data = [NSDictionary dictionaryWithObjectsAndKeys: searchText, @"searchText",
|
2014-08-06 22:06:58 +02:00
|
|
|
sortedContacts, @"cards", nil];
|
2011-04-14 20:01:02 +02:00
|
|
|
result = [self responseWithStatus: 200
|
|
|
|
andString: [data jsonRepresentation]];
|
2009-08-24 22:26:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
result = [NSException exceptionWithHTTPStatus: 400
|
|
|
|
reason: @"missing 'search' parameter"];
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-11-25 15:36:24 +01:00
|
|
|
- (NSString *) cardDavURL
|
|
|
|
{
|
|
|
|
NSString *davURL, *baseCardDAVURL;
|
|
|
|
|
|
|
|
davURL = @"";
|
|
|
|
|
|
|
|
if ([[self clientObject] respondsToSelector: @selector(realDavURL)])
|
|
|
|
davURL = [[[self clientObject] realDavURL] absoluteString];
|
|
|
|
|
|
|
|
if ([davURL hasSuffix: @"/"])
|
|
|
|
baseCardDAVURL = [davURL substringToIndex: [davURL length] - 1];
|
|
|
|
else
|
|
|
|
baseCardDAVURL = davURL;
|
|
|
|
|
|
|
|
return [NSString stringWithFormat: @"%@/", baseCardDAVURL];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) publicCardDavURL
|
|
|
|
{
|
|
|
|
if ([[self clientObject] respondsToSelector: @selector(publicDavURL)] &&
|
|
|
|
[[SOGoSystemDefaults sharedSystemDefaults] enablePublicAccess])
|
|
|
|
{
|
|
|
|
NSString *davURL, *basePublicCardDAVURL;
|
|
|
|
|
|
|
|
davURL = [[[self clientObject] publicDavURL] absoluteString];
|
|
|
|
if ([davURL hasSuffix: @"/"])
|
|
|
|
basePublicCardDAVURL = [davURL substringToIndex: [davURL length] - 1];
|
|
|
|
else
|
|
|
|
basePublicCardDAVURL = davURL;
|
|
|
|
|
|
|
|
return [NSString stringWithFormat: @"%@/", basePublicCardDAVURL];
|
|
|
|
}
|
|
|
|
|
|
|
|
return @"";
|
|
|
|
}
|
|
|
|
|
2011-04-14 20:01:02 +02:00
|
|
|
@end /* UIxContactsListActions */
|