Home "+" button: Add "Join room" option

https://github.com/vector-im/riot-meta/issues/65
This commit is contained in:
manuroe
2017-05-02 15:54:50 +02:00
parent 8d1d4cc735
commit f4a7704983
4 changed files with 96 additions and 11 deletions
+75 -6
View File
@@ -60,7 +60,7 @@
// The gradient view displayed above the screen
CAGradientLayer* tableViewMaskLayer;
MXHTTPOperation *roomCreationRequest;
MXHTTPOperation *currentRequest;
}
@end
@@ -159,7 +159,13 @@
- (void)destroy
{
[super destroy];
if (currentRequest)
{
[currentRequest cancel];
currentRequest = nil;
}
if (currentAlert)
{
[currentAlert dismiss:NO];
@@ -1542,18 +1548,18 @@
if (self.mainSession)
{
// Create one room at time
if (!roomCreationRequest)
if (!currentRequest)
{
[self startActivityIndicator];
// Create an empty room.
roomCreationRequest = [self.mainSession createRoom:nil
currentRequest = [self.mainSession createRoom:nil
visibility:kMXRoomDirectoryVisibilityPrivate
roomAlias:nil
topic:nil
success:^(MXRoom *room) {
roomCreationRequest = nil;
currentRequest = nil;
[self stopActivityIndicator];
if (currentAlert)
{
@@ -1568,7 +1574,7 @@
} failure:^(NSError *error) {
roomCreationRequest = nil;
currentRequest = nil;
[self stopActivityIndicator];
if (currentAlert)
{
@@ -1605,6 +1611,69 @@
}
}
- (void)joinARoom
{
[currentAlert dismiss:NO];
__weak typeof(self) weakSelf = self;
// Prompt the user to type a room id or room alias
currentAlert = [[MXKAlert alloc] initWithTitle:NSLocalizedStringFromTable(@"room_recents_join_room_title", @"Vector", nil)
message:NSLocalizedStringFromTable(@"room_recents_join_room_prompt", @"Vector", nil)
style:MXKAlertStyleAlert];
[currentAlert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
textField.secureTextEntry = NO;
textField.placeholder = nil;
textField.keyboardType = UIKeyboardTypeDefault;
}];
currentAlert.cancelButtonIndex = [currentAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) {
if (weakSelf)
{
typeof(self) self = weakSelf;
self->currentAlert = nil;
}
}];
[currentAlert addActionWithTitle:NSLocalizedStringFromTable(@"join", @"Vector", nil) style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) {
if (weakSelf)
{
UITextField *textField = [alert textFieldAtIndex:0];
NSString *roomAliasOrId = textField.text;
typeof(self) self = weakSelf;
self->currentAlert = nil;
[self.activityIndicator startAnimating];
self->currentRequest = [self.mainSession joinRoom:textField.text success:^(MXRoom *room) {
currentRequest = nil;
[self.activityIndicator stopAnimating];
// Show the room
[[AppDelegate theDelegate] showRoom:room.state.roomId andEventId:nil withMatrixSession:self.mainSession];
} failure:^(NSError *error) {
currentRequest = nil;
[self.activityIndicator stopAnimating];
NSLog(@"[Vector RoomVC] Join joinARoom (%@) failed", roomAliasOrId);
//Alert user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
}
}];
currentAlert.mxkAccessibilityIdentifier = @"RecentsVCJoinARoomAlert";
[currentAlert showInViewController:self];
}
#pragma mark - MXKRecentListViewControllerDelegate
- (void)recentListViewController:(MXKRecentListViewController *)recentListViewController didSelectRoom:(NSString *)roomId inMatrixSession:(MXSession *)matrixSession