зеркало из https://github.com/nextcloud/talk-ios.git
Add the ability to search and join open conversations.
Signed-off-by: Ivan Sein <ivan@nextcloud.com>
This commit is contained in:
Родитель
9efaf8be94
Коммит
c1a5be4dfb
|
@ -121,6 +121,7 @@ extern NSInteger const kReceivedChatMessagesLimit;
|
|||
// Rooms Controller
|
||||
- (NSURLSessionDataTask *)getRoomsForAccount:(TalkAccount *)account updateStatus:(BOOL)updateStatus withCompletionBlock:(GetRoomsCompletionBlock)block;
|
||||
- (NSURLSessionDataTask *)getRoomForAccount:(TalkAccount *)account withToken:(NSString *)token withCompletionBlock:(GetRoomCompletionBlock)block;
|
||||
- (NSURLSessionDataTask *)getListableRoomsForAccount:(TalkAccount *)account withSearchTerm:(NSString *)searchTerm andCompletionBlock:(GetRoomsCompletionBlock)block;
|
||||
- (NSURLSessionDataTask *)createRoomForAccount:(TalkAccount *)account with:(NSString *)invite ofType:(NCRoomType)type andName:(NSString *)roomName withCompletionBlock:(CreateRoomCompletionBlock)block;
|
||||
- (NSURLSessionDataTask *)renameRoom:(NSString *)token forAccount:(TalkAccount *)account withName:(NSString *)newName andCompletionBlock:(RenameRoomCompletionBlock)block;
|
||||
- (NSURLSessionDataTask *)makeRoomPublic:(NSString *)token forAccount:(TalkAccount *)account withCompletionBlock:(MakeRoomPublicCompletionBlock)block;
|
||||
|
|
|
@ -298,6 +298,38 @@ NSInteger const kReceivedChatMessagesLimit = 100;
|
|||
return task;
|
||||
}
|
||||
|
||||
- (NSURLSessionDataTask *)getListableRoomsForAccount:(TalkAccount *)account withSearchTerm:(NSString *)searchTerm andCompletionBlock:(GetRoomsCompletionBlock)block
|
||||
{
|
||||
NSString *endpoint = @"listed-room";
|
||||
NSInteger conversationAPIVersion = [self conversationAPIVersionForAccount:account];
|
||||
NSString *URLString = [self getRequestURLForEndpoint:endpoint withAPIVersion:conversationAPIVersion forAccount:account];
|
||||
NSDictionary *parameters = nil;
|
||||
if (searchTerm.length > 0) {
|
||||
parameters = @{@"searchTerm" : searchTerm};
|
||||
}
|
||||
NCAPISessionManager *apiSessionManager = [_apiSessionManagers objectForKey:account.accountId];
|
||||
NSURLSessionDataTask *task = [apiSessionManager GET:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) {
|
||||
NSArray *responseRooms = [[responseObject objectForKey:@"ocs"] objectForKey:@"data"];
|
||||
NSMutableArray *parsedRooms = [NSMutableArray new];
|
||||
for (NSDictionary *roomDict in responseRooms) {
|
||||
NCRoom *room = [NCRoom roomWithDictionary:roomDict andAccountId:account.accountId];
|
||||
[parsedRooms addObject:room];
|
||||
}
|
||||
if (block) {
|
||||
block(parsedRooms, nil, 0);
|
||||
}
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
NSInteger statusCode = [self getResponseStatusCode:task.response];
|
||||
[self checkResponseStatusCode:statusCode forAccount:account];
|
||||
if (block) {
|
||||
block(nil, error, statusCode);
|
||||
}
|
||||
}];
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
|
||||
- (NSURLSessionDataTask *)createRoomForAccount:(TalkAccount *)account with:(NSString *)invite ofType:(NCRoomType)type andName:(NSString *)roomName withCompletionBlock:(CreateRoomCompletionBlock)block
|
||||
{
|
||||
NSString *endpoint = @"room";
|
||||
|
|
|
@ -42,6 +42,7 @@ extern NSString * const kCapabilityCirclesSupport;
|
|||
extern NSString * const kCapabilityChatReferenceId;
|
||||
extern NSString * const kCapabilityPhonebookSearch;
|
||||
extern NSString * const kCapabilityChatReadStatus;
|
||||
extern NSString * const kCapabilityListableRooms;
|
||||
extern NSString * const kCapabilityDeleteMessages;
|
||||
extern NSString * const kCapabilityCallFlags;
|
||||
extern NSString * const kCapabilityRoomDescription;
|
||||
|
|
|
@ -44,6 +44,7 @@ NSString * const kCapabilityCirclesSupport = @"circles-support";
|
|||
NSString * const kCapabilityChatReferenceId = @"chat-reference-id";
|
||||
NSString * const kCapabilityPhonebookSearch = @"phonebook-search";
|
||||
NSString * const kCapabilityChatReadStatus = @"chat-read-status";
|
||||
NSString * const kCapabilityListableRooms = @"listable-rooms";
|
||||
NSString * const kCapabilityDeleteMessages = @"delete-messages";
|
||||
NSString * const kCapabilityCallFlags = @"conversation-call-flags";
|
||||
NSString * const kCapabilityRoomDescription = @"room-description";
|
||||
|
|
|
@ -24,9 +24,15 @@
|
|||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class NCRoom;
|
||||
|
||||
@interface RoomSearchTableViewController : UITableViewController
|
||||
|
||||
@property (nonatomic, strong) NSArray *rooms;
|
||||
@property (nonatomic, strong) NSArray *listableRooms;
|
||||
|
||||
- (NCRoom *)roomForIndexPath:(NSIndexPath *)indexPath;
|
||||
- (BOOL)hasResults;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -33,6 +33,11 @@
|
|||
#import "PlaceholderView.h"
|
||||
#import "RoomTableViewCell.h"
|
||||
|
||||
typedef enum RoomSearchSection {
|
||||
RoomSearchSectionFiltered = 0,
|
||||
RoomSearchSectionListable
|
||||
} RoomSearchSection;
|
||||
|
||||
@interface RoomSearchTableViewController ()
|
||||
{
|
||||
PlaceholderView *_roomSearchBackgroundView;
|
||||
|
@ -85,14 +90,39 @@
|
|||
return [formatter stringFromDate:date];
|
||||
}
|
||||
|
||||
#pragma mark - Table view data source
|
||||
|
||||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
||||
return 1;
|
||||
- (NCRoom *)roomForIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
if (indexPath.section == RoomSearchSectionFiltered && indexPath.row < _rooms.count) {
|
||||
return [_rooms objectAtIndex:indexPath.row];
|
||||
} else if (indexPath.section == RoomSearchSectionListable && indexPath.row < _listableRooms.count) {
|
||||
return [_listableRooms objectAtIndex:indexPath.row];
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||||
return _rooms.count;
|
||||
- (BOOL)hasResults
|
||||
{
|
||||
return _rooms.count > 0 || _listableRooms.count > 0;
|
||||
}
|
||||
|
||||
#pragma mark - Table view data source
|
||||
|
||||
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
||||
{
|
||||
return _listableRooms.count > 0 ? 2 : 1;
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
||||
{
|
||||
switch (section) {
|
||||
case RoomSearchSectionFiltered:
|
||||
return _rooms.count;
|
||||
case RoomSearchSectionListable:
|
||||
return _listableRooms.count;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
|
@ -100,14 +130,20 @@
|
|||
return kRoomTableCellHeight;
|
||||
}
|
||||
|
||||
//- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
|
||||
//{
|
||||
// return [_indexes objectAtIndex:section];
|
||||
//}
|
||||
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
|
||||
{
|
||||
switch (section) {
|
||||
case RoomSearchSectionListable:
|
||||
return NSLocalizedString(@"Open conversations", nil);
|
||||
default:
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
NCRoom *room = [_rooms objectAtIndex:indexPath.row];
|
||||
NCRoom *room = [self roomForIndexPath:indexPath];
|
||||
|
||||
RoomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kRoomCellIdentifier];
|
||||
if (!cell) {
|
||||
cell = [[RoomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kRoomCellIdentifier];
|
||||
|
|
|
@ -454,8 +454,17 @@ typedef void (^FetchRoomsCompletionBlock)(BOOL success);
|
|||
|
||||
- (void)searchForRoomsWithString:(NSString *)searchString
|
||||
{
|
||||
// Filter rooms
|
||||
_resultTableViewController.rooms = [self filterRoomsWithString:searchString];
|
||||
[_resultTableViewController.tableView reloadData];
|
||||
// Search for listable rooms
|
||||
TalkAccount *account = [[NCDatabaseManager sharedInstance] activeAccount];
|
||||
[[NCAPIController sharedInstance] getListableRoomsForAccount:account withSearchTerm:searchString andCompletionBlock:^(NSArray *rooms, NSError *error, NSInteger statusCode) {
|
||||
if (!error) {
|
||||
self->_resultTableViewController.listableRooms = rooms;
|
||||
[self->_resultTableViewController.tableView reloadData];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (NSArray *)filterRoomsWithString:(NSString *)searchString
|
||||
|
@ -687,8 +696,8 @@ typedef void (^FetchRoomsCompletionBlock)(BOOL success);
|
|||
- (void)setNotificationLevelForRoomAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
NCRoom *room = [_rooms objectAtIndex:indexPath.row];
|
||||
if (_searchController.active && _resultTableViewController.rooms.count > 0) {
|
||||
room = [_resultTableViewController.rooms objectAtIndex:indexPath.row];
|
||||
if (_searchController.active && _resultTableViewController.hasResults) {
|
||||
room = [_resultTableViewController roomForIndexPath:indexPath];
|
||||
}
|
||||
|
||||
UIAlertController *optionsActionSheet =
|
||||
|
@ -731,8 +740,8 @@ typedef void (^FetchRoomsCompletionBlock)(BOOL success);
|
|||
- (void)shareLinkFromRoomAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
NCRoom *room = [_rooms objectAtIndex:indexPath.row];
|
||||
if (_searchController.active && _resultTableViewController.rooms.count > 0) {
|
||||
room = [_resultTableViewController.rooms objectAtIndex:indexPath.row];
|
||||
if (_searchController.active && _resultTableViewController.hasResults) {
|
||||
room = [_resultTableViewController roomForIndexPath:indexPath];
|
||||
}
|
||||
|
||||
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
|
||||
|
@ -767,8 +776,8 @@ typedef void (^FetchRoomsCompletionBlock)(BOOL success);
|
|||
- (void)addRoomToFavoritesAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
NCRoom *room = [_rooms objectAtIndex:indexPath.row];
|
||||
if (_searchController.active && _resultTableViewController.rooms.count > 0) {
|
||||
room = [_resultTableViewController.rooms objectAtIndex:indexPath.row];
|
||||
if (_searchController.active && _resultTableViewController.hasResults) {
|
||||
room = [_resultTableViewController roomForIndexPath:indexPath];
|
||||
}
|
||||
|
||||
[[NCAPIController sharedInstance] addRoomToFavorites:room.token forAccount:[[NCDatabaseManager sharedInstance] activeAccount] withCompletionBlock:^(NSError *error) {
|
||||
|
@ -782,8 +791,8 @@ typedef void (^FetchRoomsCompletionBlock)(BOOL success);
|
|||
- (void)removeRoomFromFavoritesAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
NCRoom *room = [_rooms objectAtIndex:indexPath.row];
|
||||
if (_searchController.active && _resultTableViewController.rooms.count > 0) {
|
||||
room = [_resultTableViewController.rooms objectAtIndex:indexPath.row];
|
||||
if (_searchController.active && _resultTableViewController.hasResults) {
|
||||
room = [_resultTableViewController roomForIndexPath:indexPath];
|
||||
}
|
||||
|
||||
[[NCAPIController sharedInstance] removeRoomFromFavorites:room.token forAccount:[[NCDatabaseManager sharedInstance] activeAccount] withCompletionBlock:^(NSError *error) {
|
||||
|
@ -797,8 +806,8 @@ typedef void (^FetchRoomsCompletionBlock)(BOOL success);
|
|||
- (void)presentRoomInfoForRoomAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
NCRoom *room = [_rooms objectAtIndex:indexPath.row];
|
||||
if (_searchController.active && _resultTableViewController.rooms.count > 0) {
|
||||
room = [_resultTableViewController.rooms objectAtIndex:indexPath.row];
|
||||
if (_searchController.active && _resultTableViewController.hasResults) {
|
||||
room = [_resultTableViewController roomForIndexPath:indexPath];
|
||||
}
|
||||
|
||||
RoomInfoTableViewController *roomInfoVC = [[RoomInfoTableViewController alloc] initForRoom:room];
|
||||
|
@ -809,8 +818,8 @@ typedef void (^FetchRoomsCompletionBlock)(BOOL success);
|
|||
- (void)leaveRoomAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
NCRoom *room = [_rooms objectAtIndex:indexPath.row];
|
||||
if (_searchController.active && _resultTableViewController.rooms.count > 0) {
|
||||
room = [_resultTableViewController.rooms objectAtIndex:indexPath.row];
|
||||
if (_searchController.active && _resultTableViewController.hasResults) {
|
||||
room = [_resultTableViewController roomForIndexPath:indexPath];
|
||||
}
|
||||
|
||||
UIAlertController *confirmDialog =
|
||||
|
@ -818,7 +827,7 @@ typedef void (^FetchRoomsCompletionBlock)(BOOL success);
|
|||
message:NSLocalizedString(@"Once a conversation is left, to rejoin a closed conversation, an invite is needed. An open conversation can be rejoined at any time.", nil)
|
||||
preferredStyle:UIAlertControllerStyleAlert];
|
||||
UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Leave", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
|
||||
[_rooms removeObjectAtIndex:indexPath.row];
|
||||
[self->_rooms removeObjectAtIndex:indexPath.row];
|
||||
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
|
||||
[[NCAPIController sharedInstance] removeSelfFromRoom:room.token forAccount:[[NCDatabaseManager sharedInstance] activeAccount] withCompletionBlock:^(NSInteger errorCode, NSError *error) {
|
||||
if (errorCode == 400) {
|
||||
|
@ -838,8 +847,8 @@ typedef void (^FetchRoomsCompletionBlock)(BOOL success);
|
|||
- (void)deleteRoomAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
NCRoom *room = [_rooms objectAtIndex:indexPath.row];
|
||||
if (_searchController.active && _resultTableViewController.rooms.count > 0) {
|
||||
room = [_resultTableViewController.rooms objectAtIndex:indexPath.row];
|
||||
if (_searchController.active && _resultTableViewController.hasResults) {
|
||||
room = [_resultTableViewController roomForIndexPath:indexPath];
|
||||
}
|
||||
|
||||
UIAlertController *confirmDialog =
|
||||
|
@ -847,7 +856,7 @@ typedef void (^FetchRoomsCompletionBlock)(BOOL success);
|
|||
message:room.deletionMessage
|
||||
preferredStyle:UIAlertControllerStyleAlert];
|
||||
UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Delete", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
|
||||
[_rooms removeObjectAtIndex:indexPath.row];
|
||||
[self->_rooms removeObjectAtIndex:indexPath.row];
|
||||
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
|
||||
[[NCAPIController sharedInstance] deleteRoom:room.token forAccount:[[NCDatabaseManager sharedInstance] activeAccount] withCompletionBlock:^(NSError *error) {
|
||||
if (error) {
|
||||
|
@ -865,8 +874,8 @@ typedef void (^FetchRoomsCompletionBlock)(BOOL success);
|
|||
- (void)presentMoreActionsForRoomAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
NCRoom *room = [_rooms objectAtIndex:indexPath.row];
|
||||
if (_searchController.active && _resultTableViewController.rooms.count > 0) {
|
||||
room = [_resultTableViewController.rooms objectAtIndex:indexPath.row];
|
||||
if (_searchController.active && _resultTableViewController.hasResults) {
|
||||
room = [_resultTableViewController roomForIndexPath:indexPath];
|
||||
}
|
||||
|
||||
UIAlertController *optionsActionSheet =
|
||||
|
@ -930,8 +939,8 @@ typedef void (^FetchRoomsCompletionBlock)(BOOL success);
|
|||
{
|
||||
NCRoom *room = [_rooms objectAtIndex:indexPath.row];
|
||||
|
||||
if (_searchController.active && _resultTableViewController.rooms.count > 0) {
|
||||
room = [_resultTableViewController.rooms objectAtIndex:indexPath.row];
|
||||
if (_searchController.active && _resultTableViewController.hasResults) {
|
||||
room = [_resultTableViewController roomForIndexPath:indexPath];
|
||||
}
|
||||
|
||||
[[NCRoomsManager sharedInstance] startChatInRoom:room];
|
||||
|
@ -1001,8 +1010,8 @@ typedef void (^FetchRoomsCompletionBlock)(BOOL success);
|
|||
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
NCRoom *room = [_rooms objectAtIndex:indexPath.row];
|
||||
if (_searchController.active && _resultTableViewController.rooms.count > 0) {
|
||||
room = [_resultTableViewController.rooms objectAtIndex:indexPath.row];
|
||||
if (_searchController.active && _resultTableViewController.hasResults) {
|
||||
room = [_resultTableViewController roomForIndexPath:indexPath];
|
||||
}
|
||||
|
||||
NSString *deleteButtonText = NSLocalizedString(@"Delete", nil);
|
||||
|
@ -1016,8 +1025,8 @@ typedef void (^FetchRoomsCompletionBlock)(BOOL success);
|
|||
{
|
||||
if (editingStyle == UITableViewCellEditingStyleDelete) {
|
||||
NCRoom *room = [_rooms objectAtIndex:indexPath.row];
|
||||
if (_searchController.active && _resultTableViewController.rooms.count > 0) {
|
||||
room = [_resultTableViewController.rooms objectAtIndex:indexPath.row];
|
||||
if (_searchController.active && _resultTableViewController.hasResults) {
|
||||
room = [_resultTableViewController roomForIndexPath:indexPath];
|
||||
}
|
||||
|
||||
if (room.isLeavable) {
|
||||
|
@ -1045,8 +1054,8 @@ API_AVAILABLE(ios(11.0)){
|
|||
deleteAction.image = [UIImage imageNamed:@"delete"];
|
||||
|
||||
NCRoom *room = [_rooms objectAtIndex:indexPath.row];
|
||||
if (_searchController.active && _resultTableViewController.rooms.count > 0) {
|
||||
room = [_resultTableViewController.rooms objectAtIndex:indexPath.row];
|
||||
if (_searchController.active && _resultTableViewController.hasResults) {
|
||||
room = [_resultTableViewController roomForIndexPath:indexPath];
|
||||
}
|
||||
|
||||
if (room.isLeavable) {
|
||||
|
@ -1064,8 +1073,8 @@ API_AVAILABLE(ios(11.0)){
|
|||
- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView leadingSwipeActionsConfigurationForRowAtIndexPath:(nonnull NSIndexPath *)indexPath
|
||||
API_AVAILABLE(ios(11.0)){
|
||||
NCRoom *room = [_rooms objectAtIndex:indexPath.row];
|
||||
if (_searchController.active && _resultTableViewController.rooms.count > 0) {
|
||||
room = [_resultTableViewController.rooms objectAtIndex:indexPath.row];
|
||||
if (_searchController.active && _resultTableViewController.hasResults) {
|
||||
room = [_resultTableViewController roomForIndexPath:indexPath];
|
||||
}
|
||||
UIContextualAction *favoriteAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleNormal title:nil
|
||||
handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче