2014-10-02 15:02:47 +00:00
|
|
|
/*
|
|
|
|
Copyright 2014 OpenMarket Ltd
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
2014-11-17 16:32:46 +00:00
|
|
|
|
2014-10-03 17:26:39 +00:00
|
|
|
#import "RoomViewController.h"
|
2014-12-23 17:51:49 +00:00
|
|
|
#import "MemberViewController.h"
|
2015-03-31 13:09:17 +00:00
|
|
|
|
|
|
|
#import "MXKRoomBubbleTableViewCell.h"
|
|
|
|
|
2014-10-18 01:03:55 +00:00
|
|
|
#import "RoomMemberTableCell.h"
|
2014-12-15 15:54:31 +00:00
|
|
|
#import "RoomTitleView.h"
|
2014-10-02 15:02:47 +00:00
|
|
|
|
2015-01-23 14:36:05 +00:00
|
|
|
#import "MatrixSDKHandler.h"
|
2014-10-14 15:56:03 +00:00
|
|
|
#import "AppDelegate.h"
|
|
|
|
|
2015-04-02 14:55:26 +00:00
|
|
|
#import "RageShakeManager.h"
|
|
|
|
|
2014-11-10 18:01:49 +00:00
|
|
|
@interface RoomViewController () {
|
2014-11-21 09:54:49 +00:00
|
|
|
|
2014-10-17 13:54:59 +00:00
|
|
|
// Members list
|
2014-11-04 16:26:33 +00:00
|
|
|
NSArray *members;
|
2014-10-28 16:27:15 +00:00
|
|
|
id membersListener;
|
2014-11-07 21:58:26 +00:00
|
|
|
|
2015-01-28 10:30:15 +00:00
|
|
|
// the user taps on a member thumbnail
|
|
|
|
MXRoomMember *selectedRoomMember;
|
2014-10-14 15:56:03 +00:00
|
|
|
}
|
2014-10-02 15:02:47 +00:00
|
|
|
|
2014-10-15 14:13:35 +00:00
|
|
|
@property (weak, nonatomic) IBOutlet UINavigationItem *roomNavItem;
|
2015-02-23 14:46:57 +00:00
|
|
|
@property (strong, nonatomic) IBOutlet UIBarButtonItem *showRoomMembersButtonItem;
|
2014-12-15 15:54:31 +00:00
|
|
|
@property (weak, nonatomic) IBOutlet RoomTitleView *roomTitleView;
|
2015-02-23 14:46:57 +00:00
|
|
|
|
2015-04-02 09:33:41 +00:00
|
|
|
@property (strong, nonatomic) MXKAlert *actionMenu;
|
2015-01-13 16:53:31 +00:00
|
|
|
|
2014-10-02 15:02:47 +00:00
|
|
|
@end
|
|
|
|
|
2014-10-03 17:26:39 +00:00
|
|
|
@implementation RoomViewController
|
2014-10-02 15:02:47 +00:00
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
[super viewDidLoad];
|
2015-02-23 14:46:57 +00:00
|
|
|
|
2015-04-01 22:25:41 +00:00
|
|
|
// Replace the default input toolbar view with the one based on `HPGrowingTextView`.
|
|
|
|
[self setRoomInputToolbarViewClass:MXKRoomInputToolbarViewWithHPGrowingText.class];
|
|
|
|
|
2015-04-02 14:55:26 +00:00
|
|
|
// Set rageShake handler
|
|
|
|
self.rageShakeManager = [RageShakeManager sharedManager];
|
|
|
|
|
2014-12-18 13:36:55 +00:00
|
|
|
// ensure that the titleView will be scaled when it will be required
|
|
|
|
// during a screen rotation for example.
|
|
|
|
self.roomTitleView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
|
2014-10-02 15:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)didReceiveMemoryWarning {
|
|
|
|
[super didReceiveMemoryWarning];
|
|
|
|
// Dispose of any resources that can be recreated.
|
|
|
|
}
|
|
|
|
|
2014-10-13 16:53:33 +00:00
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
|
|
[super viewWillAppear:animated];
|
|
|
|
|
2014-12-24 15:32:24 +00:00
|
|
|
// Register a listener for events that concern room members
|
2015-01-23 14:36:05 +00:00
|
|
|
MatrixSDKHandler *mxHandler = [MatrixSDKHandler sharedHandler];
|
2014-12-24 15:32:24 +00:00
|
|
|
NSArray *mxMembersEvents = @[
|
|
|
|
kMXEventTypeStringRoomMember,
|
|
|
|
kMXEventTypeStringRoomPowerLevels,
|
|
|
|
kMXEventTypeStringPresence
|
|
|
|
];
|
|
|
|
membersListener = [mxHandler.mxSession listenToEventsOfTypes:mxMembersEvents onEvent:^(MXEvent *event, MXEventDirection direction, id customObject) {
|
|
|
|
// consider only live event
|
|
|
|
if (direction == MXEventDirectionForwards) {
|
|
|
|
// Check the room Id (if any)
|
2015-04-07 14:22:40 +00:00
|
|
|
if (event.roomId && [event.roomId isEqualToString:self.roomDataSource.roomId] == NO) {
|
2014-12-24 15:32:24 +00:00
|
|
|
// This event does not concern the current room members
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-28 17:39:23 +00:00
|
|
|
// Check whether no text field is editing before refreshing title view
|
|
|
|
if (!self.roomTitleView.isEditing) {
|
|
|
|
[self.roomTitleView refreshDisplay];
|
|
|
|
}
|
2014-12-24 15:32:24 +00:00
|
|
|
|
|
|
|
// refresh the
|
|
|
|
if (members.count > 0) {
|
|
|
|
// Hide potential action sheet
|
|
|
|
if (self.actionMenu) {
|
|
|
|
[self.actionMenu dismiss:NO];
|
|
|
|
self.actionMenu = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}];
|
2014-10-13 16:53:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewWillDisappear:(BOOL)animated {
|
|
|
|
[super viewWillDisappear:animated];
|
|
|
|
|
2015-02-16 09:37:17 +00:00
|
|
|
MatrixSDKHandler *mxHandler = [MatrixSDKHandler sharedHandler];
|
|
|
|
|
2014-11-04 16:26:33 +00:00
|
|
|
// hide action
|
2014-11-10 18:01:49 +00:00
|
|
|
if (self.actionMenu) {
|
|
|
|
[self.actionMenu dismiss:NO];
|
|
|
|
self.actionMenu = nil;
|
2014-11-04 16:26:33 +00:00
|
|
|
}
|
|
|
|
|
2015-02-16 09:37:17 +00:00
|
|
|
// Store the potential message partially typed in text input
|
2015-04-07 14:22:40 +00:00
|
|
|
[mxHandler storePartialTextMessage:self.inputToolbarView.textMessage forRoomId:self.roomDataSource.roomId];
|
2014-12-22 10:52:29 +00:00
|
|
|
|
2014-12-24 15:32:24 +00:00
|
|
|
if (membersListener) {
|
|
|
|
[mxHandler.mxSession removeListener:membersListener];
|
|
|
|
membersListener = nil;
|
|
|
|
}
|
2014-10-13 16:53:33 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 15:56:03 +00:00
|
|
|
- (void)viewDidAppear:(BOOL)animated {
|
|
|
|
[super viewDidAppear:animated];
|
|
|
|
|
2014-12-09 09:39:56 +00:00
|
|
|
// Set visible room id
|
2015-04-07 14:22:40 +00:00
|
|
|
[AppDelegate theDelegate].masterTabBarController.visibleRoomId = self.roomDataSource.roomId;
|
2014-12-24 10:10:41 +00:00
|
|
|
|
2015-01-22 10:09:14 +00:00
|
|
|
[self updateUI];
|
2015-02-16 15:20:33 +00:00
|
|
|
|
|
|
|
// Retrieve the potential message partially typed during last room display.
|
|
|
|
// Note: We have to wait for viewDidAppear before updating growingTextView (viewWillAppear is too early)
|
2015-04-07 14:22:40 +00:00
|
|
|
self.inputToolbarView.textMessage = [[MatrixSDKHandler sharedHandler] partialTextMessageForRoomId:self.roomDataSource.roomId];
|
2014-10-14 15:56:03 +00:00
|
|
|
}
|
|
|
|
|
2014-12-09 09:39:56 +00:00
|
|
|
- (void)viewDidDisappear:(BOOL)animated {
|
|
|
|
[super viewDidDisappear:animated];
|
|
|
|
|
|
|
|
// Reset visible room id
|
|
|
|
[AppDelegate theDelegate].masterTabBarController.visibleRoomId = nil;
|
|
|
|
}
|
|
|
|
|
2015-03-31 13:09:17 +00:00
|
|
|
#pragma mark -
|
2015-01-20 11:41:27 +00:00
|
|
|
|
2015-03-31 13:09:17 +00:00
|
|
|
- (void)dismissKeyboard {
|
2015-01-16 09:50:15 +00:00
|
|
|
|
2015-03-31 13:09:17 +00:00
|
|
|
[_roomTitleView dismissKeyboard];
|
|
|
|
[super dismissKeyboard];
|
2014-12-22 10:52:29 +00:00
|
|
|
}
|
|
|
|
|
2015-03-31 13:09:17 +00:00
|
|
|
- (void)didMatrixSessionStateChange {
|
|
|
|
|
|
|
|
[super didMatrixSessionStateChange];
|
2015-03-31 15:51:25 +00:00
|
|
|
|
|
|
|
// Check dataSource state
|
2015-04-07 14:22:40 +00:00
|
|
|
if (self.roomDataSource && self.roomDataSource.state == MXKDataSourceStatePreparing) {
|
2015-03-31 13:09:17 +00:00
|
|
|
// dataSource is not ready, keep running the loading wheel
|
|
|
|
[self.activityIndicator startAnimating];
|
2015-02-25 16:58:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-22 10:09:14 +00:00
|
|
|
- (void)updateUI {
|
2015-03-31 13:09:17 +00:00
|
|
|
|
2015-03-31 15:51:25 +00:00
|
|
|
// Update UI by considering dataSource state
|
2015-04-07 14:22:40 +00:00
|
|
|
if (self.roomDataSource && self.roomDataSource.state == MXKDataSourceStateReady) {
|
2015-03-31 13:09:17 +00:00
|
|
|
// Here the activityIndicator should be stopped, we call `didMatrixSessionStateChange` to take
|
|
|
|
// into account mxSession state before stopping activity indicator.
|
|
|
|
[super didMatrixSessionStateChange];
|
|
|
|
|
|
|
|
// Show input tool bar
|
|
|
|
self.inputToolbarView.hidden = NO;
|
|
|
|
|
2015-01-22 10:09:14 +00:00
|
|
|
// Check room members to enable/disable members button in nav bar
|
2015-04-07 14:22:40 +00:00
|
|
|
self.showRoomMembersButtonItem.enabled = ([self.roomDataSource.room.state members].count != 0);
|
2015-03-31 13:09:17 +00:00
|
|
|
|
2015-04-07 14:22:40 +00:00
|
|
|
self.roomTitleView.mxRoom = self.roomDataSource.room;
|
2015-03-31 13:09:17 +00:00
|
|
|
self.roomTitleView.editable = YES;
|
2015-03-31 15:51:25 +00:00
|
|
|
self.roomTitleView.hidden = NO;
|
2015-03-31 13:09:17 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
self.inputToolbarView.hidden = YES;
|
2015-02-23 14:46:57 +00:00
|
|
|
self.showRoomMembersButtonItem.enabled = NO;
|
2015-03-31 13:09:17 +00:00
|
|
|
|
2015-04-07 14:22:40 +00:00
|
|
|
if (self.roomDataSource && self.roomDataSource.state == MXKDataSourceStatePreparing) {
|
|
|
|
self.roomTitleView.mxRoom = self.roomDataSource.room;
|
2015-03-31 15:51:25 +00:00
|
|
|
self.roomTitleView.hidden = (!self.roomTitleView.mxRoom);
|
|
|
|
} else {
|
|
|
|
self.roomTitleView.mxRoom = nil;
|
|
|
|
self.roomTitleView.hidden = NO;
|
|
|
|
}
|
2015-03-31 13:09:17 +00:00
|
|
|
self.roomTitleView.editable = NO;
|
2015-01-22 10:09:14 +00:00
|
|
|
}
|
2015-03-31 13:09:17 +00:00
|
|
|
|
2015-01-22 10:09:14 +00:00
|
|
|
[self.roomTitleView refreshDisplay];
|
|
|
|
}
|
|
|
|
|
2015-03-31 13:09:17 +00:00
|
|
|
#pragma mark -
|
2015-01-28 10:30:15 +00:00
|
|
|
|
2015-03-31 13:09:17 +00:00
|
|
|
- (void)displayRoom:(MXKRoomDataSource*)roomDataSource {
|
|
|
|
[super displayRoom:roomDataSource];
|
|
|
|
|
|
|
|
[self updateUI];
|
2015-01-28 10:30:15 +00:00
|
|
|
}
|
|
|
|
|
2015-04-01 09:06:48 +00:00
|
|
|
- (void)destroy {
|
2015-03-31 16:33:37 +00:00
|
|
|
members = nil;
|
|
|
|
if (membersListener) {
|
|
|
|
membersListener = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self.actionMenu) {
|
|
|
|
[self.actionMenu dismiss:NO];
|
|
|
|
self.actionMenu = nil;
|
|
|
|
}
|
|
|
|
|
2015-04-01 09:06:48 +00:00
|
|
|
[super destroy];
|
2015-03-31 16:33:37 +00:00
|
|
|
}
|
|
|
|
|
2015-03-31 13:09:17 +00:00
|
|
|
#pragma mark - MXKDataSource delegate
|
2014-10-15 23:34:46 +00:00
|
|
|
|
2015-03-31 15:51:25 +00:00
|
|
|
- (void)dataSource:(MXKDataSource *)dataSource didStateChange:(MXKDataSourceState)state {
|
|
|
|
// Take into account dataSource state to update UI
|
|
|
|
[self updateUI];
|
2015-03-31 13:09:17 +00:00
|
|
|
|
2015-04-15 14:27:58 +00:00
|
|
|
if ([super respondsToSelector:@selector(dataSource:didStateChange:)]) {
|
2015-03-31 15:51:25 +00:00
|
|
|
[super dataSource:dataSource didStateChange:state];
|
2014-10-16 20:17:00 +00:00
|
|
|
}
|
2014-10-15 23:34:46 +00:00
|
|
|
}
|
|
|
|
|
2015-03-31 13:09:17 +00:00
|
|
|
- (void)dataSource:(MXKDataSource *)dataSource didRecognizeAction:(NSString *)actionIdentifier inCell:(id<MXKCellRendering>)cell userInfo:(NSDictionary *)userInfo {
|
|
|
|
|
|
|
|
// Override default implementation in case of tap on avatar
|
|
|
|
if ([actionIdentifier isEqualToString:kMXKRoomBubbleCellTapOnAvatarView]) {
|
2015-04-07 14:22:40 +00:00
|
|
|
selectedRoomMember = [self.roomDataSource.room.state memberWithUserId:userInfo[kMXKRoomBubbleCellUserIdKey]];
|
2015-03-31 13:09:17 +00:00
|
|
|
if (selectedRoomMember) {
|
2015-04-09 22:17:15 +00:00
|
|
|
[self performSegueWithIdentifier:@"showMemberDetails" sender:self];
|
2015-03-31 13:09:17 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Keep default implementation for other actions
|
|
|
|
[super dataSource:dataSource didRecognizeAction:actionIdentifier inCell:cell userInfo:userInfo];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-14 14:17:20 +00:00
|
|
|
#pragma mark - UITextField delegate
|
|
|
|
|
2014-11-21 17:56:12 +00:00
|
|
|
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
|
2014-12-15 15:54:31 +00:00
|
|
|
NSString *alertMsg = nil;
|
|
|
|
|
|
|
|
if (textField == _roomTitleView.displayNameTextField) {
|
2014-12-08 14:48:35 +00:00
|
|
|
// Check whether the user has enough power to rename the room
|
2015-04-07 14:22:40 +00:00
|
|
|
MXRoomPowerLevels *powerLevels = [self.roomDataSource.room.state powerLevels];
|
2015-01-23 14:36:05 +00:00
|
|
|
NSUInteger userPowerLevel = [powerLevels powerLevelOfUserWithUserID:[MatrixSDKHandler sharedHandler].userId];
|
2014-12-22 09:17:08 +00:00
|
|
|
if (userPowerLevel >= [powerLevels minimumPowerLevelForSendingEventAsStateEvent:kMXEventTypeStringRoomName]) {
|
2014-12-12 13:58:53 +00:00
|
|
|
// Only the room name is edited here, update the text field with the room name
|
2015-04-07 14:22:40 +00:00
|
|
|
textField.text = self.roomDataSource.room.state.name;
|
2014-12-15 15:54:31 +00:00
|
|
|
textField.backgroundColor = [UIColor whiteColor];
|
2014-12-08 14:48:35 +00:00
|
|
|
} else {
|
2014-12-15 15:54:31 +00:00
|
|
|
alertMsg = @"You are not authorized to edit this room name";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check whether the user is allowed to change room topic
|
2014-12-22 09:17:08 +00:00
|
|
|
if (userPowerLevel >= [powerLevels minimumPowerLevelForSendingEventAsStateEvent:kMXEventTypeStringRoomTopic]) {
|
2014-12-15 15:54:31 +00:00
|
|
|
// Show topic text field even if the current value is nil
|
|
|
|
_roomTitleView.hiddenTopic = NO;
|
|
|
|
if (alertMsg) {
|
|
|
|
// Here the user can only update the room topic, switch on room topic field (without displaying alert)
|
|
|
|
alertMsg = nil;
|
|
|
|
[_roomTitleView.topicTextField becomeFirstResponder];
|
|
|
|
return NO;
|
2014-12-08 14:48:35 +00:00
|
|
|
}
|
|
|
|
}
|
2014-12-15 15:54:31 +00:00
|
|
|
} else if (textField == _roomTitleView.topicTextField) {
|
|
|
|
// Check whether the user has enough power to edit room topic
|
2015-04-07 14:22:40 +00:00
|
|
|
MXRoomPowerLevels *powerLevels = [self.roomDataSource.room.state powerLevels];
|
2015-01-23 14:36:05 +00:00
|
|
|
NSUInteger userPowerLevel = [powerLevels powerLevelOfUserWithUserID:[MatrixSDKHandler sharedHandler].userId];
|
2014-12-22 09:17:08 +00:00
|
|
|
if (userPowerLevel >= [powerLevels minimumPowerLevelForSendingEventAsStateEvent:kMXEventTypeStringRoomTopic]) {
|
2014-12-15 15:54:31 +00:00
|
|
|
textField.backgroundColor = [UIColor whiteColor];
|
2014-12-19 07:03:39 +00:00
|
|
|
[self.roomTitleView stopTopicAnimation];
|
2014-12-15 15:54:31 +00:00
|
|
|
} else {
|
|
|
|
alertMsg = @"You are not authorized to edit this room topic";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alertMsg) {
|
|
|
|
// Alert user
|
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
|
if (self.actionMenu) {
|
|
|
|
[self.actionMenu dismiss:NO];
|
|
|
|
}
|
2015-04-02 09:33:41 +00:00
|
|
|
self.actionMenu = [[MXKAlert alloc] initWithTitle:nil message:alertMsg style:MXKAlertStyleAlert];
|
|
|
|
self.actionMenu.cancelButtonIndex = [self.actionMenu addActionWithTitle:@"Cancel" style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert) {
|
2014-12-15 15:54:31 +00:00
|
|
|
weakSelf.actionMenu = nil;
|
|
|
|
}];
|
|
|
|
[self.actionMenu showInViewController:self];
|
2014-12-08 14:48:35 +00:00
|
|
|
return NO;
|
2014-11-21 17:56:12 +00:00
|
|
|
}
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)textFieldDidEndEditing:(UITextField *)textField {
|
2014-12-15 15:54:31 +00:00
|
|
|
if (textField == _roomTitleView.displayNameTextField) {
|
|
|
|
textField.backgroundColor = [UIColor clearColor];
|
2014-12-08 14:48:35 +00:00
|
|
|
|
2014-12-15 15:54:31 +00:00
|
|
|
NSString *roomName = textField.text;
|
2015-04-07 14:22:40 +00:00
|
|
|
if ((roomName.length || self.roomDataSource.room.state.name.length) && [roomName isEqualToString:self.roomDataSource.room.state.name] == NO) {
|
2015-03-31 13:09:17 +00:00
|
|
|
[self.activityIndicator startAnimating];
|
2014-12-11 17:37:25 +00:00
|
|
|
__weak typeof(self) weakSelf = self;
|
2015-04-07 14:22:40 +00:00
|
|
|
[self.roomDataSource.room setName:roomName success:^{
|
2015-03-31 13:09:17 +00:00
|
|
|
// Here the activityIndicator should be stopped, we call `didMatrixSessionStateChange` to take
|
|
|
|
// into account mxSession state before stopping activity indicator.
|
|
|
|
[super didMatrixSessionStateChange];
|
2014-12-15 15:54:31 +00:00
|
|
|
// Refresh title display
|
2015-04-07 14:22:40 +00:00
|
|
|
textField.text = weakSelf.roomDataSource.room.state.displayname;
|
2014-11-21 17:56:12 +00:00
|
|
|
} failure:^(NSError *error) {
|
2015-03-31 13:09:17 +00:00
|
|
|
[super didMatrixSessionStateChange];
|
2014-11-21 17:56:12 +00:00
|
|
|
// Revert change
|
2015-04-07 14:22:40 +00:00
|
|
|
textField.text = weakSelf.roomDataSource.room.state.displayname;
|
2015-03-31 13:09:17 +00:00
|
|
|
NSLog(@"[Console RoomVC] Rename room failed: %@", error);
|
|
|
|
// Alert user
|
2014-11-21 17:56:12 +00:00
|
|
|
[[AppDelegate theDelegate] showErrorAsAlert:error];
|
|
|
|
}];
|
2014-12-12 13:58:53 +00:00
|
|
|
} else {
|
|
|
|
// No change on room name, restore title with room displayName
|
2015-04-07 14:22:40 +00:00
|
|
|
textField.text = self.roomDataSource.room.state.displayname;
|
2014-12-15 15:54:31 +00:00
|
|
|
}
|
|
|
|
} else if (textField == _roomTitleView.topicTextField) {
|
|
|
|
textField.backgroundColor = [UIColor clearColor];
|
|
|
|
|
|
|
|
NSString *topic = textField.text;
|
2015-04-07 14:22:40 +00:00
|
|
|
if ((topic.length || self.roomDataSource.room.state.topic.length) && [topic isEqualToString:self.roomDataSource.room.state.topic] == NO) {
|
2015-03-31 13:09:17 +00:00
|
|
|
[self.activityIndicator startAnimating];
|
2014-12-15 15:54:31 +00:00
|
|
|
__weak typeof(self) weakSelf = self;
|
2015-04-07 14:22:40 +00:00
|
|
|
[self.roomDataSource.room setTopic:topic success:^{
|
2015-03-31 13:09:17 +00:00
|
|
|
// Here the activityIndicator should be stopped, we call `didMatrixSessionStateChange` to take
|
|
|
|
// into account mxSession state before stopping activity indicator.
|
|
|
|
[super didMatrixSessionStateChange];
|
2014-12-15 15:54:31 +00:00
|
|
|
// Hide topic field if empty
|
|
|
|
weakSelf.roomTitleView.hiddenTopic = !textField.text.length;
|
|
|
|
} failure:^(NSError *error) {
|
2015-03-31 13:09:17 +00:00
|
|
|
[super didMatrixSessionStateChange];
|
2014-12-15 15:54:31 +00:00
|
|
|
// Revert change
|
2015-04-07 14:22:40 +00:00
|
|
|
textField.text = weakSelf.roomDataSource.room.state.topic;
|
2014-12-15 15:54:31 +00:00
|
|
|
// Hide topic field if empty
|
|
|
|
weakSelf.roomTitleView.hiddenTopic = !textField.text.length;
|
2015-02-24 12:49:05 +00:00
|
|
|
NSLog(@"[RoomVC] Topic room change failed: %@", error);
|
2014-12-15 15:54:31 +00:00
|
|
|
//Alert user
|
|
|
|
[[AppDelegate theDelegate] showErrorAsAlert:error];
|
|
|
|
}];
|
|
|
|
} else {
|
|
|
|
// Hide topic field if empty
|
|
|
|
_roomTitleView.hiddenTopic = !topic.length;
|
2014-11-21 17:56:12 +00:00
|
|
|
}
|
|
|
|
}
|
2014-12-08 14:48:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)textFieldShouldReturn:(UITextField*) textField {
|
2014-12-15 15:54:31 +00:00
|
|
|
if (textField == _roomTitleView.displayNameTextField) {
|
|
|
|
// "Next" key has been pressed
|
|
|
|
[_roomTitleView.topicTextField becomeFirstResponder];
|
|
|
|
} else {
|
|
|
|
// "Done" key has been pressed
|
|
|
|
[textField resignFirstResponder];
|
|
|
|
}
|
2014-10-13 16:53:33 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2015-03-31 13:09:17 +00:00
|
|
|
- (BOOL)isIRCStyleCommand:(NSString*)string {
|
|
|
|
// Override the default behavior for `/join` command in order to open automatically the joined room
|
2014-10-27 10:35:52 +00:00
|
|
|
|
2015-03-31 13:09:17 +00:00
|
|
|
if ([string hasPrefix:kCmdJoinRoom]) {
|
2014-10-27 10:35:52 +00:00
|
|
|
// Join a room
|
2015-03-31 13:09:17 +00:00
|
|
|
NSString *roomAlias = [string substringFromIndex:kCmdJoinRoom.length + 1];
|
2014-10-27 10:35:52 +00:00
|
|
|
// Remove white space from both ends
|
|
|
|
roomAlias = [roomAlias stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
|
|
|
|
|
|
|
|
// Check
|
|
|
|
if (roomAlias.length) {
|
2015-01-23 14:36:05 +00:00
|
|
|
[[MatrixSDKHandler sharedHandler].mxSession joinRoom:roomAlias success:^(MXRoom *room) {
|
2014-12-17 09:55:33 +00:00
|
|
|
// Show the room
|
|
|
|
[[AppDelegate theDelegate].masterTabBarController showRoom:room.state.roomId];
|
|
|
|
} failure:^(NSError *error) {
|
2015-03-31 13:09:17 +00:00
|
|
|
NSLog(@"[Console RoomVC] Join roomAlias (%@) failed: %@", roomAlias, error);
|
2014-12-17 09:55:33 +00:00
|
|
|
//Alert user
|
|
|
|
[[AppDelegate theDelegate] showErrorAsAlert:error];
|
|
|
|
}];
|
2014-10-27 10:35:52 +00:00
|
|
|
} else {
|
|
|
|
// Display cmd usage in text input as placeholder
|
2015-03-31 13:09:17 +00:00
|
|
|
self.inputToolbarView.placeholder = @"Usage: /join <room_alias>";
|
2014-11-17 16:32:46 +00:00
|
|
|
}
|
2015-03-31 13:09:17 +00:00
|
|
|
return YES;
|
2014-11-04 16:26:33 +00:00
|
|
|
}
|
2015-03-31 13:09:17 +00:00
|
|
|
return [super isIRCStyleCommand:string];
|
2014-11-04 16:26:33 +00:00
|
|
|
}
|
2014-12-23 17:51:49 +00:00
|
|
|
|
|
|
|
#pragma mark - Segues
|
|
|
|
|
|
|
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
2015-04-09 22:17:15 +00:00
|
|
|
if ([[segue identifier] isEqualToString:@"showMemberList"]) {
|
|
|
|
|
2015-04-10 13:23:43 +00:00
|
|
|
if ([[segue destinationViewController] isKindOfClass:[MXKRoomMemberListViewController class]]) {
|
|
|
|
MXKRoomMemberListViewController* membersController = (MXKRoomMemberListViewController*)[segue destinationViewController];
|
|
|
|
|
|
|
|
// Dismiss keyboard
|
|
|
|
[self dismissKeyboard];
|
|
|
|
|
|
|
|
MXKRoomMemberListDataSource *membersDataSource = [[MXKRoomMemberListDataSource alloc] initWithRoomId:self.roomDataSource.roomId andMatrixSession:[MatrixSDKHandler sharedHandler].mxSession];
|
|
|
|
[membersController displayList:membersDataSource];
|
|
|
|
}
|
2015-04-09 22:17:15 +00:00
|
|
|
} else if ([[segue identifier] isEqualToString:@"showMemberDetails"]) {
|
2014-12-23 17:51:49 +00:00
|
|
|
MemberViewController* controller = [segue destinationViewController];
|
2015-01-28 10:30:15 +00:00
|
|
|
|
|
|
|
if (selectedRoomMember) {
|
|
|
|
controller.mxRoomMember = selectedRoomMember;
|
|
|
|
selectedRoomMember = nil;
|
|
|
|
}
|
2015-04-07 14:22:40 +00:00
|
|
|
controller.mxRoom = self.roomDataSource.room;
|
2014-12-23 17:51:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-02 15:02:47 +00:00
|
|
|
@end
|
2014-12-22 10:55:28 +00:00
|
|
|
|
|
|
|
|