2017-03-23 16:48:05 +00:00
|
|
|
|
/*
|
|
|
|
|
Copyright 2017 Vector Creations Ltd
|
2018-07-23 16:06:53 +00:00
|
|
|
|
Copyright 2018 New Vector Ltd
|
|
|
|
|
|
2017-03-23 16:48:05 +00:00
|
|
|
|
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 "RecentsDataSource.h"
|
2017-12-12 15:03:26 +00:00
|
|
|
|
#import "GroupsDataSource.h"
|
2017-03-23 16:48:05 +00:00
|
|
|
|
|
|
|
|
|
|
2017-04-18 13:55:51 +00:00
|
|
|
|
#import "MXRoom+Riot.h"
|
2017-08-22 07:46:53 +00:00
|
|
|
|
#import "MXSession+Riot.h"
|
2017-04-18 13:55:51 +00:00
|
|
|
|
|
2020-05-04 17:59:11 +00:00
|
|
|
|
#import "SettingsViewController.h"
|
|
|
|
|
#import "SecurityViewController.h"
|
|
|
|
|
|
2021-10-26 15:42:33 +00:00
|
|
|
|
#import "GeneratedInterface-Swift.h"
|
2018-07-02 12:51:47 +00:00
|
|
|
|
|
2022-01-12 17:11:29 +00:00
|
|
|
|
@interface MasterTabBarController () <UITabBarControllerDelegate>
|
2017-03-23 16:48:05 +00:00
|
|
|
|
{
|
|
|
|
|
// Array of `MXSession` instances.
|
2022-01-12 17:11:29 +00:00
|
|
|
|
NSMutableArray<MXSession*> *mxSessionArray;
|
2017-03-23 16:48:05 +00:00
|
|
|
|
|
2017-04-06 12:27:45 +00:00
|
|
|
|
// The recents data source shared between all the view controllers of the tab bar.
|
|
|
|
|
RecentsDataSource *recentsDataSource;
|
2021-05-20 19:42:04 +00:00
|
|
|
|
|
2017-03-23 16:48:05 +00:00
|
|
|
|
// Current alert (if any).
|
2017-07-14 14:41:25 +00:00
|
|
|
|
UIAlertController *currentAlert;
|
2017-07-21 09:28:17 +00:00
|
|
|
|
|
|
|
|
|
// Keep reference on the pushed view controllers to release them correctly
|
|
|
|
|
NSMutableArray *childViewControllers;
|
2017-08-11 14:56:09 +00:00
|
|
|
|
|
2019-01-11 09:32:56 +00:00
|
|
|
|
// Observe kThemeServiceDidChangeThemeNotification to handle user interface theme change.
|
|
|
|
|
id kThemeServiceDidChangeThemeNotificationObserver;
|
2017-12-12 15:03:26 +00:00
|
|
|
|
|
|
|
|
|
// The groups data source
|
|
|
|
|
GroupsDataSource *groupsDataSource;
|
2021-07-15 12:10:01 +00:00
|
|
|
|
|
2021-08-02 07:57:30 +00:00
|
|
|
|
// Custom title view of the navigation bar
|
|
|
|
|
MainTitleView *titleView;
|
2021-10-06 20:06:00 +00:00
|
|
|
|
|
|
|
|
|
id spaceNotificationCounterDidUpdateNotificationCountObserver;
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 10:37:29 +00:00
|
|
|
|
@property(nonatomic,getter=isHidden) BOOL hidden;
|
|
|
|
|
|
2022-01-12 17:11:29 +00:00
|
|
|
|
@property (nonatomic, readwrite) OnboardingCoordinatorBridgePresenter *onboardingCoordinatorBridgePresenter;
|
|
|
|
|
|
|
|
|
|
// Tell whether the onboarding screen is preparing.
|
|
|
|
|
@property (nonatomic, readwrite) BOOL isOnboardingCoordinatorPreparing;
|
|
|
|
|
@property (nonatomic, readwrite) BOOL isOnboardingInProgress;
|
|
|
|
|
|
|
|
|
|
// Observer that checks when the Authentication view controller has gone.
|
|
|
|
|
@property (nonatomic, readwrite) id addAccountObserver;
|
|
|
|
|
@property (nonatomic, readwrite) id removeAccountObserver;
|
|
|
|
|
|
|
|
|
|
// The parameters to pass to the Authentication view controller.
|
|
|
|
|
@property (nonatomic, readwrite) NSDictionary *authViewControllerRegistrationParameters;
|
|
|
|
|
@property (nonatomic, readwrite) MXCredentials *softLogoutCredentials;
|
|
|
|
|
|
|
|
|
|
@property (nonatomic) BOOL reviewSessionAlertHasBeenDisplayed;
|
2020-04-30 13:28:43 +00:00
|
|
|
|
|
2021-12-06 12:52:33 +00:00
|
|
|
|
/**
|
|
|
|
|
A flag to indicate that the analytics prompt should be shown during `-addMatrixSession:`.
|
|
|
|
|
*/
|
|
|
|
|
@property(nonatomic) BOOL presentAnalyticsPromptOnAddSession;
|
|
|
|
|
|
2017-03-23 16:48:05 +00:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation MasterTabBarController
|
|
|
|
|
|
2021-05-20 19:42:04 +00:00
|
|
|
|
#pragma mark - Properties override
|
|
|
|
|
|
|
|
|
|
- (HomeViewController *)homeViewController
|
|
|
|
|
{
|
2021-08-31 06:51:05 +00:00
|
|
|
|
UIViewController *wrapperVC = [self viewControllerForClass:HomeViewControllerWithBannerWrapperViewController.class];
|
|
|
|
|
return [(HomeViewControllerWithBannerWrapperViewController *)wrapperVC homeViewController];
|
2021-05-20 19:42:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (FavouritesViewController *)favouritesViewController
|
|
|
|
|
{
|
|
|
|
|
return (FavouritesViewController*)[self viewControllerForClass:FavouritesViewController.class];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (PeopleViewController *)peopleViewController
|
|
|
|
|
{
|
|
|
|
|
return (PeopleViewController*)[self viewControllerForClass:PeopleViewController.class];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (RoomsViewController *)roomsViewController
|
|
|
|
|
{
|
|
|
|
|
return (RoomsViewController*)[self viewControllerForClass:RoomsViewController.class];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (GroupsViewController *)groupsViewController
|
|
|
|
|
{
|
|
|
|
|
return (GroupsViewController*)[self viewControllerForClass:GroupsViewController.class];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - Life cycle
|
|
|
|
|
|
2017-03-23 16:48:05 +00:00
|
|
|
|
- (void)viewDidLoad
|
|
|
|
|
{
|
|
|
|
|
[super viewDidLoad];
|
|
|
|
|
// Do any additional setup after loading the view, typically from a nib.
|
2020-05-05 07:17:47 +00:00
|
|
|
|
|
2021-07-16 14:20:28 +00:00
|
|
|
|
self.delegate = self;
|
|
|
|
|
|
2022-02-17 16:50:02 +00:00
|
|
|
|
self.isOnboardingInProgress = NO;
|
2020-09-15 14:48:35 +00:00
|
|
|
|
|
2022-02-17 16:50:02 +00:00
|
|
|
|
// Note: UITabBarViewController should not be embed in a UINavigationController (https://github.com/vector-im/riot-ios/issues/3086)
|
2020-05-05 07:17:47 +00:00
|
|
|
|
[self vc_removeBackTitle];
|
2017-04-14 15:01:44 +00:00
|
|
|
|
|
2021-07-15 12:10:01 +00:00
|
|
|
|
[self setupTitleView];
|
2021-09-28 05:40:01 +00:00
|
|
|
|
titleView.titleLabel.text = [VectorL10n titleHome];
|
2021-07-15 12:10:01 +00:00
|
|
|
|
|
2017-07-21 09:28:17 +00:00
|
|
|
|
childViewControllers = [NSMutableArray array];
|
2021-09-20 08:10:27 +00:00
|
|
|
|
|
|
|
|
|
MXWeakify(self);
|
2021-10-06 20:06:00 +00:00
|
|
|
|
spaceNotificationCounterDidUpdateNotificationCountObserver = [[NSNotificationCenter defaultCenter] addObserverForName:MXSpaceNotificationCounter.didUpdateNotificationCount object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
|
2021-09-20 08:10:27 +00:00
|
|
|
|
MXStrongifyAndReturnIfNil(self);
|
|
|
|
|
[self updateSideMenuNotifcationIcon];
|
|
|
|
|
}];
|
2017-08-11 14:56:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)userInterfaceThemeDidChange
|
|
|
|
|
{
|
2021-07-15 12:10:01 +00:00
|
|
|
|
id<Theme> theme = ThemeService.shared.theme;
|
|
|
|
|
[theme applyStyleOnNavigationBar:self.navigationController.navigationBar];
|
2018-11-29 16:31:41 +00:00
|
|
|
|
|
2021-07-15 12:10:01 +00:00
|
|
|
|
[theme applyStyleOnTabBar:self.tabBar];
|
2017-08-11 14:56:09 +00:00
|
|
|
|
|
2021-07-15 12:10:01 +00:00
|
|
|
|
self.view.backgroundColor = theme.backgroundColor;
|
2021-08-02 07:57:30 +00:00
|
|
|
|
[titleView updateWithTheme:theme];
|
2021-07-15 12:10:01 +00:00
|
|
|
|
|
2017-08-11 14:56:09 +00:00
|
|
|
|
[self setNeedsStatusBarAppearanceUpdate];
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-08 15:02:25 +00:00
|
|
|
|
- (UIViewController *)childViewControllerForStatusBarStyle
|
2017-08-11 14:56:09 +00:00
|
|
|
|
{
|
2020-04-08 15:02:25 +00:00
|
|
|
|
return self.selectedViewController;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (UIViewController *)childViewControllerForStatusBarHidden
|
|
|
|
|
{
|
|
|
|
|
return self.selectedViewController;
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-27 10:37:29 +00:00
|
|
|
|
- (void)viewWillAppear:(BOOL)animated
|
|
|
|
|
{
|
|
|
|
|
[super viewWillAppear:animated];
|
|
|
|
|
|
|
|
|
|
// Show the tab bar view controller content only when a user is logged in.
|
|
|
|
|
self.hidden = ([MXKAccountManager sharedManager].accounts.count == 0);
|
2021-04-23 20:26:54 +00:00
|
|
|
|
|
2021-05-20 19:42:04 +00:00
|
|
|
|
if (!kThemeServiceDidChangeThemeNotificationObserver)
|
|
|
|
|
{
|
|
|
|
|
// Observe user interface theme change.
|
|
|
|
|
kThemeServiceDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kThemeServiceDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
|
|
|
|
|
|
|
|
|
|
[self userInterfaceThemeDidChange];
|
|
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
[self userInterfaceThemeDidChange];
|
|
|
|
|
}
|
2017-04-27 10:37:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 16:48:05 +00:00
|
|
|
|
- (void)viewDidAppear:(BOOL)animated
|
|
|
|
|
{
|
2021-06-03 08:30:07 +00:00
|
|
|
|
MXLogDebug(@"[MasterTabBarController] viewDidAppear");
|
2017-03-23 16:48:05 +00:00
|
|
|
|
[super viewDidAppear:animated];
|
|
|
|
|
|
|
|
|
|
// Check whether we're not logged in
|
2019-07-19 12:25:45 +00:00
|
|
|
|
BOOL authIsShown = NO;
|
2017-03-23 16:48:05 +00:00
|
|
|
|
if (![MXKAccountManager sharedManager].accounts.count)
|
|
|
|
|
{
|
2022-01-12 17:11:29 +00:00
|
|
|
|
[self showOnboardingFlow];
|
2019-07-19 12:25:45 +00:00
|
|
|
|
authIsShown = YES;
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
2019-07-19 12:25:45 +00:00
|
|
|
|
else if (![MXKAccountManager sharedManager].activeAccounts.count)
|
|
|
|
|
{
|
|
|
|
|
// Display a login screen if the account is soft logout
|
|
|
|
|
// Note: We support only one account
|
|
|
|
|
MXKAccount *account = [MXKAccountManager sharedManager].accounts.firstObject;
|
|
|
|
|
if (account.isSoftLogout)
|
|
|
|
|
{
|
2022-01-12 17:11:29 +00:00
|
|
|
|
[self showSoftLogoutOnboardingFlowWithCredentials:account.mxCredentials];
|
2019-07-19 12:25:45 +00:00
|
|
|
|
authIsShown = YES;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!authIsShown)
|
2017-03-23 16:48:05 +00:00
|
|
|
|
{
|
2021-10-27 13:51:46 +00:00
|
|
|
|
// Check whether the user should be prompted to send analytics.
|
2021-11-19 10:00:24 +00:00
|
|
|
|
if (Analytics.shared.shouldShowAnalyticsPrompt)
|
2017-03-23 16:48:05 +00:00
|
|
|
|
{
|
2021-12-06 12:52:33 +00:00
|
|
|
|
MXSession *mxSession = self.mxSessions.firstObject;
|
|
|
|
|
if (mxSession)
|
|
|
|
|
{
|
|
|
|
|
[self promptUserBeforeUsingAnalyticsForSession:mxSession];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
self.presentAnalyticsPromptOnAddSession = YES;
|
|
|
|
|
}
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
2017-04-14 15:01:44 +00:00
|
|
|
|
|
2017-04-28 12:06:58 +00:00
|
|
|
|
[self refreshTabBarBadges];
|
2017-07-21 09:28:17 +00:00
|
|
|
|
|
|
|
|
|
// Release properly pushed and/or presented view controller
|
|
|
|
|
if (childViewControllers.count)
|
|
|
|
|
{
|
|
|
|
|
for (id viewController in childViewControllers)
|
|
|
|
|
{
|
|
|
|
|
if ([viewController isKindOfClass:[UINavigationController class]])
|
|
|
|
|
{
|
|
|
|
|
UINavigationController *navigationController = (UINavigationController*)viewController;
|
|
|
|
|
for (id subViewController in navigationController.viewControllers)
|
|
|
|
|
{
|
|
|
|
|
if ([subViewController respondsToSelector:@selector(destroy)])
|
|
|
|
|
{
|
|
|
|
|
[subViewController destroy];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if ([viewController respondsToSelector:@selector(destroy)])
|
|
|
|
|
{
|
|
|
|
|
[viewController destroy];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[childViewControllers removeAllObjects];
|
|
|
|
|
}
|
2020-04-30 13:28:43 +00:00
|
|
|
|
|
2020-07-10 19:28:57 +00:00
|
|
|
|
[[AppDelegate theDelegate] checkAppVersion];
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-14 15:01:44 +00:00
|
|
|
|
- (void)viewDidDisappear:(BOOL)animated
|
|
|
|
|
{
|
|
|
|
|
[super viewDidDisappear:animated];
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 16:48:05 +00:00
|
|
|
|
- (void)dealloc
|
|
|
|
|
{
|
|
|
|
|
mxSessionArray = nil;
|
|
|
|
|
|
|
|
|
|
if (currentAlert)
|
|
|
|
|
{
|
2017-07-14 14:41:25 +00:00
|
|
|
|
[currentAlert dismissViewControllerAnimated:NO completion:nil];
|
2017-03-23 16:48:05 +00:00
|
|
|
|
currentAlert = nil;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-12 17:11:29 +00:00
|
|
|
|
if (self.addAccountObserver)
|
2017-03-23 16:48:05 +00:00
|
|
|
|
{
|
2022-01-12 17:11:29 +00:00
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self.addAccountObserver];
|
|
|
|
|
self.addAccountObserver = nil;
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
2022-01-12 17:11:29 +00:00
|
|
|
|
if (self.removeAccountObserver)
|
2019-07-23 14:20:07 +00:00
|
|
|
|
{
|
2022-01-12 17:11:29 +00:00
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self.removeAccountObserver];
|
|
|
|
|
self.removeAccountObserver = nil;
|
2019-07-23 14:20:07 +00:00
|
|
|
|
}
|
2017-07-21 09:28:17 +00:00
|
|
|
|
|
2019-01-11 09:32:56 +00:00
|
|
|
|
if (kThemeServiceDidChangeThemeNotificationObserver)
|
2017-08-11 14:56:09 +00:00
|
|
|
|
{
|
2019-01-11 09:32:56 +00:00
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:kThemeServiceDidChangeThemeNotificationObserver];
|
|
|
|
|
kThemeServiceDidChangeThemeNotificationObserver = nil;
|
2017-08-11 14:56:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-06 20:06:00 +00:00
|
|
|
|
if (spaceNotificationCounterDidUpdateNotificationCountObserver)
|
|
|
|
|
{
|
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:spaceNotificationCounterDidUpdateNotificationCountObserver];
|
|
|
|
|
spaceNotificationCounterDidUpdateNotificationCountObserver = nil;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-21 09:28:17 +00:00
|
|
|
|
childViewControllers = nil;
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-20 19:42:04 +00:00
|
|
|
|
#pragma mark - Public
|
|
|
|
|
|
|
|
|
|
- (void)updateViewControllers:(NSArray<UIViewController*>*)viewControllers
|
|
|
|
|
{
|
|
|
|
|
self.viewControllers = viewControllers;
|
|
|
|
|
|
|
|
|
|
[self initializeDataSources];
|
|
|
|
|
|
2021-09-22 14:57:31 +00:00
|
|
|
|
// Need to be called in case of the controllers have been replaced
|
|
|
|
|
[self.selectedViewController viewWillAppear:NO];
|
|
|
|
|
|
2021-05-20 19:42:04 +00:00
|
|
|
|
// Adjust the display of the icons in the tabbar.
|
|
|
|
|
for (UITabBarItem *tabBarItem in self.tabBar.items)
|
|
|
|
|
{
|
|
|
|
|
if (@available(iOS 13.0, *))
|
|
|
|
|
{
|
|
|
|
|
// Fix iOS 13 misalignment tab bar images. Some titles are nil and other empty strings. Nil title behaves as if a non-empty title was set.
|
|
|
|
|
// Note: However no need to modify imageInsets property on iOS 13.
|
|
|
|
|
tabBarItem.title = @"";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-20 08:10:27 +00:00
|
|
|
|
|
2022-02-23 11:41:05 +00:00
|
|
|
|
titleView.titleLabel.text = [self getTitleForItemViewController:self.selectedViewController];
|
2021-09-22 14:57:31 +00:00
|
|
|
|
|
|
|
|
|
// Need to be called in case of the controllers have been replaced
|
|
|
|
|
[self.selectedViewController viewDidAppear:NO];
|
2021-05-20 19:42:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-22 16:49:22 +00:00
|
|
|
|
- (void)removeTabAt:(MasterTabBarIndex)tag
|
|
|
|
|
{
|
|
|
|
|
NSInteger index = [self indexOfTabItemWithTag:tag];
|
|
|
|
|
if (index != NSNotFound) {
|
|
|
|
|
NSMutableArray<UIViewController*> *viewControllers = [NSMutableArray arrayWithArray:self.viewControllers];
|
|
|
|
|
[viewControllers removeObjectAtIndex:index];
|
|
|
|
|
self.viewControllers = viewControllers;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-05 08:34:42 +00:00
|
|
|
|
- (void)selectTabAtIndex:(MasterTabBarIndex)tabBarIndex
|
|
|
|
|
{
|
|
|
|
|
NSInteger index = [self indexOfTabItemWithTag:tabBarIndex];
|
|
|
|
|
self.selectedIndex = index;
|
2022-02-23 11:41:05 +00:00
|
|
|
|
|
|
|
|
|
titleView.titleLabel.text = [self getTitleForItemViewController:self.selectedViewController];
|
2021-10-05 08:34:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 16:48:05 +00:00
|
|
|
|
#pragma mark -
|
|
|
|
|
|
2021-06-07 13:24:51 +00:00
|
|
|
|
- (NSArray<MXSession*>*)mxSessions
|
2017-03-23 16:48:05 +00:00
|
|
|
|
{
|
|
|
|
|
return [NSArray arrayWithArray:mxSessionArray];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)initializeDataSources
|
|
|
|
|
{
|
|
|
|
|
MXSession *mainSession = mxSessionArray.firstObject;
|
|
|
|
|
|
|
|
|
|
if (mainSession)
|
|
|
|
|
{
|
2021-06-03 08:30:07 +00:00
|
|
|
|
MXLogDebug(@"[MasterTabBarController] initializeDataSources");
|
2017-06-14 15:30:01 +00:00
|
|
|
|
|
2017-03-23 16:48:05 +00:00
|
|
|
|
// Init the recents data source
|
2021-10-04 14:28:21 +00:00
|
|
|
|
RecentsListService *recentsListService = [[RecentsListService alloc] initWithSession:mainSession];
|
|
|
|
|
recentsDataSource = [[RecentsDataSource alloc] initWithMatrixSession:mainSession
|
|
|
|
|
recentsListService:recentsListService];
|
2017-04-06 12:27:45 +00:00
|
|
|
|
|
2021-05-20 19:42:04 +00:00
|
|
|
|
[self.homeViewController displayList:recentsDataSource];
|
|
|
|
|
[self.favouritesViewController displayList:recentsDataSource];
|
|
|
|
|
[self.peopleViewController displayList:recentsDataSource];
|
|
|
|
|
[self.roomsViewController displayList:recentsDataSource];
|
2017-03-23 16:48:05 +00:00
|
|
|
|
|
2017-06-14 15:30:01 +00:00
|
|
|
|
// Restore the right delegate of the shared recent data source.
|
2021-05-20 19:42:04 +00:00
|
|
|
|
id<MXKDataSourceDelegate> recentsDataSourceDelegate = self.homeViewController;
|
2017-06-14 15:30:01 +00:00
|
|
|
|
RecentsDataSourceMode recentsDataSourceMode = RecentsDataSourceModeHome;
|
2021-05-20 19:42:04 +00:00
|
|
|
|
|
|
|
|
|
NSInteger tabItemTag = self.tabBar.items[self.selectedIndex].tag;
|
|
|
|
|
|
|
|
|
|
switch (tabItemTag)
|
2017-06-14 15:30:01 +00:00
|
|
|
|
{
|
|
|
|
|
case TABBAR_HOME_INDEX:
|
|
|
|
|
break;
|
|
|
|
|
case TABBAR_FAVOURITES_INDEX:
|
2021-05-20 19:42:04 +00:00
|
|
|
|
recentsDataSourceDelegate = self.favouritesViewController;
|
2017-06-14 15:30:01 +00:00
|
|
|
|
recentsDataSourceMode = RecentsDataSourceModeFavourites;
|
|
|
|
|
break;
|
|
|
|
|
case TABBAR_PEOPLE_INDEX:
|
2021-05-20 19:42:04 +00:00
|
|
|
|
recentsDataSourceDelegate = self.peopleViewController;
|
2017-06-14 15:30:01 +00:00
|
|
|
|
recentsDataSourceMode = RecentsDataSourceModePeople;
|
|
|
|
|
break;
|
|
|
|
|
case TABBAR_ROOMS_INDEX:
|
2021-05-20 19:42:04 +00:00
|
|
|
|
recentsDataSourceDelegate = self.roomsViewController;
|
2017-06-14 15:30:01 +00:00
|
|
|
|
recentsDataSourceMode = RecentsDataSourceModeRooms;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
[recentsDataSource setDelegate:recentsDataSourceDelegate andRecentsDataSourceMode:recentsDataSourceMode];
|
|
|
|
|
|
2017-12-12 15:03:26 +00:00
|
|
|
|
// Init the recents data source
|
|
|
|
|
groupsDataSource = [[GroupsDataSource alloc] initWithMatrixSession:mainSession];
|
|
|
|
|
[groupsDataSource finalizeInitialization];
|
2021-05-20 19:42:04 +00:00
|
|
|
|
[self.groupsViewController displayList:groupsDataSource];
|
2017-12-12 15:03:26 +00:00
|
|
|
|
|
2017-03-23 16:48:05 +00:00
|
|
|
|
// Check whether there are others sessions
|
2021-06-07 13:24:51 +00:00
|
|
|
|
NSArray<MXSession*>* mxSessions = self.mxSessions;
|
2017-03-23 16:48:05 +00:00
|
|
|
|
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
|
|
|
|
|
{
|
2021-06-07 14:20:49 +00:00
|
|
|
|
if ([mxSessionArray containsObject:mxSession])
|
|
|
|
|
{
|
|
|
|
|
MXLogDebug(@"MasterTabBarController already has %@ in mxSessionArray", mxSession)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-06 12:52:33 +00:00
|
|
|
|
if (self.presentAnalyticsPromptOnAddSession)
|
|
|
|
|
{
|
|
|
|
|
self.presentAnalyticsPromptOnAddSession = NO;
|
|
|
|
|
[self promptUserBeforeUsingAnalyticsForSession:mxSession];
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 16:48:05 +00:00
|
|
|
|
// Check whether the controller's view is loaded into memory.
|
2021-05-20 19:42:04 +00:00
|
|
|
|
if (self.homeViewController)
|
2017-03-23 16:48:05 +00:00
|
|
|
|
{
|
|
|
|
|
// 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];
|
2020-04-30 13:28:43 +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
|
|
|
|
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];
|
2017-12-12 15:03:26 +00:00
|
|
|
|
|
|
|
|
|
// @TODO: handle multi sessions for groups
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)removeMatrixSession:(MXSession *)mxSession
|
|
|
|
|
{
|
2021-06-07 14:20:49 +00:00
|
|
|
|
if (![mxSessionArray containsObject:mxSession])
|
|
|
|
|
{
|
|
|
|
|
MXLogDebug(@"MasterTabBarController does not contain %@ in mxSessionArray", mxSession)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
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];
|
|
|
|
|
|
2021-05-20 19:42:04 +00:00
|
|
|
|
[self.homeViewController displayList:nil];
|
|
|
|
|
[self.favouritesViewController displayList:nil];
|
|
|
|
|
[self.peopleViewController displayList:nil];
|
|
|
|
|
[self.roomsViewController displayList:nil];
|
2017-04-06 12:27:45 +00:00
|
|
|
|
|
|
|
|
|
[recentsDataSource destroy];
|
|
|
|
|
recentsDataSource = nil;
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[mxSessionArray removeObject:mxSession];
|
2017-12-12 15:03:26 +00:00
|
|
|
|
|
|
|
|
|
// @TODO: handle multi sessions for groups
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-18 13:55:51 +00:00
|
|
|
|
- (void)onMatrixSessionStateDidChange:(NSNotification *)notif
|
|
|
|
|
{
|
2017-04-28 12:06:58 +00:00
|
|
|
|
[self refreshTabBarBadges];
|
2017-04-18 13:55:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-12 17:11:29 +00:00
|
|
|
|
// TODO: Manage the onboarding coordinator at the AppCoordinator level
|
|
|
|
|
- (void)presentOnboardingFlow
|
2021-05-20 19:42:04 +00:00
|
|
|
|
{
|
2022-01-12 17:11:29 +00:00
|
|
|
|
OnboardingCoordinatorBridgePresenterParameters *parameters = [[OnboardingCoordinatorBridgePresenterParameters alloc] init];
|
|
|
|
|
// Forward parameters if any
|
|
|
|
|
if (self.authViewControllerRegistrationParameters)
|
|
|
|
|
{
|
|
|
|
|
parameters.externalRegistrationParameters = self.authViewControllerRegistrationParameters;
|
|
|
|
|
self.authViewControllerRegistrationParameters = nil;
|
|
|
|
|
}
|
|
|
|
|
if (self.softLogoutCredentials)
|
|
|
|
|
{
|
|
|
|
|
parameters.softLogoutCredentials = self.softLogoutCredentials;
|
|
|
|
|
self.softLogoutCredentials = nil;
|
|
|
|
|
}
|
2021-05-20 19:42:04 +00:00
|
|
|
|
|
2022-01-12 17:11:29 +00:00
|
|
|
|
MXWeakify(self);
|
|
|
|
|
OnboardingCoordinatorBridgePresenter *onboardingCoordinatorBridgePresenter = [[OnboardingCoordinatorBridgePresenter alloc] initWith:parameters];
|
|
|
|
|
onboardingCoordinatorBridgePresenter.completion = ^{
|
|
|
|
|
MXStrongifyAndReturnIfNil(self);
|
|
|
|
|
[self.onboardingCoordinatorBridgePresenter dismissWithAnimated:YES completion:nil];
|
|
|
|
|
self.onboardingCoordinatorBridgePresenter = nil;
|
|
|
|
|
|
2022-02-17 16:50:02 +00:00
|
|
|
|
self.isOnboardingInProgress = NO; // Must be set before calling didCompleteAuthentication
|
2022-01-12 17:11:29 +00:00
|
|
|
|
[self.masterTabBarDelegate masterTabBarControllerDidCompleteAuthentication:self];
|
|
|
|
|
};
|
2021-05-20 19:42:04 +00:00
|
|
|
|
|
2022-01-12 17:11:29 +00:00
|
|
|
|
[onboardingCoordinatorBridgePresenter presentFrom:self animated:NO];
|
2021-05-20 19:42:04 +00:00
|
|
|
|
|
2022-01-12 17:11:29 +00:00
|
|
|
|
self.onboardingCoordinatorBridgePresenter = onboardingCoordinatorBridgePresenter;
|
|
|
|
|
self.isOnboardingCoordinatorPreparing = NO;
|
2021-05-20 19:42:04 +00:00
|
|
|
|
|
2022-01-12 17:11:29 +00:00
|
|
|
|
self.addAccountObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMXKAccountManagerDidAddAccountNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
|
|
|
|
|
MXStrongifyAndReturnIfNil(self);
|
2022-02-07 12:26:47 +00:00
|
|
|
|
|
|
|
|
|
// What was this doing? This should probably happen elsewhere
|
2022-01-12 17:11:29 +00:00
|
|
|
|
// self.onboardingCoordinatorBridgePresenter = nil;
|
2021-05-20 19:42:04 +00:00
|
|
|
|
|
2022-01-12 17:11:29 +00:00
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self.addAccountObserver];
|
|
|
|
|
self.addAccountObserver = nil;
|
2021-05-20 19:42:04 +00:00
|
|
|
|
}];
|
|
|
|
|
|
2022-01-12 17:11:29 +00:00
|
|
|
|
self.removeAccountObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMXKAccountManagerDidRemoveAccountNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
|
|
|
|
|
MXStrongifyAndReturnIfNil(self);
|
2021-05-20 19:42:04 +00:00
|
|
|
|
// The user has cleared data for their soft logged out account
|
2022-02-07 12:26:47 +00:00
|
|
|
|
|
|
|
|
|
// What was this doing? This should probably happen elsewhere
|
2022-01-12 17:11:29 +00:00
|
|
|
|
// self.onboardingCoordinatorBridgePresenter = nil;
|
2021-05-20 19:42:04 +00:00
|
|
|
|
|
2022-01-12 17:11:29 +00:00
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self.removeAccountObserver];
|
|
|
|
|
self.removeAccountObserver = nil;
|
2021-05-20 19:42:04 +00:00
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-12 17:11:29 +00:00
|
|
|
|
- (void)showOnboardingFlow
|
2017-03-23 16:48:05 +00:00
|
|
|
|
{
|
2021-06-03 08:30:07 +00:00
|
|
|
|
MXLogDebug(@"[MasterTabBarController] showAuthenticationScreen");
|
2017-10-30 15:39:58 +00:00
|
|
|
|
|
2017-03-23 16:48:05 +00:00
|
|
|
|
// Check whether an authentication screen is not already shown or preparing
|
2022-01-12 17:11:29 +00:00
|
|
|
|
if (!self.onboardingCoordinatorBridgePresenter && !self.isOnboardingCoordinatorPreparing)
|
2017-03-23 16:48:05 +00:00
|
|
|
|
{
|
2022-01-12 17:11:29 +00:00
|
|
|
|
self.isOnboardingCoordinatorPreparing = YES;
|
|
|
|
|
self.isOnboardingInProgress = YES;
|
2017-03-23 16:48:05 +00:00
|
|
|
|
|
2020-05-04 17:59:11 +00:00
|
|
|
|
[self resetReviewSessionsFlags];
|
|
|
|
|
|
2017-03-23 16:48:05 +00:00
|
|
|
|
[[AppDelegate theDelegate] restoreInitialDisplay:^{
|
2021-05-20 19:42:04 +00:00
|
|
|
|
|
2022-01-12 17:11:29 +00:00
|
|
|
|
[self presentOnboardingFlow];
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-12 17:11:29 +00:00
|
|
|
|
/**
|
|
|
|
|
Sets up authentication with parameters detected in a universal link. For example
|
|
|
|
|
https://app.element.io/#/register/?hs_url=matrix.example.com&is_url=identity.example.com
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
- (void)showOnboardingFlowWithRegistrationParameters:(NSDictionary *)parameters
|
2017-03-23 16:48:05 +00:00
|
|
|
|
{
|
2022-01-12 17:11:29 +00:00
|
|
|
|
if (self.onboardingCoordinatorBridgePresenter)
|
2017-03-23 16:48:05 +00:00
|
|
|
|
{
|
2021-06-03 08:30:07 +00:00
|
|
|
|
MXLogDebug(@"[MasterTabBarController] Universal link: Forward registration parameter to the existing AuthViewController");
|
2022-01-12 17:11:29 +00:00
|
|
|
|
[self.onboardingCoordinatorBridgePresenter updateWithExternalRegistrationParameters:parameters];
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-06-03 08:30:07 +00:00
|
|
|
|
MXLogDebug(@"[MasterTabBarController] Universal link: Prompt to logout current sessions and open AuthViewController to complete the registration");
|
2017-03-23 16:48:05 +00:00
|
|
|
|
|
|
|
|
|
// Keep a ref on the params
|
2022-01-12 17:11:29 +00:00
|
|
|
|
self.authViewControllerRegistrationParameters = parameters;
|
2017-03-23 16:48:05 +00:00
|
|
|
|
|
2018-04-17 19:39:31 +00:00
|
|
|
|
// Prompt to logout. It will then display AuthViewController if the user is logged out.
|
|
|
|
|
[[AppDelegate theDelegate] logoutWithConfirmation:YES completion:^(BOOL isLoggedOut) {
|
|
|
|
|
if (!isLoggedOut)
|
|
|
|
|
{
|
|
|
|
|
// Reset temporary params
|
2022-01-12 17:11:29 +00:00
|
|
|
|
self.authViewControllerRegistrationParameters = nil;
|
2018-04-17 19:39:31 +00:00
|
|
|
|
}
|
|
|
|
|
}];
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-12 17:11:29 +00:00
|
|
|
|
- (void)showSoftLogoutOnboardingFlowWithCredentials:(MXCredentials*)credentials;
|
2019-07-19 12:25:45 +00:00
|
|
|
|
{
|
2021-06-03 08:30:07 +00:00
|
|
|
|
MXLogDebug(@"[MasterTabBarController] showAuthenticationScreenAfterSoftLogout");
|
2019-07-19 12:25:45 +00:00
|
|
|
|
|
2022-01-12 17:11:29 +00:00
|
|
|
|
self.softLogoutCredentials = credentials;
|
2019-07-19 12:25:45 +00:00
|
|
|
|
|
|
|
|
|
// Check whether an authentication screen is not already shown or preparing
|
2022-01-12 17:11:29 +00:00
|
|
|
|
if (!self.onboardingCoordinatorBridgePresenter && !self.isOnboardingCoordinatorPreparing)
|
2019-07-19 12:25:45 +00:00
|
|
|
|
{
|
2022-01-12 17:11:29 +00:00
|
|
|
|
self.isOnboardingCoordinatorPreparing = YES;
|
|
|
|
|
self.isOnboardingInProgress = YES;
|
2019-07-19 12:25:45 +00:00
|
|
|
|
|
|
|
|
|
[[AppDelegate theDelegate] restoreInitialDisplay:^{
|
|
|
|
|
|
2022-01-12 17:11:29 +00:00
|
|
|
|
[self presentOnboardingFlow];
|
2019-07-19 12:25:45 +00:00
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 09:40:18 +00:00
|
|
|
|
- (void)selectRoomWithParameters:(RoomNavigationParameters*)paramaters completion:(void (^)(void))completion
|
2017-03-23 16:48:05 +00:00
|
|
|
|
{
|
2021-10-05 14:24:58 +00:00
|
|
|
|
[self releaseSelectedItem];
|
2017-03-23 16:48:05 +00:00
|
|
|
|
|
2021-10-12 17:10:30 +00:00
|
|
|
|
_selectedRoomId = paramaters.roomId;
|
|
|
|
|
_selectedEventId = paramaters.eventId;
|
|
|
|
|
_selectedRoomSession = paramaters.mxSession;
|
2017-03-23 16:48:05 +00:00
|
|
|
|
|
2021-10-12 17:10:30 +00:00
|
|
|
|
[self.masterTabBarDelegate masterTabBarController:self didSelectRoomWithParameters:paramaters completion:completion];
|
2021-10-05 08:34:42 +00:00
|
|
|
|
|
2021-10-08 14:06:23 +00:00
|
|
|
|
[self refreshSelectedControllerSelectedCellIfNeeded];
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 12:47:17 +00:00
|
|
|
|
- (void)selectRoomPreviewWithParameters:(RoomPreviewNavigationParameters*)parameters completion:(void (^)(void))completion
|
2017-03-23 16:48:05 +00:00
|
|
|
|
{
|
2021-10-05 14:24:58 +00:00
|
|
|
|
[self releaseSelectedItem];
|
|
|
|
|
|
2021-10-12 17:10:30 +00:00
|
|
|
|
RoomPreviewData *roomPreviewData = parameters.previewData;
|
|
|
|
|
|
2017-03-23 16:48:05 +00:00
|
|
|
|
_selectedRoomPreviewData = roomPreviewData;
|
|
|
|
|
_selectedRoomId = roomPreviewData.roomId;
|
|
|
|
|
_selectedRoomSession = roomPreviewData.mxSession;
|
|
|
|
|
|
2021-10-12 17:10:30 +00:00
|
|
|
|
[self.masterTabBarDelegate masterTabBarController:self didSelectRoomPreviewWithParameters:parameters completion:completion];
|
2017-03-28 15:26:50 +00:00
|
|
|
|
|
2021-10-08 14:06:23 +00:00
|
|
|
|
[self refreshSelectedControllerSelectedCellIfNeeded];
|
2020-09-07 08:01:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-28 15:26:50 +00:00
|
|
|
|
- (void)selectContact:(MXKContact*)contact
|
2021-10-20 13:55:46 +00:00
|
|
|
|
{
|
2021-10-21 08:00:37 +00:00
|
|
|
|
ScreenPresentationParameters *presentationParameters = [[ScreenPresentationParameters alloc] initWithRestoreInitialDisplay:YES stackAboveVisibleViews:NO];
|
2021-10-20 13:55:46 +00:00
|
|
|
|
|
|
|
|
|
[self selectContact:contact withPresentationParameters:presentationParameters];
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 08:00:37 +00:00
|
|
|
|
- (void)selectContact:(MXKContact*)contact withPresentationParameters:(ScreenPresentationParameters*)presentationParameters
|
2020-09-07 08:01:06 +00:00
|
|
|
|
{
|
2021-10-05 14:24:58 +00:00
|
|
|
|
[self releaseSelectedItem];
|
2020-09-07 08:01:06 +00:00
|
|
|
|
|
2017-03-28 15:26:50 +00:00
|
|
|
|
_selectedContact = contact;
|
2020-09-07 08:01:06 +00:00
|
|
|
|
|
2021-10-20 13:55:46 +00:00
|
|
|
|
[self.masterTabBarDelegate masterTabBarController:self didSelectContact:contact withPresentationParameters:presentationParameters];
|
2020-09-07 08:01:06 +00:00
|
|
|
|
|
2021-10-08 14:06:23 +00:00
|
|
|
|
[self refreshSelectedControllerSelectedCellIfNeeded];
|
2017-03-28 15:26:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-12 15:03:26 +00:00
|
|
|
|
- (void)selectGroup:(MXGroup*)group inMatrixSession:(MXSession*)matrixSession
|
2021-10-20 13:55:46 +00:00
|
|
|
|
{
|
2021-10-21 08:00:37 +00:00
|
|
|
|
ScreenPresentationParameters *presentationParameters = [[ScreenPresentationParameters alloc] initWithRestoreInitialDisplay:YES stackAboveVisibleViews:NO];
|
2021-10-20 13:55:46 +00:00
|
|
|
|
|
|
|
|
|
[self selectGroup:group inMatrixSession:matrixSession presentationParameters:presentationParameters];
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-21 08:00:37 +00:00
|
|
|
|
- (void)selectGroup:(MXGroup*)group inMatrixSession:(MXSession*)matrixSession presentationParameters:(ScreenPresentationParameters*)presentationParameters
|
2017-12-12 15:03:26 +00:00
|
|
|
|
{
|
2021-10-05 14:24:58 +00:00
|
|
|
|
[self releaseSelectedItem];
|
|
|
|
|
|
2017-12-12 15:03:26 +00:00
|
|
|
|
_selectedGroup = group;
|
|
|
|
|
_selectedGroupSession = matrixSession;
|
|
|
|
|
|
2021-10-20 13:55:46 +00:00
|
|
|
|
[self.masterTabBarDelegate masterTabBarController:self didSelectGroup:group inMatrixSession:matrixSession presentationParameters:presentationParameters];
|
2020-09-07 08:01:06 +00:00
|
|
|
|
|
2021-10-08 14:06:23 +00:00
|
|
|
|
[self refreshSelectedControllerSelectedCellIfNeeded];
|
2017-12-12 15:03:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-28 15:26:50 +00:00
|
|
|
|
- (void)releaseSelectedItem
|
2017-03-23 16:48:05 +00:00
|
|
|
|
{
|
|
|
|
|
_selectedRoomId = nil;
|
|
|
|
|
_selectedEventId = nil;
|
|
|
|
|
_selectedRoomSession = nil;
|
2018-08-09 14:30:31 +00:00
|
|
|
|
_selectedRoomPreviewData = nil;
|
2017-03-23 16:48:05 +00:00
|
|
|
|
|
2017-03-28 15:26:50 +00:00
|
|
|
|
_selectedContact = nil;
|
|
|
|
|
|
2017-12-12 15:03:26 +00:00
|
|
|
|
_selectedGroup = nil;
|
2021-10-05 08:34:42 +00:00
|
|
|
|
_selectedGroupSession = nil;
|
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)
|
|
|
|
|
{
|
2020-06-25 08:23:24 +00:00
|
|
|
|
roomCount += [session vc_missedDiscussionsCount];
|
2017-04-18 13:55:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return roomCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSUInteger)missedHighlightDiscussionsCount
|
|
|
|
|
{
|
|
|
|
|
NSUInteger roomCount = 0;
|
|
|
|
|
|
|
|
|
|
for (MXSession *session in mxSessionArray)
|
|
|
|
|
{
|
|
|
|
|
roomCount += [session missedHighlightDiscussionsCount];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return roomCount;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-20 19:42:04 +00:00
|
|
|
|
- (UIViewController*)viewControllerForClass:(Class)klass
|
2017-03-23 16:48:05 +00:00
|
|
|
|
{
|
2021-05-20 19:42:04 +00:00
|
|
|
|
UIViewController *foundViewController;
|
2020-09-07 08:01:06 +00:00
|
|
|
|
|
2021-05-20 19:42:04 +00:00
|
|
|
|
NSInteger viewControllerIndex = [self.viewControllers indexOfObjectPassingTest:^BOOL(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
|
|
if ([obj isKindOfClass:klass])
|
2020-09-07 08:01:06 +00:00
|
|
|
|
{
|
2021-05-20 19:42:04 +00:00
|
|
|
|
*stop = YES;
|
|
|
|
|
return YES;
|
2017-03-28 15:26:50 +00:00
|
|
|
|
}
|
2021-05-20 19:42:04 +00:00
|
|
|
|
return NO;
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
if (viewControllerIndex != NSNotFound)
|
2017-03-23 16:48:05 +00:00
|
|
|
|
{
|
2021-05-20 19:42:04 +00:00
|
|
|
|
foundViewController = self.viewControllers[viewControllerIndex];
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
2017-03-28 15:26:50 +00:00
|
|
|
|
|
2021-05-20 19:42:04 +00:00
|
|
|
|
return foundViewController;
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-02 16:35:29 +00:00
|
|
|
|
- (void)filterRoomsWithParentId:(NSString*)roomParentId
|
|
|
|
|
inMatrixSession:(MXSession*)mxSession
|
|
|
|
|
{
|
2021-08-02 07:57:30 +00:00
|
|
|
|
titleView.subtitleLabel.text = roomParentId ? [mxSession roomSummaryWithRoomId:roomParentId].displayname : nil;
|
2021-07-15 12:10:01 +00:00
|
|
|
|
|
|
|
|
|
recentsDataSource.currentSpace = [mxSession.spaceService getSpaceWithId:roomParentId];
|
2021-09-20 08:10:27 +00:00
|
|
|
|
[self updateSideMenuNotifcationIcon];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)updateSideMenuNotifcationIcon
|
|
|
|
|
{
|
|
|
|
|
BOOL displayNotification = NO;
|
|
|
|
|
|
|
|
|
|
for (MXRoomSummary *summary in recentsDataSource.mxSession.spaceService.rootSpaceSummaries) {
|
|
|
|
|
if (summary.membership == MXMembershipInvite) {
|
|
|
|
|
displayNotification = YES;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!displayNotification) {
|
|
|
|
|
MXSpaceNotificationState *notificationState = [recentsDataSource.mxSession.spaceService.notificationCounter notificationStateForAllSpacesExcept: recentsDataSource.currentSpace.spaceId];
|
|
|
|
|
|
|
|
|
|
if (recentsDataSource.currentSpace)
|
|
|
|
|
{
|
|
|
|
|
MXSpaceNotificationState *homeNotificationState = recentsDataSource.mxSession.spaceService.notificationCounter.homeNotificationState;
|
|
|
|
|
displayNotification = notificationState.groupMissedDiscussionsCount > 0 || notificationState.groupMissedDiscussionsHighlightedCount > 0 || homeNotificationState.allCount > 0 || homeNotificationState.allHighlightCount > 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
displayNotification = notificationState.groupMissedDiscussionsCount > 0 || notificationState.groupMissedDiscussionsHighlightedCount > 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[self.masterTabBarDelegate masterTabBarController:self needsSideMenuIconWithNotification:displayNotification];
|
2021-07-02 16:35:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-20 19:42:04 +00:00
|
|
|
|
#pragma mark -
|
|
|
|
|
|
2021-07-15 12:10:01 +00:00
|
|
|
|
-(void)setupTitleView
|
|
|
|
|
{
|
2021-08-02 07:57:30 +00:00
|
|
|
|
titleView = [MainTitleView new];
|
|
|
|
|
self.navigationItem.titleView = titleView;
|
2021-07-15 12:10:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-21 09:28:17 +00:00
|
|
|
|
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
|
|
|
|
|
{
|
|
|
|
|
// Keep ref on presented view controller
|
|
|
|
|
[childViewControllers addObject:viewControllerToPresent];
|
|
|
|
|
|
|
|
|
|
[super presentViewController:viewControllerToPresent animated:flag completion:completion];
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-08 14:06:23 +00:00
|
|
|
|
- (void)refreshSelectedControllerSelectedCellIfNeeded
|
2021-10-05 08:34:42 +00:00
|
|
|
|
{
|
|
|
|
|
if (self.splitViewController)
|
|
|
|
|
{
|
|
|
|
|
// Refresh selected cell without scrolling the selected cell (We suppose it's visible here)
|
|
|
|
|
[self refreshCurrentSelectedCell:NO];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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-27 10:37:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setHidden:(BOOL)hidden
|
|
|
|
|
{
|
|
|
|
|
_hidden = hidden;
|
|
|
|
|
|
2019-01-11 10:45:27 +00:00
|
|
|
|
[self.view superview].backgroundColor = ThemeService.shared.theme.backgroundColor;
|
2017-04-27 10:37:29 +00:00
|
|
|
|
self.view.hidden = hidden;
|
|
|
|
|
self.navigationController.navigationBar.hidden = hidden;
|
|
|
|
|
}
|
2017-03-27 13:59:51 +00:00
|
|
|
|
|
2022-02-23 11:41:05 +00:00
|
|
|
|
- (NSString*)getTitleForItemViewController:(UIViewController*)itemViewController
|
|
|
|
|
{
|
|
|
|
|
if ([itemViewController conformsToProtocol:@protocol(MasterTabBarItemDisplayProtocol)])
|
|
|
|
|
{
|
|
|
|
|
UIViewController<MasterTabBarItemDisplayProtocol> *masterTabBarItem = (UIViewController<MasterTabBarItemDisplayProtocol>*)itemViewController;
|
|
|
|
|
return masterTabBarItem.masterTabBarItemTitle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-14 15:01:44 +00:00
|
|
|
|
#pragma mark -
|
|
|
|
|
|
2021-04-19 16:53:32 +00:00
|
|
|
|
- (void)refreshTabBarBadges
|
|
|
|
|
{
|
|
|
|
|
// Use a middle dot to signal missed notif in favourites
|
|
|
|
|
if (RiotSettings.shared.homeScreenShowFavouritesTab)
|
2021-03-11 08:01:44 +00:00
|
|
|
|
{
|
2021-09-24 15:50:41 +00:00
|
|
|
|
[self setMissedDiscussionsMark:(recentsDataSource.favoriteMissedDiscussionsCount.numberOfNotified ? @"\u00B7": nil)
|
2021-04-19 16:53:32 +00:00
|
|
|
|
onTabBarItem:TABBAR_FAVOURITES_INDEX
|
2021-09-24 15:50:41 +00:00
|
|
|
|
withBadgeColor:(recentsDataSource.favoriteMissedDiscussionsCount.hasHighlight ? ThemeService.shared.theme.noticeColor : ThemeService.shared.theme.noticeSecondaryColor)];
|
2021-03-11 08:01:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-19 16:53:32 +00:00
|
|
|
|
// Update the badge on People and Rooms tabs
|
|
|
|
|
if (RiotSettings.shared.homeScreenShowPeopleTab)
|
2021-03-11 08:01:44 +00:00
|
|
|
|
{
|
2021-09-24 15:50:41 +00:00
|
|
|
|
if (recentsDataSource.directMissedDiscussionsCount.hasUnsent)
|
2021-04-19 16:53:32 +00:00
|
|
|
|
{
|
|
|
|
|
[self setBadgeValue:@"!"
|
|
|
|
|
onTabBarItem:TABBAR_PEOPLE_INDEX
|
|
|
|
|
withBadgeColor:ThemeService.shared.theme.noticeColor];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-09-24 15:50:41 +00:00
|
|
|
|
[self setMissedDiscussionsCount:recentsDataSource.directMissedDiscussionsCount.numberOfNotified
|
2021-04-19 16:53:32 +00:00
|
|
|
|
onTabBarItem:TABBAR_PEOPLE_INDEX
|
2021-09-24 15:50:41 +00:00
|
|
|
|
withBadgeColor:(recentsDataSource.directMissedDiscussionsCount.hasHighlight ? ThemeService.shared.theme.noticeColor : ThemeService.shared.theme.noticeSecondaryColor)];
|
2021-04-19 16:53:32 +00:00
|
|
|
|
}
|
2021-03-11 08:01:44 +00:00
|
|
|
|
}
|
2021-04-19 16:53:32 +00:00
|
|
|
|
|
|
|
|
|
if (RiotSettings.shared.homeScreenShowRoomsTab)
|
2021-03-11 08:01:44 +00:00
|
|
|
|
{
|
2021-09-24 15:50:41 +00:00
|
|
|
|
if (recentsDataSource.groupMissedDiscussionsCount.hasUnsent)
|
2021-04-19 16:53:32 +00:00
|
|
|
|
{
|
2021-09-24 15:50:41 +00:00
|
|
|
|
[self setMissedDiscussionsCount:recentsDataSource.groupMissedDiscussionsCount.numberOfUnsent
|
2021-04-19 16:53:32 +00:00
|
|
|
|
onTabBarItem:TABBAR_ROOMS_INDEX
|
|
|
|
|
withBadgeColor:ThemeService.shared.theme.noticeColor];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-09-24 15:50:41 +00:00
|
|
|
|
[self setMissedDiscussionsCount:recentsDataSource.groupMissedDiscussionsCount.numberOfNotified
|
2021-04-19 16:53:32 +00:00
|
|
|
|
onTabBarItem:TABBAR_ROOMS_INDEX
|
2021-09-24 15:50:41 +00:00
|
|
|
|
withBadgeColor:(recentsDataSource.groupMissedDiscussionsCount.hasHighlight ? ThemeService.shared.theme.noticeColor : ThemeService.shared.theme.noticeSecondaryColor)];
|
2021-04-19 16:53:32 +00:00
|
|
|
|
}
|
2021-03-11 08:01:44 +00:00
|
|
|
|
}
|
2017-04-28 12:06:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setMissedDiscussionsCount:(NSUInteger)count onTabBarItem:(NSUInteger)index withBadgeColor:(UIColor*)badgeColor
|
2017-04-14 15:01:44 +00:00
|
|
|
|
{
|
2021-03-11 08:01:44 +00:00
|
|
|
|
[self setBadgeValue:count ? [self tabBarBadgeStringValue:count] : nil onTabBarItem:index withBadgeColor:badgeColor];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setBadgeValue:(NSString *)value onTabBarItem:(NSUInteger)index withBadgeColor:(UIColor*)badgeColor
|
|
|
|
|
{
|
2021-04-19 16:53:32 +00:00
|
|
|
|
NSInteger itemIndex = [self indexOfTabItemWithTag:index];
|
|
|
|
|
if (itemIndex != NSNotFound)
|
2017-04-14 15:01:44 +00:00
|
|
|
|
{
|
2021-04-19 16:53:32 +00:00
|
|
|
|
if (value)
|
|
|
|
|
{
|
|
|
|
|
self.tabBar.items[itemIndex].badgeValue = value;
|
|
|
|
|
|
|
|
|
|
self.tabBar.items[itemIndex].badgeColor = badgeColor;
|
|
|
|
|
|
|
|
|
|
[self.tabBar.items[itemIndex] setBadgeTextAttributes:@{
|
|
|
|
|
NSForegroundColorAttributeName: ThemeService.shared.theme.baseTextPrimaryColor
|
|
|
|
|
}
|
|
|
|
|
forState:UIControlStateNormal];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
self.tabBar.items[itemIndex].badgeValue = nil;
|
|
|
|
|
}
|
2017-04-28 12:06:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-14 08:06:36 +00:00
|
|
|
|
- (void)setMissedDiscussionsMark:(NSString*)mark onTabBarItem:(NSUInteger)index withBadgeColor:(UIColor*)badgeColor
|
|
|
|
|
{
|
2021-04-19 16:53:32 +00:00
|
|
|
|
NSInteger itemIndex = [self indexOfTabItemWithTag:index];
|
|
|
|
|
if (itemIndex != NSNotFound)
|
2017-06-14 08:06:36 +00:00
|
|
|
|
{
|
2021-04-19 16:53:32 +00:00
|
|
|
|
if (mark)
|
|
|
|
|
{
|
|
|
|
|
self.tabBar.items[itemIndex].badgeValue = mark;
|
|
|
|
|
|
|
|
|
|
self.tabBar.items[itemIndex].badgeColor = badgeColor;
|
|
|
|
|
|
|
|
|
|
[self.tabBar.items[itemIndex] setBadgeTextAttributes:@{
|
|
|
|
|
NSForegroundColorAttributeName: ThemeService.shared.theme.baseTextPrimaryColor
|
|
|
|
|
}
|
|
|
|
|
forState:UIControlStateNormal];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
self.tabBar.items[itemIndex].badgeValue = nil;
|
|
|
|
|
}
|
2017-06-14 08:06:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-28 12:06:58 +00:00
|
|
|
|
- (NSString*)tabBarBadgeStringValue:(NSUInteger)count
|
|
|
|
|
{
|
|
|
|
|
NSString *badgeValue;
|
|
|
|
|
|
|
|
|
|
if (count > 1000)
|
|
|
|
|
{
|
|
|
|
|
CGFloat value = count / 1000.0;
|
2021-09-28 05:40:01 +00:00
|
|
|
|
badgeValue = [VectorL10n largeBadgeValueKFormat:value];
|
2017-04-28 12:06:58 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
badgeValue = [NSString stringWithFormat:@"%tu", count];
|
2017-04-14 15:01:44 +00:00
|
|
|
|
}
|
2017-04-28 12:06:58 +00:00
|
|
|
|
|
|
|
|
|
return badgeValue;
|
2017-04-14 15:01:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-19 16:53:32 +00:00
|
|
|
|
- (NSInteger)indexOfTabItemWithTag:(NSUInteger)tag
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0 ; i < self.tabBar.items.count ; i++)
|
|
|
|
|
{
|
|
|
|
|
if (self.tabBar.items[i].tag == tag)
|
|
|
|
|
{
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NSNotFound;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-28 12:06:58 +00:00
|
|
|
|
#pragma mark -
|
2017-03-23 16:48:05 +00:00
|
|
|
|
|
2021-12-06 12:52:33 +00:00
|
|
|
|
- (void)promptUserBeforeUsingAnalyticsForSession:(MXSession *)mxSession
|
2017-03-23 16:48:05 +00:00
|
|
|
|
{
|
2021-12-07 12:09:26 +00:00
|
|
|
|
// Analytics aren't collected on iOS 12 & 13.
|
|
|
|
|
if (@available(iOS 14.0, *))
|
|
|
|
|
{
|
|
|
|
|
MXLogDebug(@"[MasterTabBarController]: Invite the user to send analytics");
|
|
|
|
|
[self.masterTabBarDelegate masterTabBarController:self shouldPresentAnalyticsPromptForMatrixSession:mxSession];
|
|
|
|
|
}
|
2017-03-23 16:48:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 17:59:11 +00:00
|
|
|
|
#pragma mark - Review session
|
|
|
|
|
|
|
|
|
|
- (void)presentVerifyCurrentSessionAlertIfNeededWithSession:(MXSession*)session
|
|
|
|
|
{
|
2020-09-25 11:06:34 +00:00
|
|
|
|
if (RiotSettings.shared.hideVerifyThisSessionAlert
|
|
|
|
|
|| self.reviewSessionAlertHasBeenDisplayed
|
2022-01-12 17:11:29 +00:00
|
|
|
|
|| self.isOnboardingInProgress)
|
2020-05-04 17:59:11 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
self.reviewSessionAlertHasBeenDisplayed = YES;
|
|
|
|
|
[self presentVerifyCurrentSessionAlertWithSession:session];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)presentVerifyCurrentSessionAlertWithSession:(MXSession*)session
|
|
|
|
|
{
|
2021-06-03 08:30:07 +00:00
|
|
|
|
MXLogDebug(@"[MasterTabBarController] presentVerifyCurrentSessionAlertWithSession");
|
2020-09-29 15:02:02 +00:00
|
|
|
|
|
2020-05-04 17:59:11 +00:00
|
|
|
|
[currentAlert dismissViewControllerAnimated:NO completion:nil];
|
|
|
|
|
|
2021-09-28 05:40:01 +00:00
|
|
|
|
UIAlertController *alert = [UIAlertController alertControllerWithTitle:[VectorL10n keyVerificationSelfVerifyCurrentSessionAlertTitle]
|
|
|
|
|
message:[VectorL10n keyVerificationSelfVerifyCurrentSessionAlertMessage]
|
2020-05-04 17:59:11 +00:00
|
|
|
|
preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
|
|
2021-09-28 05:40:01 +00:00
|
|
|
|
[alert addAction:[UIAlertAction actionWithTitle:[VectorL10n keyVerificationSelfVerifyCurrentSessionAlertValidateAction]
|
2020-05-04 17:59:11 +00:00
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
[[AppDelegate theDelegate] presentCompleteSecurityForSession:session];
|
|
|
|
|
}]];
|
|
|
|
|
|
2021-09-28 05:40:01 +00:00
|
|
|
|
[alert addAction:[UIAlertAction actionWithTitle:[VectorL10n later]
|
2020-05-04 17:59:11 +00:00
|
|
|
|
style:UIAlertActionStyleCancel
|
|
|
|
|
handler:nil]];
|
|
|
|
|
|
2021-09-28 05:40:01 +00:00
|
|
|
|
[alert addAction:[UIAlertAction actionWithTitle:[VectorL10n doNotAskAgain]
|
2020-05-04 17:59:11 +00:00
|
|
|
|
style:UIAlertActionStyleDestructive
|
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
RiotSettings.shared.hideVerifyThisSessionAlert = YES;
|
|
|
|
|
}]];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[self presentViewController:alert animated:YES completion:nil];
|
|
|
|
|
|
|
|
|
|
currentAlert = alert;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)presentReviewUnverifiedSessionsAlertIfNeededWithSession:(MXSession*)session
|
|
|
|
|
{
|
|
|
|
|
if (RiotSettings.shared.hideReviewSessionsAlert || self.reviewSessionAlertHasBeenDisplayed)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-26 13:39:00 +00:00
|
|
|
|
NSArray<MXDeviceInfo*> *devices = [session.crypto devicesForUser:session.myUserId].allValues;
|
2020-05-04 17:59:11 +00:00
|
|
|
|
|
|
|
|
|
BOOL isUserHasOneUnverifiedDevice = NO;
|
|
|
|
|
|
|
|
|
|
for (MXDeviceInfo *device in devices)
|
|
|
|
|
{
|
2020-05-08 05:52:33 +00:00
|
|
|
|
if (!device.trustLevel.isCrossSigningVerified)
|
2020-05-04 17:59:11 +00:00
|
|
|
|
{
|
|
|
|
|
isUserHasOneUnverifiedDevice = YES;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isUserHasOneUnverifiedDevice)
|
|
|
|
|
{
|
|
|
|
|
self.reviewSessionAlertHasBeenDisplayed = YES;
|
|
|
|
|
[self presentReviewUnverifiedSessionsAlertWithSession:session];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)presentReviewUnverifiedSessionsAlertWithSession:(MXSession*)session
|
|
|
|
|
{
|
2021-06-03 08:30:07 +00:00
|
|
|
|
MXLogDebug(@"[MasterTabBarController] presentReviewUnverifiedSessionsAlertWithSession");
|
2020-09-29 15:02:02 +00:00
|
|
|
|
|
2020-05-04 17:59:11 +00:00
|
|
|
|
[currentAlert dismissViewControllerAnimated:NO completion:nil];
|
|
|
|
|
|
2021-09-28 05:40:01 +00:00
|
|
|
|
UIAlertController *alert = [UIAlertController alertControllerWithTitle:[VectorL10n keyVerificationSelfVerifyUnverifiedSessionsAlertTitle]
|
|
|
|
|
message:[VectorL10n keyVerificationSelfVerifyUnverifiedSessionsAlertMessage]
|
2020-05-04 17:59:11 +00:00
|
|
|
|
preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
|
|
2021-09-28 05:40:01 +00:00
|
|
|
|
[alert addAction:[UIAlertAction actionWithTitle:[VectorL10n keyVerificationSelfVerifyUnverifiedSessionsAlertValidateAction]
|
2020-05-04 17:59:11 +00:00
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
[self showSettingsSecurityScreenForSession:session];
|
|
|
|
|
}]];
|
|
|
|
|
|
2021-09-28 05:40:01 +00:00
|
|
|
|
[alert addAction:[UIAlertAction actionWithTitle:[VectorL10n later]
|
2020-05-04 17:59:11 +00:00
|
|
|
|
style:UIAlertActionStyleCancel
|
|
|
|
|
handler:nil]];
|
|
|
|
|
|
2021-09-28 05:40:01 +00:00
|
|
|
|
[alert addAction:[UIAlertAction actionWithTitle:[VectorL10n doNotAskAgain]
|
2020-05-04 17:59:11 +00:00
|
|
|
|
style:UIAlertActionStyleDestructive
|
|
|
|
|
handler:^(UIAlertAction * action) {
|
|
|
|
|
RiotSettings.shared.hideReviewSessionsAlert = YES;
|
|
|
|
|
}]];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[self presentViewController:alert animated:YES completion:nil];
|
|
|
|
|
|
|
|
|
|
currentAlert = alert;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)showSettingsSecurityScreenForSession:(MXSession*)session
|
|
|
|
|
{
|
|
|
|
|
SettingsViewController *settingsViewController = [SettingsViewController instantiate];
|
|
|
|
|
[settingsViewController loadViewIfNeeded];
|
|
|
|
|
SecurityViewController *securityViewController = [SecurityViewController instantiateWithMatrixSession:session];
|
|
|
|
|
|
|
|
|
|
[[AppDelegate theDelegate] restoreInitialDisplay:^{
|
2020-05-05 07:17:47 +00:00
|
|
|
|
self.navigationController.viewControllers = @[self, settingsViewController, securityViewController];
|
2020-05-04 17:59:11 +00:00
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)resetReviewSessionsFlags
|
|
|
|
|
{
|
|
|
|
|
self.reviewSessionAlertHasBeenDisplayed = NO;
|
|
|
|
|
RiotSettings.shared.hideVerifyThisSessionAlert = NO;
|
|
|
|
|
RiotSettings.shared.hideReviewSessionsAlert = NO;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-14 07:41:15 +00:00
|
|
|
|
#pragma mark - UITabBarDelegate
|
|
|
|
|
|
|
|
|
|
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
|
|
|
|
|
{
|
2017-06-16 14:55:54 +00:00
|
|
|
|
// Detect multi-tap on the current selected tab.
|
|
|
|
|
if (item.tag == self.selectedIndex)
|
2017-06-14 07:41:15 +00:00
|
|
|
|
{
|
|
|
|
|
// Scroll to the next room with missed notifications.
|
2017-06-16 14:55:54 +00:00
|
|
|
|
if (item.tag == TABBAR_ROOMS_INDEX)
|
|
|
|
|
{
|
|
|
|
|
[self.roomsViewController scrollToNextRoomWithMissedNotifications];
|
|
|
|
|
}
|
|
|
|
|
else if (item.tag == TABBAR_PEOPLE_INDEX)
|
|
|
|
|
{
|
|
|
|
|
[self.peopleViewController scrollToNextRoomWithMissedNotifications];
|
|
|
|
|
}
|
|
|
|
|
else if (item.tag == TABBAR_FAVOURITES_INDEX)
|
|
|
|
|
{
|
|
|
|
|
[self.favouritesViewController scrollToNextRoomWithMissedNotifications];
|
|
|
|
|
}
|
2017-06-14 07:41:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-16 14:20:28 +00:00
|
|
|
|
#pragma mark - UITabBarControllerDelegate
|
|
|
|
|
|
|
|
|
|
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
|
|
|
|
|
{
|
2022-02-23 11:41:05 +00:00
|
|
|
|
titleView.titleLabel.text = [self getTitleForItemViewController:viewController];
|
2021-07-16 14:20:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 16:48:05 +00:00
|
|
|
|
@end
|