Search for different shareTypes depending on server capabilities.

Signed-off-by: Ivan Sein <ivan@nextcloud.com>
This commit is contained in:
Ivan Sein 2020-02-03 20:11:35 +01:00
Родитель cd186ca3c8
Коммит 93c0616694
8 изменённых файлов: 42 добавлений и 20 удалений

Просмотреть файл

@ -219,7 +219,7 @@
- (void)getPossibleParticipants
{
[[NCAPIController sharedInstance] getContactsForAccount:[[NCDatabaseManager sharedInstance] activeAccount] withSearchParam:nil andCompletionBlock:^(NSArray *indexes, NSMutableDictionary *contacts, NSMutableArray *contactList, NSError *error) {
[[NCAPIController sharedInstance] getContactsForAccount:[[NCDatabaseManager sharedInstance] activeAccount] forRoom:_room.token groupRoom:YES withSearchParam:nil andCompletionBlock:^(NSArray *indexes, NSMutableDictionary *contacts, NSMutableArray *contactList, NSError *error) {
if (!error) {
NSMutableArray *filteredParticipants = [self filterContacts:contactList];
NSMutableDictionary *participants = [[NCAPIController sharedInstance] indexedUsersFromUsersArray:filteredParticipants];
@ -238,7 +238,7 @@
- (void)searchForParticipantsWithString:(NSString *)searchString
{
[_searchParticipantsTask cancel];
_searchParticipantsTask = [[NCAPIController sharedInstance] getContactsForAccount:[[NCDatabaseManager sharedInstance] activeAccount] withSearchParam:searchString andCompletionBlock:^(NSArray *indexes, NSMutableDictionary *contacts, NSMutableArray *contactList, NSError *error) {
_searchParticipantsTask = [[NCAPIController sharedInstance] getContactsForAccount:[[NCDatabaseManager sharedInstance] activeAccount] forRoom:_room.token groupRoom:YES withSearchParam:searchString andCompletionBlock:^(NSArray *indexes, NSMutableDictionary *contacts, NSMutableArray *contactList, NSError *error) {
if (!error) {
NSMutableArray *filteredParticipants = [self filterContacts:contactList];
NSMutableDictionary *participants = [[NCAPIController sharedInstance] indexedUsersFromUsersArray:filteredParticipants];
@ -340,8 +340,12 @@
cell.labelTitle.text = participant.name;
[cell.contactImage setImageWithURLRequest:[[NCAPIController sharedInstance] createAvatarRequestForUser:participant.userId andSize:96 usingAccount:[[NCDatabaseManager sharedInstance] activeAccount]]
placeholderImage:nil success:nil failure:nil];
if ([participant.source isEqualToString:@"users"]) {
[cell.contactImage setImageWithURLRequest:[[NCAPIController sharedInstance] createAvatarRequestForUser:participant.userId andSize:96 usingAccount:[[NCDatabaseManager sharedInstance] activeAccount]]
placeholderImage:nil success:nil failure:nil];
} else {
[cell.contactImage setImage:[UIImage imageNamed:@"group-bg"]];
}
UIImageView *checkboxChecked = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"checkbox-checked"]];
UIImageView *checkboxUnchecked = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"checkbox-unchecked"]];

Просмотреть файл

@ -77,7 +77,7 @@ typedef void (^UnsubscribeToPushProxyCompletionBlock)(NSError *error);
- (void)createAPISessionManagerForAccount:(TalkAccount *)account;
// Contacts Controller
- (NSURLSessionDataTask *)getContactsForAccount:(TalkAccount *)account withSearchParam:(NSString *)search andCompletionBlock:(GetContactsCompletionBlock)block;
- (NSURLSessionDataTask *)getContactsForAccount:(TalkAccount *)account forRoom:(NSString *)room groupRoom:(BOOL)groupRoom withSearchParam:(NSString *)search andCompletionBlock:(GetContactsCompletionBlock)block;
- (NSMutableDictionary *)indexedUsersFromUsersArray:(NSArray *)users;
// Rooms Controller

Просмотреть файл

@ -161,15 +161,24 @@ NSString * const kNCSpreedAPIVersion = @"/apps/spreed/api/v1";
#pragma mark - Contacts Controller
- (NSURLSessionDataTask *)getContactsForAccount:(TalkAccount *)account withSearchParam:(NSString *)search andCompletionBlock:(GetContactsCompletionBlock)block
- (NSURLSessionDataTask *)getContactsForAccount:(TalkAccount *)account forRoom:(NSString *)room groupRoom:(BOOL)groupRoom withSearchParam:(NSString *)search andCompletionBlock:(GetContactsCompletionBlock)block
{
NSMutableArray *shareTypes = [[NSMutableArray alloc] initWithObjects:@(NCShareTypeUser), nil];
if (groupRoom && [[NCSettingsController sharedInstance] serverHasTalkCapability:kCapabilityInviteGroupsAndMails]) {
[shareTypes addObject:@(NCShareTypeGroup)];
[shareTypes addObject:@(NCShareTypeEmail)];
if ([[NCSettingsController sharedInstance] serverHasTalkCapability:kCapabilityCirclesSupport]) {
[shareTypes addObject:@(NCShareTypeCircle)];
}
}
NSString *URLString = [NSString stringWithFormat:@"%@%@/core/autocomplete/get", account.server, kNCOCSAPIVersion];
NSDictionary *parameters = @{@"fomat" : @"json",
@"search" : search ? search : @"",
@"limit" : @"50",
@"itemType" : @"call",
@"itemId" : @"new",
@"shareTypes" : @[@(NCShareTypeUser)]
@"itemId" : room ? room : @"new",
@"shareTypes" : shareTypes
};
NCAPISessionManager *apiSessionManager = [_apiSessionManagers objectForKey:account.accountId];

Просмотреть файл

@ -32,10 +32,12 @@ extern NSString * const kNCLockScreenPasscodeType;
extern NSString * const kCapabilitySystemMessages;
extern NSString * const kCapabilityNotificationLevels;
extern NSString * const kCapabilityInviteGroupsAndMails;
extern NSString * const kCapabilityLockedOneToOneRooms;
extern NSString * const kCapabilityWebinaryLobby;
extern NSString * const kCapabilityChatReadMarker;
extern NSString * const kCapabilityStartCallFlag;
extern NSString * const kCapabilityCirclesSupport;
extern NSInteger const kDefaultChatMaxLength;
extern NSString * const kMinimumRequiredTalkCapability;

Просмотреть файл

@ -53,12 +53,14 @@ NSString * const kNCUserDefaultBrowser = @"ncUserDefaultBrowser";
NSString * const kNCLockScreenPasscode = @"ncLockScreenPasscode";
NSString * const kNCLockScreenPasscodeType = @"ncLockScreenPasscodeType";
NSString * const kCapabilitySystemMessages = @"system-messages";
NSString * const kCapabilityNotificationLevels = @"notification-levels";
NSString * const kCapabilityLockedOneToOneRooms = @"locked-one-to-one-rooms";
NSString * const kCapabilityWebinaryLobby = @"webinary-lobby";
NSString * const kCapabilityChatReadMarker = @"chat-read-marker";
NSString * const kCapabilityStartCallFlag = @"start-call-flag";
NSString * const kCapabilitySystemMessages = @"system-messages";
NSString * const kCapabilityNotificationLevels = @"notification-levels";
NSString * const kCapabilityInviteGroupsAndMails = @"invite-groups-and-mails";
NSString * const kCapabilityLockedOneToOneRooms = @"locked-one-to-one-rooms";
NSString * const kCapabilityWebinaryLobby = @"webinary-lobby";
NSString * const kCapabilityChatReadMarker = @"chat-read-marker";
NSString * const kCapabilityStartCallFlag = @"start-call-flag";
NSString * const kCapabilityCirclesSupport = @"circles-support";
NSInteger const kDefaultChatMaxLength = 1000;
NSString * const kMinimumRequiredTalkCapability = kCapabilitySystemMessages; // Talk 4.0 is the minimum required version

Просмотреть файл

@ -11,6 +11,7 @@
typedef enum NCShareType {
NCShareTypeUser = 0,
NCShareTypeGroup = 1,
NCShareTypeEmail = 4,
NCShareTypeCircle = 7
} NCShareType;

Просмотреть файл

@ -187,7 +187,7 @@ NSString * const NCSelectedContactForChatNotification = @"NCSelectedContactForCh
- (void)getContacts
{
[[NCAPIController sharedInstance] getContactsForAccount:[[NCDatabaseManager sharedInstance] activeAccount] withSearchParam:nil andCompletionBlock:^(NSArray *indexes, NSMutableDictionary *contacts, NSMutableArray *contactList, NSError *error) {
[[NCAPIController sharedInstance] getContactsForAccount:[[NCDatabaseManager sharedInstance] activeAccount] forRoom:nil groupRoom:NO withSearchParam:nil andCompletionBlock:^(NSArray *indexes, NSMutableDictionary *contacts, NSMutableArray *contactList, NSError *error) {
if (!error) {
_contacts = contacts;
_indexes = [NSMutableArray arrayWithArray:indexes];
@ -204,7 +204,7 @@ NSString * const NCSelectedContactForChatNotification = @"NCSelectedContactForCh
- (void)searchForContactsWithString:(NSString *)searchString
{
[_searchContactsTask cancel];
_searchContactsTask = [[NCAPIController sharedInstance] getContactsForAccount:[[NCDatabaseManager sharedInstance] activeAccount] withSearchParam:searchString andCompletionBlock:^(NSArray *indexes, NSMutableDictionary *contacts, NSMutableArray *contactList, NSError *error) {
_searchContactsTask = [[NCAPIController sharedInstance] getContactsForAccount:[[NCDatabaseManager sharedInstance] activeAccount] forRoom:nil groupRoom:NO withSearchParam:searchString andCompletionBlock:^(NSArray *indexes, NSMutableDictionary *contacts, NSMutableArray *contactList, NSError *error) {
if (!error) {
[_resultTableViewController setSearchResultContacts:contacts withIndexes:indexes];
} else {

Просмотреть файл

@ -203,7 +203,7 @@
- (void)getPossibleParticipants
{
[[NCAPIController sharedInstance] getContactsForAccount:[[NCDatabaseManager sharedInstance] activeAccount] withSearchParam:nil andCompletionBlock:^(NSArray *indexes, NSMutableDictionary *contacts, NSMutableArray *contactList, NSError *error) {
[[NCAPIController sharedInstance] getContactsForAccount:[[NCDatabaseManager sharedInstance] activeAccount] forRoom:nil groupRoom:YES withSearchParam:nil andCompletionBlock:^(NSArray *indexes, NSMutableDictionary *contacts, NSMutableArray *contactList, NSError *error) {
if (!error) {
_participants = contacts;
_indexes = [NSMutableArray arrayWithArray:indexes];
@ -220,7 +220,7 @@
- (void)searchForParticipantsWithString:(NSString *)searchString
{
[_searchParticipantsTask cancel];
_searchParticipantsTask = [[NCAPIController sharedInstance] getContactsForAccount:[[NCDatabaseManager sharedInstance] activeAccount] withSearchParam:searchString andCompletionBlock:^(NSArray *indexes, NSMutableDictionary *contacts, NSMutableArray *contactList, NSError *error) {
_searchParticipantsTask = [[NCAPIController sharedInstance] getContactsForAccount:[[NCDatabaseManager sharedInstance] activeAccount] forRoom:nil groupRoom:YES withSearchParam:searchString andCompletionBlock:^(NSArray *indexes, NSMutableDictionary *contacts, NSMutableArray *contactList, NSError *error) {
if (!error) {
[_resultTableViewController setSearchResultContacts:contacts withIndexes:indexes];
} else {
@ -319,8 +319,12 @@
cell.labelTitle.text = participant.name;
[cell.contactImage setImageWithURLRequest:[[NCAPIController sharedInstance] createAvatarRequestForUser:participant.userId andSize:96 usingAccount:[[NCDatabaseManager sharedInstance] activeAccount]]
placeholderImage:nil success:nil failure:nil];
if ([participant.source isEqualToString:@"users"]) {
[cell.contactImage setImageWithURLRequest:[[NCAPIController sharedInstance] createAvatarRequestForUser:participant.userId andSize:96 usingAccount:[[NCDatabaseManager sharedInstance] activeAccount]]
placeholderImage:nil success:nil failure:nil];
} else {
[cell.contactImage setImage:[UIImage imageNamed:@"group-bg"]];
}
UIImageView *checkboxChecked = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"checkbox-checked"]];
UIImageView *checkboxUnchecked = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"checkbox-unchecked"]];