2017-03-23 16:48:05 +00:00
|
|
|
|
/*
|
|
|
|
|
Copyright 2017 Vector Creations 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#import "MasterTabBarController.h"
|
|
|
|
|
|
|
|
|
|
#import "UnifiedSearchViewController.h"
|
|
|
|
|
|
|
|
|
|
#import "RecentsDataSource.h"
|
|
|
|
|
|
|
|
|
|
#import "AppDelegate.h"
|
|
|
|
|
|
2017-04-18 13:55:51 +00:00
|
|
|
|
#import "MXRoom+Riot.h"
|
|
|
|
|
|
2017-03-23 16:48:05 +00:00
|
|
|
|
@interface MasterTabBarController ()
|
|
|
|
|
{
|
|
|
|
|
// Array of `MXSession` instances.
|
|
|
|
|
NSMutableArray *mxSessionArray;
|
|
|
|
|
|
|
|
|
|
// Tell whether the authentication screen is preparing.
|
|
|
|
|
BOOL isAuthViewControllerPreparing;
|
|
|
|
|
|
|
|
|
|
// Observer that checks when the Authentification view controller has gone.
|
|
|
|
|
id authViewControllerObserver;
|
|
|
|
|
|
|
|
|
|
// The parameters to pass to the Authentification view controller.
|
|
|
|
|
NSDictionary *authViewControllerRegistrationParameters;
|
|
|
|
|
|
2017-04-06 12:27:45 +00:00
|
|
|
|
// The recents data source shared between all the view controllers of the tab bar.
|
|
|
|
|
RecentsDataSource *recentsDataSource;
|
2017-03-23 16:48:05 +00:00
|
|
|
|
|
|
|
|
|
// The current unified search screen if any
|
|
|
|
|
UnifiedSearchViewController *unifiedSearchViewController;
|
|
|
|
|
|
|
|
|
|
// Current alert (if any).
|
|
|
|
|
MXKAlert *currentAlert;
|
2017-04-14 15:01:44 +00:00
|
|
|
|
|
2017-04-18 13:55:51 +00:00
|
|
|
|
// Observer kMXRoomSummaryDidChangeNotification to keep updated the missed discussion count
|
|
|
|
|
id mxRoomSummaryDidChangeObserver;
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation MasterTabBarController
|
|
|
|
|
|
|
|
|
|
- (void)viewDidLoad
|
|
|
|
|
{
|
|
|
|
|
[super viewDidLoad];
|
|
|
|
|
// Do any additional setup after loading the view, typically from a nib.
|
|
|
|
|
|
2017-04-06 12:27:45 +00:00
|
|
|
|
// Retrieve the all view controllers
|
2017-03-24 16:19:55 +00:00
|
|
|
|
_homeViewController = [self.viewControllers objectAtIndex:TABBAR_HOME_INDEX];
|
2017-04-06 12:27:45 +00:00
|
|
|
|
_favouritesViewController = [self.viewControllers objectAtIndex:TABBAR_FAVOURITES_INDEX];
|
|
|
|
|
_peopleViewController = [self.viewControllers objectAtIndex:TABBAR_PEOPLE_INDEX];
|
|
|
|
|
_roomsViewController = [self.viewControllers objectAtIndex:TABBAR_ROOMS_INDEX];
|
|
|
|
|
|
|
|
|
|
// Sanity check
|
|
|
|
|
NSAssert(_homeViewController && _favouritesViewController && _peopleViewController && _roomsViewController, @"Something wrong in Main.storyboard");
|
|
|
|
|
|
|
|
|
|
self.tabBar.tintColor = kRiotColorGreen;
|
2017-03-23 16:48:05 +00:00
|
|
|
|
|
2017-04-14 15:01:44 +00:00
|
|
|
|
// Adjust the display of the icons in the tabbar.
|
|
|
|
|
for (UITabBarItem *tabBarItem in self.tabBar.items)
|
|
|
|
|
{
|
|
|
|
|
tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 16:48:05 +00:00
|
|
|
|
// Initialize here the data sources if a matrix session has been already set.
|
|
|
|
|
[self initializeDataSources];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)viewDidAppear:(BOOL)animated
|
|
|
|
|
{
|
|
|
|
|
[super viewDidAppear:animated];
|
|
|
|
|
|
|
|
|
|
// Check whether we're not logged in
|
|
|
|
|
if (![MXKAccountManager sharedManager].accounts.count)
|
|
|
|
|
{
|
|
|
|
|
[self showAuthenticationScreen];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Check whether the user has been already prompted to send crash reports.
|
|
|
|
|
// (Check whether 'enableCrashReport' flag has been set once)
|
|
|
|
|
if (![[NSUserDefaults standardUserDefaults] objectForKey:@"enableCrashReport"])
|
|
|
|
|
{
|
|
|
|
|
[self promptUserBeforeUsingGoogleAnalytics];
|
|
|
|
|
}
|
2017-04-14 15:01:44 +00:00
|
|
|
|
|
|
|
|
|
// Observe missed notifications
|
2017-04-18 13:55:51 +00:00
|
|
|
|
mxRoomSummaryDidChangeObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMXRoomSummaryDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
|
2017-04-14 15:01:44 +00:00
|
|
|
|
|
|
|
|
|
[self refreshHomeTabBadge];
|
|
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
[self refreshHomeTabBadge];
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (unifiedSearchViewController)
|
|
|
|
|
{
|
|
|
|
|
[unifiedSearchViewController destroy];
|
|
|
|
|
unifiedSearchViewController = nil;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-14 15:01:44 +00:00
|
|
|
|
- (void)viewDidDisappear:(BOOL)animated
|
|
|
|
|
{
|
|
|
|
|
[super viewDidDisappear:animated];
|
|
|
|
|
|
2017-04-18 13:55:51 +00:00
|
|
|
|
if (mxRoomSummaryDidChangeObserver)
|
2017-04-14 15:01:44 +00:00
|
|
|
|
{
|
2017-04-18 13:55:51 +00:00
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:mxRoomSummaryDidChangeObserver];
|
|
|
|
|
mxRoomSummaryDidChangeObserver = nil;
|
2017-04-14 15:01:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 16:48:05 +00:00
|
|
|
|
- (void)dealloc
|
|
|
|
|
{
|
|
|
|
|
mxSessionArray = nil;
|
|
|
|
|
|
|
|
|
|
_homeViewController = nil;
|
2017-04-06 12:27:45 +00:00
|
|
|
|
_favouritesViewController = nil;
|
|
|
|
|
_peopleViewController = nil;
|
|
|
|
|
_roomsViewController = nil;
|
2017-03-23 16:48:05 +00:00
|
|
|
|
|
|
|
|
|
if (currentAlert)
|
|
|
|
|
{
|
|
|
|
|
[currentAlert dismiss:NO];
|
|
|
|
|
currentAlert = nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (authViewControllerObserver)
|
|
|
|
|
{
|
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:authViewControllerObserver];
|
|
|
|
|
authViewControllerObserver = nil;
|
|
|
|
|
}
|
2017-04-14 15:01:44 +00:00
|
|
|
|
|
2017-04-18 13:55:51 +00:00
|
|
|
|
if (mxRoomSummaryDidChangeObserver)
|
2017-04-14 15:01:44 +00:00
|
|
|
|
{
|
2017-04-18 13:55:51 +00:00
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:mxRoomSummaryDidChangeObserver];
|
|
|
|
|
mxRoomSummaryDidChangeObserver = nil;
|
2017-04-14 15:01:44 +00:00
|
|
|
|
}
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
|
- (NSArray*)mxSessions
|
|
|
|
|
{
|
|
|
|
|
return [NSArray arrayWithArray:mxSessionArray];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)initializeDataSources
|
|
|
|
|
{
|
|
|
|
|
MXSession *mainSession = mxSessionArray.firstObject;
|
|
|
|
|
|
|
|
|
|
if (mainSession)
|
|
|
|
|
{
|
|
|
|
|
// Init the recents data source
|
2017-04-06 12:27:45 +00:00
|
|
|
|
recentsDataSource = [[RecentsDataSource alloc] initWithMatrixSession:mainSession];
|
|
|
|
|
|
|
|
|
|
[_homeViewController displayList:recentsDataSource];
|
|
|
|
|
[_favouritesViewController displayList:recentsDataSource];
|
2017-04-11 07:36:22 +00:00
|
|
|
|
[_peopleViewController displayList:recentsDataSource];
|
2017-04-06 12:27:45 +00:00
|
|
|
|
[_roomsViewController displayList:recentsDataSource];
|
2017-03-23 16:48:05 +00:00
|
|
|
|
|
|
|
|
|
// Check whether there are others sessions
|
|
|
|
|
NSArray* mxSessions = self.mxSessions;
|
|
|
|
|
if (mxSessions.count > 1)
|
|
|
|
|
{
|
|
|
|
|
for (MXSession *mxSession in mxSessions)
|
|
|
|
|
{
|
|
|
|
|
if (mxSession != mainSession)
|
|
|
|
|
{
|
|
|
|
|
// Add the session to the recents data source
|
2017-04-06 12:27:45 +00:00
|
|
|
|
[recentsDataSource addMatrixSession:mxSession];
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)addMatrixSession:(MXSession *)mxSession
|
|
|
|
|
{
|
|
|
|
|
// Check whether the controller's view is loaded into memory.
|
|
|
|
|
if (_homeViewController)
|
|
|
|
|
{
|
|
|
|
|
// Check whether the data sources have been initialized.
|
2017-04-06 12:27:45 +00:00
|
|
|
|
if (!recentsDataSource)
|
2017-03-23 16:48:05 +00:00
|
|
|
|
{
|
|
|
|
|
// Add first the session. The updated sessions list will be used during data sources initialization.
|
|
|
|
|
mxSessionArray = [NSMutableArray array];
|
|
|
|
|
[mxSessionArray addObject:mxSession];
|
|
|
|
|
|
|
|
|
|
// Prepare data sources and return
|
|
|
|
|
[self initializeDataSources];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-04-06 12:27:45 +00:00
|
|
|
|
// Add the session to the existing data sources
|
|
|
|
|
[recentsDataSource addMatrixSession:mxSession];
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!mxSessionArray)
|
|
|
|
|
{
|
|
|
|
|
mxSessionArray = [NSMutableArray array];
|
2017-04-18 13:55:51 +00:00
|
|
|
|
|
|
|
|
|
// Add matrix sessions observer on first added session
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMatrixSessionStateDidChange:) name:kMXSessionStateDidChangeNotification object:nil];
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
[mxSessionArray addObject:mxSession];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)removeMatrixSession:(MXSession *)mxSession
|
|
|
|
|
{
|
2017-04-06 12:27:45 +00:00
|
|
|
|
[recentsDataSource removeMatrixSession:mxSession];
|
2017-03-23 16:48:05 +00:00
|
|
|
|
|
|
|
|
|
// Check whether there are others sessions
|
2017-04-06 12:27:45 +00:00
|
|
|
|
if (!recentsDataSource.mxSessions.count)
|
2017-03-23 16:48:05 +00:00
|
|
|
|
{
|
2017-04-18 13:55:51 +00:00
|
|
|
|
// Remove matrix sessions observer
|
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:kMXSessionStateDidChangeNotification object:nil];
|
|
|
|
|
|
2017-03-23 16:48:05 +00:00
|
|
|
|
[_homeViewController displayList:nil];
|
2017-04-06 12:27:45 +00:00
|
|
|
|
[_favouritesViewController displayList:nil];
|
2017-04-11 07:36:22 +00:00
|
|
|
|
[_peopleViewController displayList:nil];
|
2017-04-06 12:27:45 +00:00
|
|
|
|
[_roomsViewController displayList:nil];
|
|
|
|
|
|
|
|
|
|
[recentsDataSource destroy];
|
|
|
|
|
recentsDataSource = nil;
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[mxSessionArray removeObject:mxSession];
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-18 13:55:51 +00:00
|
|
|
|
- (void)onMatrixSessionStateDidChange:(NSNotification *)notif
|
|
|
|
|
{
|
|
|
|
|
[self refreshHomeTabBadge];
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 16:48:05 +00:00
|
|
|
|
- (void)showAuthenticationScreen
|
|
|
|
|
{
|
|
|
|
|
// Check whether an authentication screen is not already shown or preparing
|
|
|
|
|
if (!self.authViewController && !isAuthViewControllerPreparing)
|
|
|
|
|
{
|
|
|
|
|
isAuthViewControllerPreparing = YES;
|
|
|
|
|
|
|
|
|
|
[[AppDelegate theDelegate] restoreInitialDisplay:^{
|
|
|
|
|
|
|
|
|
|
[self performSegueWithIdentifier:@"showAuth" sender:self];
|
|
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)showAuthenticationScreenWithRegistrationParameters:(NSDictionary *)parameters
|
|
|
|
|
{
|
|
|
|
|
if (self.authViewController)
|
|
|
|
|
{
|
|
|
|
|
NSLog(@"[MasterTabBarController] Universal link: Forward registration parameter to the existing AuthViewController");
|
|
|
|
|
self.authViewController.externalRegistrationParameters = parameters;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NSLog(@"[MasterTabBarController] Universal link: Logout current sessions and open AuthViewController to complete the registration");
|
|
|
|
|
|
|
|
|
|
// Keep a ref on the params
|
|
|
|
|
authViewControllerRegistrationParameters = parameters;
|
|
|
|
|
|
|
|
|
|
// And do a logout out. It will then display AuthViewController
|
|
|
|
|
[[AppDelegate theDelegate] logout];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)selectRoomWithId:(NSString*)roomId andEventId:(NSString*)eventId inMatrixSession:(MXSession*)matrixSession
|
|
|
|
|
{
|
|
|
|
|
if (_selectedRoomId && [_selectedRoomId isEqualToString:roomId]
|
|
|
|
|
&& _selectedEventId && [_selectedEventId isEqualToString:eventId]
|
|
|
|
|
&& _selectedRoomSession && _selectedRoomSession == matrixSession)
|
|
|
|
|
{
|
|
|
|
|
// Nothing to do
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_selectedRoomId = roomId;
|
|
|
|
|
_selectedEventId = eventId;
|
|
|
|
|
_selectedRoomSession = matrixSession;
|
|
|
|
|
|
|
|
|
|
if (roomId && matrixSession)
|
|
|
|
|
{
|
2017-03-28 15:26:50 +00:00
|
|
|
|
[self performSegueWithIdentifier:@"showRoomDetails" sender:self];
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-03-28 15:26:50 +00:00
|
|
|
|
[self releaseSelectedItem];
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)showRoomPreview:(RoomPreviewData *)roomPreviewData
|
|
|
|
|
{
|
|
|
|
|
_selectedRoomPreviewData = roomPreviewData;
|
|
|
|
|
_selectedRoomId = roomPreviewData.roomId;
|
|
|
|
|
_selectedRoomSession = roomPreviewData.mxSession;
|
|
|
|
|
|
2017-03-28 15:26:50 +00:00
|
|
|
|
[self performSegueWithIdentifier:@"showRoomDetails" sender:self];
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-28 15:26:50 +00:00
|
|
|
|
- (void)selectContact:(MXKContact*)contact
|
|
|
|
|
{
|
|
|
|
|
_selectedContact = contact;
|
|
|
|
|
|
|
|
|
|
[self performSegueWithIdentifier:@"showContactDetails" sender:self];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)releaseSelectedItem
|
2017-03-23 16:48:05 +00:00
|
|
|
|
{
|
|
|
|
|
_selectedRoomId = nil;
|
|
|
|
|
_selectedEventId = nil;
|
|
|
|
|
_selectedRoomSession = nil;
|
|
|
|
|
|
|
|
|
|
if (_currentRoomViewController)
|
|
|
|
|
{
|
|
|
|
|
// If the displayed data is not a preview, let the manager release the room data source
|
|
|
|
|
// (except if the view controller has the room data source ownership).
|
|
|
|
|
if (!_currentRoomViewController.roomPreviewData && _currentRoomViewController.roomDataSource && !_currentRoomViewController.hasRoomDataSourceOwnership)
|
|
|
|
|
{
|
|
|
|
|
MXSession *mxSession = _currentRoomViewController.roomDataSource.mxSession;
|
|
|
|
|
MXKRoomDataSourceManager *roomDataSourceManager = [MXKRoomDataSourceManager sharedManagerForMatrixSession:mxSession];
|
|
|
|
|
|
|
|
|
|
// Let the manager release live room data sources where the user is in
|
|
|
|
|
[roomDataSourceManager closeRoomDataSource:_currentRoomViewController.roomDataSource forceClose:NO];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[_currentRoomViewController destroy];
|
|
|
|
|
_currentRoomViewController = nil;
|
|
|
|
|
}
|
2017-03-28 15:26:50 +00:00
|
|
|
|
|
|
|
|
|
_selectedContact = nil;
|
|
|
|
|
|
|
|
|
|
if (_currentContactDetailViewController)
|
|
|
|
|
{
|
|
|
|
|
[_currentContactDetailViewController destroy];
|
|
|
|
|
_currentContactDetailViewController = nil;
|
|
|
|
|
}
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-24 16:19:55 +00:00
|
|
|
|
- (void)dismissUnifiedSearch:(BOOL)animated completion:(void (^)(void))completion
|
|
|
|
|
{
|
|
|
|
|
if (unifiedSearchViewController)
|
2017-03-23 16:48:05 +00:00
|
|
|
|
{
|
2017-03-24 16:19:55 +00:00
|
|
|
|
[self.navigationController dismissViewControllerAnimated:animated completion:completion];
|
|
|
|
|
}
|
|
|
|
|
else if (completion)
|
|
|
|
|
{
|
|
|
|
|
completion();
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-18 13:55:51 +00:00
|
|
|
|
- (NSUInteger)missedDiscussionsCount
|
|
|
|
|
{
|
|
|
|
|
NSUInteger roomCount = 0;
|
|
|
|
|
|
|
|
|
|
// Considering all the current sessions.
|
|
|
|
|
for (MXSession *session in mxSessionArray)
|
|
|
|
|
{
|
|
|
|
|
// Sum all the rooms with missed notifications.
|
|
|
|
|
for (MXRoomSummary *roomSummary in session.roomsSummaries)
|
|
|
|
|
{
|
|
|
|
|
NSUInteger notificationCount = roomSummary.notificationCount;
|
|
|
|
|
|
|
|
|
|
// Ignore the regular notification count if the room is in 'mentions only" mode at the Riot level.
|
|
|
|
|
if (roomSummary.room.isMentionsOnly)
|
|
|
|
|
{
|
|
|
|
|
// Only the highlighted missed messages must be considered here.
|
|
|
|
|
notificationCount = roomSummary.highlightCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (notificationCount)
|
|
|
|
|
{
|
|
|
|
|
roomCount ++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add the invites count
|
|
|
|
|
roomCount += [session invitedRooms].count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return roomCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSUInteger)missedHighlightDiscussionsCount
|
|
|
|
|
{
|
|
|
|
|
NSUInteger roomCount = 0;
|
|
|
|
|
|
|
|
|
|
for (MXSession *session in mxSessionArray)
|
|
|
|
|
{
|
|
|
|
|
roomCount += [session missedHighlightDiscussionsCount];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return roomCount;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-24 16:19:55 +00:00
|
|
|
|
#pragma mark -
|
2017-03-23 16:48:05 +00:00
|
|
|
|
|
|
|
|
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
|
|
|
|
|
{
|
2017-03-28 15:26:50 +00:00
|
|
|
|
if ([[segue identifier] isEqualToString:@"showRoomDetails"] || [[segue identifier] isEqualToString:@"showContactDetails"])
|
2017-03-23 16:48:05 +00:00
|
|
|
|
{
|
2017-03-28 15:26:50 +00:00
|
|
|
|
UINavigationController *navigationController = [segue destinationViewController];
|
|
|
|
|
|
|
|
|
|
// Release existing Room view controller (if any)
|
|
|
|
|
if (_currentRoomViewController)
|
2017-03-23 16:48:05 +00:00
|
|
|
|
{
|
2017-03-28 15:26:50 +00:00
|
|
|
|
// If the displayed data is not a preview, let the manager release the room data source
|
|
|
|
|
// (except if the view controller has the room data source ownership).
|
|
|
|
|
if (!_currentRoomViewController.roomPreviewData && _currentRoomViewController.roomDataSource && !_currentRoomViewController.hasRoomDataSourceOwnership)
|
|
|
|
|
{
|
|
|
|
|
MXSession *mxSession = _currentRoomViewController.roomDataSource.mxSession;
|
|
|
|
|
MXKRoomDataSourceManager *roomDataSourceManager = [MXKRoomDataSourceManager sharedManagerForMatrixSession:mxSession];
|
|
|
|
|
|
|
|
|
|
[roomDataSourceManager closeRoomDataSource:_currentRoomViewController.roomDataSource forceClose:NO];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[_currentRoomViewController destroy];
|
|
|
|
|
_currentRoomViewController = nil;
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
2017-03-28 15:26:50 +00:00
|
|
|
|
else if (_currentContactDetailViewController)
|
2017-03-23 16:48:05 +00:00
|
|
|
|
{
|
2017-03-28 15:26:50 +00:00
|
|
|
|
[_currentContactDetailViewController destroy];
|
|
|
|
|
_currentContactDetailViewController = nil;
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-28 15:26:50 +00:00
|
|
|
|
if ([[segue identifier] isEqualToString:@"showRoomDetails"])
|
2017-03-23 16:48:05 +00:00
|
|
|
|
{
|
2017-03-28 15:26:50 +00:00
|
|
|
|
// Replace the rootviewcontroller with a room view controller
|
|
|
|
|
// Get the RoomViewController from the storyboard
|
|
|
|
|
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
|
|
|
|
|
_currentRoomViewController = [storyboard instantiateViewControllerWithIdentifier:@"RoomViewControllerStoryboardId"];
|
2017-03-23 16:48:05 +00:00
|
|
|
|
|
2017-03-28 15:26:50 +00:00
|
|
|
|
navigationController.viewControllers = @[_currentRoomViewController];
|
2017-03-23 16:48:05 +00:00
|
|
|
|
|
|
|
|
|
if (!_selectedRoomPreviewData)
|
|
|
|
|
{
|
|
|
|
|
MXKRoomDataSource *roomDataSource;
|
|
|
|
|
|
2017-03-27 13:59:51 +00:00
|
|
|
|
// Check whether an event has been selected from messages or files search tab.
|
|
|
|
|
MXEvent *selectedSearchEvent = unifiedSearchViewController.selectedSearchEvent;
|
|
|
|
|
MXSession *selectedSearchEventSession = unifiedSearchViewController.selectedSearchEventSession;
|
2017-03-23 16:48:05 +00:00
|
|
|
|
|
2017-03-27 13:59:51 +00:00
|
|
|
|
if (!selectedSearchEvent)
|
2017-03-23 16:48:05 +00:00
|
|
|
|
{
|
|
|
|
|
if (!_selectedEventId)
|
|
|
|
|
{
|
|
|
|
|
// LIVE: Show the room live timeline managed by MXKRoomDataSourceManager
|
|
|
|
|
MXKRoomDataSourceManager *roomDataSourceManager = [MXKRoomDataSourceManager sharedManagerForMatrixSession:_selectedRoomSession];
|
|
|
|
|
roomDataSource = [roomDataSourceManager roomDataSourceForRoom:_selectedRoomId create:YES];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Open the room on the requested event
|
|
|
|
|
roomDataSource = [[RoomDataSource alloc] initWithRoomId:_selectedRoomId initialEventId:_selectedEventId andMatrixSession:_selectedRoomSession];
|
|
|
|
|
[roomDataSource finalizeInitialization];
|
|
|
|
|
|
|
|
|
|
// Give the data source ownership to the room view controller.
|
|
|
|
|
_currentRoomViewController.hasRoomDataSourceOwnership = YES;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-27 13:59:51 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Search result: Create a temp timeline from the selected event
|
|
|
|
|
roomDataSource = [[RoomDataSource alloc] initWithRoomId:selectedSearchEvent.roomId initialEventId:selectedSearchEvent.eventId andMatrixSession:selectedSearchEventSession];
|
|
|
|
|
[roomDataSource finalizeInitialization];
|
|
|
|
|
|
|
|
|
|
// Give the data source ownership to the room view controller.
|
|
|
|
|
_currentRoomViewController.hasRoomDataSourceOwnership = YES;
|
|
|
|
|
}
|
2017-03-23 16:48:05 +00:00
|
|
|
|
|
|
|
|
|
[_currentRoomViewController displayRoom:roomDataSource];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
[_currentRoomViewController displayRoomPreview:_selectedRoomPreviewData];
|
|
|
|
|
_selectedRoomPreviewData = nil;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-28 15:26:50 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Replace the rootviewcontroller with a contact details view controller
|
|
|
|
|
_currentContactDetailViewController = [ContactDetailsViewController contactDetailsViewController];
|
|
|
|
|
_currentContactDetailViewController.enableVoipCall = NO;
|
|
|
|
|
_currentContactDetailViewController.contact = _selectedContact;
|
|
|
|
|
|
|
|
|
|
navigationController.viewControllers = @[_currentContactDetailViewController];
|
|
|
|
|
}
|
2017-03-23 16:48:05 +00:00
|
|
|
|
|
|
|
|
|
if (self.splitViewController)
|
|
|
|
|
{
|
|
|
|
|
// Refresh selected cell without scrolling the selected cell (We suppose it's visible here)
|
2017-03-27 13:59:51 +00:00
|
|
|
|
[self refreshCurrentSelectedCell:NO];
|
2017-03-23 16:48:05 +00:00
|
|
|
|
|
2017-03-28 15:26:50 +00:00
|
|
|
|
if (_currentRoomViewController)
|
2017-03-23 16:48:05 +00:00
|
|
|
|
{
|
2017-03-28 15:26:50 +00:00
|
|
|
|
_currentRoomViewController.navigationItem.leftBarButtonItem = self.splitViewController.displayModeButtonItem;
|
|
|
|
|
_currentRoomViewController.navigationItem.leftItemsSupplementBackButton = YES;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_currentContactDetailViewController.navigationItem.leftBarButtonItem = self.splitViewController.displayModeButtonItem;
|
|
|
|
|
_currentContactDetailViewController.navigationItem.leftItemsSupplementBackButton = YES;
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Keep ref on destinationViewController
|
|
|
|
|
[super prepareForSegue:segue sender:sender];
|
|
|
|
|
|
|
|
|
|
if ([[segue identifier] isEqualToString:@"showAuth"])
|
|
|
|
|
{
|
|
|
|
|
// Keep ref on the authentification view controller while it is displayed
|
|
|
|
|
// ie until we get the notification about a new account
|
|
|
|
|
_authViewController = segue.destinationViewController;
|
|
|
|
|
isAuthViewControllerPreparing = NO;
|
|
|
|
|
|
|
|
|
|
authViewControllerObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMXKAccountManagerDidAddAccountNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
|
|
|
|
|
|
|
|
|
|
_authViewController = nil;
|
|
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:authViewControllerObserver];
|
|
|
|
|
authViewControllerObserver = nil;
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
// Forward parameters if any
|
|
|
|
|
if (authViewControllerRegistrationParameters)
|
|
|
|
|
{
|
|
|
|
|
_authViewController.externalRegistrationParameters = authViewControllerRegistrationParameters;
|
|
|
|
|
authViewControllerRegistrationParameters = nil;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if ([[segue identifier] isEqualToString:@"showUnifiedSearch"])
|
|
|
|
|
{
|
|
|
|
|
unifiedSearchViewController= segue.destinationViewController;
|
|
|
|
|
|
|
|
|
|
for (MXSession *session in mxSessionArray)
|
|
|
|
|
{
|
|
|
|
|
[unifiedSearchViewController addMatrixSession:session];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-28 15:26:50 +00:00
|
|
|
|
|
|
|
|
|
// Hide back button title
|
2017-03-28 16:17:14 +00:00
|
|
|
|
self.navigationController.topViewController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-27 13:59:51 +00:00
|
|
|
|
// Made the actual selected view controller update its selected cell.
|
|
|
|
|
- (void)refreshCurrentSelectedCell:(BOOL)forceVisible
|
|
|
|
|
{
|
|
|
|
|
UIViewController *selectedViewController = self.selectedViewController;
|
|
|
|
|
|
|
|
|
|
if ([selectedViewController respondsToSelector:@selector(refreshCurrentSelectedCell:)])
|
|
|
|
|
{
|
|
|
|
|
[(id)selectedViewController refreshCurrentSelectedCell:forceVisible];
|
|
|
|
|
}}
|
|
|
|
|
|
2017-04-14 15:01:44 +00:00
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
|
- (void)refreshHomeTabBadge
|
|
|
|
|
{
|
2017-04-18 13:55:51 +00:00
|
|
|
|
NSUInteger count = [self missedDiscussionsCount];
|
2017-04-14 15:01:44 +00:00
|
|
|
|
if (count)
|
|
|
|
|
{
|
|
|
|
|
NSString *badgeValue;
|
|
|
|
|
|
|
|
|
|
if (count > 1000)
|
|
|
|
|
{
|
|
|
|
|
CGFloat value = count / 1000.0;
|
2017-04-18 13:55:51 +00:00
|
|
|
|
badgeValue = [NSString stringWithFormat:NSLocalizedStringFromTable(@"large_badge_value_k_format", @"Vector", nil), value];
|
2017-04-14 15:01:44 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
badgeValue = [NSString stringWithFormat:@"%tu", count];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.tabBar.items[TABBAR_HOME_INDEX].badgeValue = badgeValue;
|
2017-04-18 13:55:51 +00:00
|
|
|
|
|
2017-04-19 07:18:54 +00:00
|
|
|
|
if ([UITabBarItem instancesRespondToSelector:@selector(setBadgeColor:)])
|
2017-04-18 13:55:51 +00:00
|
|
|
|
{
|
2017-04-19 07:18:54 +00:00
|
|
|
|
if (self.missedHighlightDiscussionsCount)
|
|
|
|
|
{
|
|
|
|
|
self.tabBar.items[TABBAR_HOME_INDEX].badgeColor = kRiotColorPinkRed;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
self.tabBar.items[TABBAR_HOME_INDEX].badgeColor = kRiotColorGreen;
|
|
|
|
|
}
|
2017-04-18 13:55:51 +00:00
|
|
|
|
}
|
2017-04-14 15:01:44 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
self.tabBar.items[TABBAR_HOME_INDEX].badgeValue = nil;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 16:48:05 +00:00
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
|
|
- (void)promptUserBeforeUsingGoogleAnalytics
|
|
|
|
|
{
|
|
|
|
|
NSLog(@"[MasterTabBarController]: Invite the user to send crash reports");
|
|
|
|
|
|
|
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
|
|
|
|
|
|
|
[currentAlert dismiss:NO];
|
|
|
|
|
|
|
|
|
|
NSString *appDisplayName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];
|
|
|
|
|
|
|
|
|
|
currentAlert = [[MXKAlert alloc] initWithTitle:[NSString stringWithFormat:NSLocalizedStringFromTable(@"google_analytics_use_prompt", @"Vector", nil), appDisplayName]
|
|
|
|
|
message:nil
|
|
|
|
|
style:MXKAlertStyleAlert];
|
|
|
|
|
|
|
|
|
|
currentAlert.cancelButtonIndex = [currentAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"no"]
|
|
|
|
|
style:MXKAlertActionStyleDefault
|
|
|
|
|
handler:^(MXKAlert *alert) {
|
|
|
|
|
|
|
|
|
|
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"enableCrashReport"];
|
|
|
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
|
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
|
{
|
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
|
strongSelf->currentAlert = nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
[currentAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"yes"]
|
|
|
|
|
style:MXKAlertActionStyleDefault
|
|
|
|
|
handler:^(MXKAlert *alert) {
|
|
|
|
|
|
|
|
|
|
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"enableCrashReport"];
|
|
|
|
|
[[NSUserDefaults standardUserDefaults] synchronize];
|
|
|
|
|
|
|
|
|
|
if (weakSelf)
|
|
|
|
|
{
|
|
|
|
|
__strong __typeof(weakSelf)strongSelf = weakSelf;
|
|
|
|
|
strongSelf->currentAlert = nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[[AppDelegate theDelegate] startGoogleAnalytics];
|
|
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
currentAlert.mxkAccessibilityIdentifier = @"HomeVCUseGoogleAnalyticsAlert";
|
|
|
|
|
[currentAlert showInViewController:self];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|