mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-17 15:09:31 +02:00
Implement showRoom: in order to open directly details view controller on joined room or new created room.
This commit is contained in:
@@ -206,6 +206,7 @@
|
||||
<outlet property="controlViewBottomConstraint" destination="C5t-bm-3s8" id="Ks1-Z5-mzO"/>
|
||||
<outlet property="messageTextField" destination="k2m-aY-U73" id="fSA-Eg-duj"/>
|
||||
<outlet property="optionBtn" destination="cfF-YG-Cvg" id="Ppb-dg-Tub"/>
|
||||
<outlet property="roomNavItem" destination="3Zt-Wl-J6o" id="gjB-fs-Whw"/>
|
||||
<outlet property="sendBtn" destination="Icg-kc-a2c" id="Tr0-1e-QJp"/>
|
||||
<outlet property="tableView" destination="meV-kn-sxo" id="Q9E-0S-N40"/>
|
||||
</connections>
|
||||
@@ -678,10 +679,10 @@
|
||||
</objects>
|
||||
<point key="canvasLocation" x="55" y="842"/>
|
||||
</scene>
|
||||
<!--Chat Rooms-->
|
||||
<!--RecentsSplitVC-->
|
||||
<scene sceneID="Nki-YV-4Qg">
|
||||
<objects>
|
||||
<splitViewController title="Chat Rooms" id="H1p-Uh-vWS" sceneMemberID="viewController">
|
||||
<splitViewController title="RecentsSplitVC" id="H1p-Uh-vWS" sceneMemberID="viewController">
|
||||
<tabBarItem key="tabBarItem" systemItem="recents" id="mXn-Bx-qzv"/>
|
||||
<toolbarItems/>
|
||||
<connections>
|
||||
@@ -767,10 +768,10 @@
|
||||
</objects>
|
||||
<point key="canvasLocation" x="1665" y="-687"/>
|
||||
</scene>
|
||||
<!--Navigation Controller-->
|
||||
<!--RoomNav-->
|
||||
<scene sceneID="r7l-gg-dq7">
|
||||
<objects>
|
||||
<navigationController id="vC3-pB-5Vb" sceneMemberID="viewController">
|
||||
<navigationController title="RoomNav" id="vC3-pB-5Vb" sceneMemberID="viewController">
|
||||
<navigationBar key="navigationBar" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="DjV-YW-jjY">
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</navigationBar>
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
|
||||
if ([[MatrixHandler sharedHandler] isLogged]) {
|
||||
// Update alias placeholder
|
||||
_roomAliasTextField.placeholder = [NSString stringWithFormat:@"(e.g. #foo:%@)", [[MatrixHandler sharedHandler] homeServer]];
|
||||
_roomAliasTextField.placeholder = [NSString stringWithFormat:@"(e.g. #foo:%@)", [MatrixHandler sharedHandler].homeServer];
|
||||
// Refresh listed public rooms
|
||||
[self refreshPublicRooms];
|
||||
}
|
||||
@@ -93,7 +93,7 @@
|
||||
sectionHeader.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0];
|
||||
|
||||
if (_publicRooms) {
|
||||
NSString *homeserver = [[MatrixHandler sharedHandler] homeServerURL];
|
||||
NSString *homeserver = [MatrixHandler sharedHandler].homeServerURL;
|
||||
if (homeserver.length) {
|
||||
sectionHeader.text = [NSString stringWithFormat:@" Public Rooms (at %@):", homeserver];
|
||||
} else {
|
||||
@@ -118,17 +118,24 @@
|
||||
#pragma mark - Table view delegate
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
// Join the selected room
|
||||
MXPublicRoom *publicRoom = [_publicRooms objectAtIndex:indexPath.row];
|
||||
[[[MatrixHandler sharedHandler] mxSession] join:publicRoom.room_id success:^{
|
||||
// Show joined room
|
||||
[[AppDelegate theDelegate].masterTabBarController showRoomDetails:publicRoom.room_id];
|
||||
} failure:^(NSError *error) {
|
||||
NSLog(@"Failed to join public room (%@) failed: %@", publicRoom.displayname, error);
|
||||
//Alert user
|
||||
[[AppDelegate theDelegate] showErrorAsAlert:error];
|
||||
}];
|
||||
MatrixHandler *mxHandler = [MatrixHandler sharedHandler];
|
||||
|
||||
// Check whether the user has already joined the selected public room
|
||||
MXPublicRoom *publicRoom = [_publicRooms objectAtIndex:indexPath.row];
|
||||
if ([mxHandler.mxData getRoomData:publicRoom.room_id]) {
|
||||
// Open selected room
|
||||
[[AppDelegate theDelegate].masterTabBarController showRoom:publicRoom.room_id];
|
||||
} else {
|
||||
// Join the selected room
|
||||
[mxHandler.mxSession join:publicRoom.room_id success:^{
|
||||
// Show joined room
|
||||
[[AppDelegate theDelegate].masterTabBarController showRoom:publicRoom.room_id];
|
||||
} failure:^(NSError *error) {
|
||||
NSLog(@"Failed to join public room (%@) failed: %@", publicRoom.displayname, error);
|
||||
//Alert user
|
||||
[[AppDelegate theDelegate] showErrorAsAlert:error];
|
||||
}];
|
||||
}
|
||||
|
||||
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||||
}
|
||||
@@ -137,7 +144,7 @@
|
||||
|
||||
- (void)refreshPublicRooms {
|
||||
// Retrieve public rooms
|
||||
[[[MatrixHandler sharedHandler] mxHomeServer] publicRooms:^(NSArray *rooms){
|
||||
[[MatrixHandler sharedHandler].mxHomeServer publicRooms:^(NSArray *rooms){
|
||||
_publicRooms = rooms;
|
||||
[_publicRoomsTable reloadData];
|
||||
}
|
||||
@@ -163,7 +170,7 @@
|
||||
// Remove '#' character
|
||||
alias = [alias substringFromIndex:1];
|
||||
// Remove homeserver
|
||||
NSString *suffix = [NSString stringWithFormat:@":%@",[[MatrixHandler sharedHandler] homeServer]];
|
||||
NSString *suffix = [NSString stringWithFormat:@":%@",[MatrixHandler sharedHandler].homeServer];
|
||||
NSRange range = [alias rangeOfString:suffix];
|
||||
alias = [alias stringByReplacingCharactersInRange:range withString:@""];
|
||||
}
|
||||
@@ -230,10 +237,10 @@
|
||||
NSString * alias = textField.text;
|
||||
if (alias.length) {
|
||||
// add homeserver as suffix
|
||||
textField.text = [NSString stringWithFormat:@"#%@:%@", alias, [[MatrixHandler sharedHandler] homeServer]];
|
||||
textField.text = [NSString stringWithFormat:@"#%@:%@", alias, [MatrixHandler sharedHandler].homeServer];
|
||||
}
|
||||
|
||||
textField.placeholder = [NSString stringWithFormat:@"(e.g. #foo:%@)", [[MatrixHandler sharedHandler] homeServer]];
|
||||
textField.placeholder = [NSString stringWithFormat:@"(e.g. #foo:%@)", [MatrixHandler sharedHandler].homeServer];
|
||||
} else if (textField == _participantsTextField) {
|
||||
NSArray *participants = self.participantsList;
|
||||
textField.text = [participants componentsJoinedByString:@"; "];
|
||||
@@ -252,7 +259,7 @@
|
||||
participants = [participants stringByAppendingString:@" @"];
|
||||
} else if ([string isEqualToString:@":"]) {
|
||||
// Add homeserver
|
||||
participants = [participants stringByAppendingString:[[MatrixHandler sharedHandler] homeServer]];
|
||||
participants = [participants stringByAppendingString:[MatrixHandler sharedHandler].homeServer];
|
||||
}
|
||||
|
||||
textField.text = participants;
|
||||
@@ -286,7 +293,7 @@
|
||||
}
|
||||
|
||||
// Create new room
|
||||
[[[MatrixHandler sharedHandler] mxSession]
|
||||
[[MatrixHandler sharedHandler].mxSession
|
||||
createRoom:roomName
|
||||
visibility:(_roomVisibilityControl.selectedSegmentIndex == 0) ? kMXRoomVisibilityPublic : kMXRoomVisibilityPrivate
|
||||
room_alias_name:self.alias
|
||||
@@ -298,7 +305,7 @@
|
||||
_roomAliasTextField.text = nil;
|
||||
_participantsTextField.text = nil;
|
||||
// Open created room
|
||||
[[AppDelegate theDelegate].masterTabBarController showRoomDetails:response.room_id];
|
||||
[[AppDelegate theDelegate].masterTabBarController showRoom:response.room_id];
|
||||
} failure:^(NSError *error) {
|
||||
_createRoomBtn.enabled = YES;
|
||||
NSLog(@"Create room (%@ %@ %@ (%@)) failed: %@", _roomNameTextField.text, self.alias, self.participantsList, (_roomVisibilityControl.selectedSegmentIndex == 0) ? @"Public":@"Private", error);
|
||||
|
||||
@@ -24,10 +24,8 @@
|
||||
@interface MasterTabBarController : UITabBarController
|
||||
|
||||
- (void)showLoginScreen;
|
||||
|
||||
- (void)showRoomCreationForm;
|
||||
|
||||
- (void)showRoomDetails:(NSString*)roomId;
|
||||
- (void)showRoom:(NSString*)roomId;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -17,7 +17,12 @@
|
||||
#import "MasterTabBarController.h"
|
||||
#import "MatrixHandler.h"
|
||||
|
||||
@interface MasterTabBarController ()
|
||||
#import "RecentsViewController.h"
|
||||
|
||||
@interface MasterTabBarController () {
|
||||
UINavigationController *recentsNavigationController;
|
||||
RecentsViewController *recentsViewController;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -26,6 +31,26 @@
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view, typically from a nib.
|
||||
|
||||
// To simplify navigation into the app, we retrieve here the navigation controller and the view controller related
|
||||
// to the recents list in Recents Tab.
|
||||
// Note: UISplitViewController is not supported on iPhone for iOS < 8.0
|
||||
UIViewController* recents = [self.viewControllers objectAtIndex:TABBAR_RECENTS_INDEX];
|
||||
recentsNavigationController = nil;
|
||||
if ([recents isKindOfClass:[UISplitViewController class]]) {
|
||||
UISplitViewController *splitViewController = (UISplitViewController *)recents;
|
||||
recentsNavigationController = [splitViewController.viewControllers objectAtIndex:0];
|
||||
} else if ([recents isKindOfClass:[UINavigationController class]]) {
|
||||
recentsNavigationController = (UINavigationController*)recents;
|
||||
}
|
||||
|
||||
if (recentsNavigationController) {
|
||||
for (UIViewController *viewController in recentsNavigationController.viewControllers) {
|
||||
if ([viewController isKindOfClass:[RecentsViewController class]]) {
|
||||
recentsViewController = (RecentsViewController*)viewController;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)viewDidAppear:(BOOL)animated {
|
||||
@@ -41,6 +66,11 @@
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
recentsNavigationController = nil;
|
||||
recentsViewController = nil;
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (void)showLoginScreen {
|
||||
@@ -52,10 +82,17 @@
|
||||
[self setSelectedIndex:TABBAR_HOME_INDEX];
|
||||
}
|
||||
|
||||
- (void)showRoomDetails:(NSString*)roomId {
|
||||
// Switch on recent
|
||||
- (void)showRoom:(NSString*)roomId {
|
||||
// Force back to recents list if room details is displayed in Recents Tab
|
||||
if (recentsViewController) {
|
||||
[recentsNavigationController popToViewController:recentsViewController animated:NO];
|
||||
}
|
||||
|
||||
// Switch on Recents Tab
|
||||
[self setSelectedIndex:TABBAR_RECENTS_INDEX];
|
||||
//TODO
|
||||
|
||||
// Select room to display its details
|
||||
recentsViewController.preSelectedRoomId = roomId;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
@property (nonatomic,readonly) BOOL isLogged;
|
||||
@property (nonatomic,readonly) BOOL isInitialSyncDone;
|
||||
|
||||
+ (id)sharedHandler;
|
||||
+ (MatrixHandler *)sharedHandler;
|
||||
|
||||
- (void)logout;
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ static MatrixHandler *sharedHandler = nil;
|
||||
|
||||
@synthesize homeServerURL, homeServer, userLogin, userId, accessToken;
|
||||
|
||||
+ (id)sharedHandler {
|
||||
+ (MatrixHandler *)sharedHandler {
|
||||
@synchronized(self) {
|
||||
if(sharedHandler == nil)
|
||||
{
|
||||
|
||||
@@ -20,8 +20,7 @@
|
||||
|
||||
@interface RecentsViewController : UITableViewController
|
||||
|
||||
@property (strong, nonatomic) RoomViewController *roomViewController;
|
||||
|
||||
@property (strong, nonatomic) NSString *preSelectedRoomId; // set a non-nil value to this property will open room details
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -31,10 +31,11 @@
|
||||
@implementation RecentsTableViewCell
|
||||
@end
|
||||
|
||||
@interface RecentsViewController ()
|
||||
@interface RecentsViewController () {
|
||||
NSArray *recents;
|
||||
}
|
||||
@property (strong, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator;
|
||||
|
||||
@property NSArray *recents;
|
||||
@end
|
||||
|
||||
@implementation RecentsViewController
|
||||
@@ -54,16 +55,19 @@
|
||||
|
||||
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(createNewRoom:)];
|
||||
self.navigationItem.rightBarButtonItem = addButton;
|
||||
self.roomViewController = (RoomViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
|
||||
|
||||
// Add activity indicator
|
||||
[self.view addSubview:_activityIndicator];
|
||||
_activityIndicator.center = CGPointMake(self.view.center.x, 100);
|
||||
[self.view bringSubviewToFront:_activityIndicator];
|
||||
|
||||
// Initialisation
|
||||
recents = nil;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
self.recents = nil;
|
||||
recents = nil;
|
||||
_preSelectedRoomId = nil;
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
@@ -75,31 +79,80 @@
|
||||
[super viewWillAppear:animated];
|
||||
|
||||
// Refresh recents table
|
||||
[self refresh];
|
||||
[self configureView];
|
||||
[[MatrixHandler sharedHandler] addObserver:self forKeyPath:@"isInitialSyncDone" options:0 context:nil];
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated {
|
||||
[super viewWillDisappear:animated];
|
||||
|
||||
// Leave potential editing mode
|
||||
[self setEditing:NO];
|
||||
|
||||
_preSelectedRoomId = nil;
|
||||
[[MatrixHandler sharedHandler] removeObserver:self forKeyPath:@"isInitialSyncDone"];
|
||||
}
|
||||
|
||||
#pragma mark - recents
|
||||
#pragma mark -
|
||||
|
||||
- (void)refresh {
|
||||
- (void)setPreSelectedRoomId:(NSString *)roomId {
|
||||
_preSelectedRoomId = nil;
|
||||
|
||||
if (roomId) {
|
||||
// Check whether recents update is in progress
|
||||
if ([_activityIndicator isAnimating]) {
|
||||
// Postpone room details display
|
||||
_preSelectedRoomId = roomId;
|
||||
return;
|
||||
}
|
||||
|
||||
// Look for the room index in recents list
|
||||
NSIndexPath *indexPath = nil;
|
||||
for (NSUInteger index = 0; index < recents.count; index++) {
|
||||
MXEvent *mxEvent = [recents objectAtIndex:index];
|
||||
if ([roomId isEqualToString:mxEvent.room_id]) {
|
||||
indexPath = [NSIndexPath indexPathForRow:index inSection:0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (indexPath) {
|
||||
// Open details view
|
||||
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionMiddle];
|
||||
UITableViewCell *recentCell = [self.tableView cellForRowAtIndexPath:indexPath];
|
||||
[self performSegueWithIdentifier:@"showDetail" sender:recentCell];
|
||||
} else {
|
||||
NSLog(@"We are not able to open room (%@) because it does not appear in recents yet", roomId);
|
||||
// Postpone room details display. We run activity indicator until recents are updated
|
||||
_preSelectedRoomId = roomId;
|
||||
// Start activity indicator
|
||||
[_activityIndicator startAnimating];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Internals
|
||||
|
||||
- (void)configureView {
|
||||
[_activityIndicator startAnimating];
|
||||
|
||||
MatrixHandler *mxHandler = [MatrixHandler sharedHandler];
|
||||
if ([mxHandler isInitialSyncDone] || [mxHandler isLogged] == NO) {
|
||||
// Update recents
|
||||
if (mxHandler.mxData) {
|
||||
self.recents = mxHandler.mxData.recents;
|
||||
recents = mxHandler.mxData.recents;
|
||||
} else {
|
||||
self.recents = nil;
|
||||
recents = nil;
|
||||
}
|
||||
|
||||
// Reload table
|
||||
[self.tableView reloadData];
|
||||
[_activityIndicator stopAnimating];
|
||||
|
||||
// Check whether a room is preselected
|
||||
if (_preSelectedRoomId) {
|
||||
self.preSelectedRoomId = _preSelectedRoomId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +167,7 @@
|
||||
if ([@"isInitialSyncDone" isEqualToString:keyPath])
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self refresh];
|
||||
[self configureView];
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -124,7 +177,7 @@
|
||||
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
||||
if ([[segue identifier] isEqualToString:@"showDetail"]) {
|
||||
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
|
||||
MXEvent *mxEvent = self.recents[indexPath.row];
|
||||
MXEvent *mxEvent = recents[indexPath.row];
|
||||
|
||||
UIViewController *controller;
|
||||
if ([[segue destinationViewController] isKindOfClass:[UINavigationController class]]) {
|
||||
@@ -149,7 +202,7 @@
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||||
return self.recents.count;
|
||||
return recents.count;
|
||||
}
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
@@ -160,9 +213,9 @@
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
RecentsTableViewCell *cell = (RecentsTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"RecentsCell" forIndexPath:indexPath];
|
||||
|
||||
MXEvent *mxEvent = self.recents[indexPath.row];
|
||||
MXEvent *mxEvent = recents[indexPath.row];
|
||||
MatrixHandler *mxHandler = [MatrixHandler sharedHandler];
|
||||
MXRoomData *mxRoomData = [[mxHandler mxData] getRoomData:mxEvent.room_id];
|
||||
MXRoomData *mxRoomData = [mxHandler.mxData getRoomData:mxEvent.room_id];
|
||||
|
||||
cell.roomTitle.text = [mxRoomData displayname];
|
||||
cell.lastEventDescription.text = [mxHandler displayTextFor:mxEvent inDetailMode:YES];
|
||||
@@ -186,10 +239,18 @@
|
||||
|
||||
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
if (editingStyle == UITableViewCellEditingStyleDelete) {
|
||||
// [self.recents removeObjectAtIndex:indexPath.row];
|
||||
// [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
|
||||
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
|
||||
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
|
||||
// TODO enable the following code when "leave" will be available in SDK
|
||||
// // Leave the selected room
|
||||
// MXEvent *mxEvent = recents[indexPath.row];
|
||||
// [[MatrixHandler sharedHandler].mxSession leave:mxEvent.room_id success:^{
|
||||
// // Refresh table display
|
||||
// [recents removeObjectAtIndex:indexPath.row];
|
||||
// [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
|
||||
// } failure:^(NSError *error) {
|
||||
// NSLog(@"Failed to leave room (%@) failed: %@", mxEvent.room_id, error);
|
||||
// //Alert user
|
||||
// [[AppDelegate theDelegate] showErrorAsAlert:error];
|
||||
// }];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
BOOL isFirstDisplay;
|
||||
}
|
||||
|
||||
@property (weak, nonatomic) IBOutlet UINavigationItem *roomNavItem;
|
||||
@property (weak, nonatomic) IBOutlet UITableView *tableView;
|
||||
@property (weak, nonatomic) IBOutlet UIView *controlView;
|
||||
@property (weak, nonatomic) IBOutlet UIButton *optionBtn;
|
||||
@@ -69,12 +70,15 @@
|
||||
- (void)configureView {
|
||||
// Update room data
|
||||
if (self.roomId) {
|
||||
self.mxRoomData = [[[MatrixHandler sharedHandler] mxData] getRoomData:self.roomId];
|
||||
self.mxRoomData = [[MatrixHandler sharedHandler].mxData getRoomData:self.roomId];
|
||||
} else {
|
||||
self.mxRoomData = nil;
|
||||
}
|
||||
|
||||
[self.tableView reloadData];
|
||||
|
||||
// Update room title
|
||||
self.roomNavItem.title = self.mxRoomData.displayname;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad {
|
||||
|
||||
Reference in New Issue
Block a user