From 8a64c2bc4159a1b6eeb2e55b144089abbbf759bf Mon Sep 17 00:00:00 2001 From: manuroe Date: Tue, 25 Sep 2018 11:20:50 +0200 Subject: [PATCH 1/2] SettingsVC: Use MXKAccount method to determine if LL is supported by the HS --- .../Modules/Settings/SettingsViewController.m | 71 ++++++++----------- 1 file changed, 31 insertions(+), 40 deletions(-) diff --git a/Riot/Modules/Settings/SettingsViewController.m b/Riot/Modules/Settings/SettingsViewController.m index 9999778b8..726abe5de 100644 --- a/Riot/Modules/Settings/SettingsViewController.m +++ b/Riot/Modules/Settings/SettingsViewController.m @@ -2059,7 +2059,9 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); MXKTableViewCellWithLabelAndSwitch* labelAndSwitchCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath]; labelAndSwitchCell.mxkLabel.text = NSLocalizedStringFromTable(@"settings_labs_room_members_lazy_loading", @"Vector", nil); - labelAndSwitchCell.mxkSwitch.on = [MXKAppSettings standardAppSettings].syncWithLazyLoadOfRoomMembers; + + MXKAccount* account = [MXKAccountManager sharedManager].activeAccounts.firstObject; + labelAndSwitchCell.mxkSwitch.on = account.mxSession.syncWithLazyLoadOfRoomMembers; [labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(toggleSyncWithLazyLoadOfRoomMembers:) forControlEvents:UIControlEventTouchUpInside]; @@ -2924,54 +2926,43 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)(); [self startActivityIndicator]; // Check the user homeserver supports lazy-loading - MXSession* session = [AppDelegate theDelegate].mxSessions.firstObject; + MXKAccount* account = [MXKAccountManager sharedManager].activeAccounts.firstObject; MXWeakify(self); - void(^onFailure)(NSError *) = ^(NSError *error) { + [account supportLazyLoadOfRoomMembers:^(BOOL supportLazyLoadOfRoomMembers) { MXStrongifyAndReturnIfNil(self); - [switchButton setOn:NO animated:YES]; - switchButton.enabled = YES; - [self stopActivityIndicator]; - - // No support of lazy-loading, do not engage it and warn the user - [self->currentAlert dismissViewControllerAnimated:NO completion:nil]; - - self->currentAlert = [UIAlertController alertControllerWithTitle:nil - message:NSLocalizedStringFromTable(@"settings_labs_room_members_lazy_loading_error_message", @"Vector", nil) - preferredStyle:UIAlertControllerStyleAlert]; - - MXWeakify(self); - [self->currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"ok"] - style:UIAlertActionStyleDefault - handler:^(UIAlertAction * action) { - MXStrongifyAndReturnIfNil(self); - self->currentAlert = nil; - }]]; - - [self->currentAlert mxk_setAccessibilityIdentifier: @"SettingsVCNoHSSupportOfLazyLoading"]; - [self presentViewController:self->currentAlert animated:YES completion:nil]; - }; - - // Check first the home server supports m.lazy_load_members - [session supportedMatrixVersions:^(MXMatrixVersions *matrixVersions) { - - if (matrixVersions.supportLazyLoadMembers) + if (supportLazyLoadOfRoomMembers) { - // Check then, we can create a LL filter on it - [session setFilter:[MXFilterJSONModel syncFilterForLazyLoading] success:^(NSString *filterId) { - - // Lazy-loading is fully supported, enable it - [MXKAppSettings standardAppSettings].syncWithLazyLoadOfRoomMembers = YES; - [self launchClearCache]; - - } failure:onFailure]; + // Lazy-loading is fully supported, enable it + [MXKAppSettings standardAppSettings].syncWithLazyLoadOfRoomMembers = YES; + [self launchClearCache]; } else { - onFailure(nil); + [switchButton setOn:NO animated:YES]; + switchButton.enabled = YES; + [self stopActivityIndicator]; + + // No support of lazy-loading, do not engage it and warn the user + [self->currentAlert dismissViewControllerAnimated:NO completion:nil]; + + self->currentAlert = [UIAlertController alertControllerWithTitle:nil + message:NSLocalizedStringFromTable(@"settings_labs_room_members_lazy_loading_error_message", @"Vector", nil) + preferredStyle:UIAlertControllerStyleAlert]; + + MXWeakify(self); + [self->currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"ok"] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { + MXStrongifyAndReturnIfNil(self); + self->currentAlert = nil; + }]]; + + [self->currentAlert mxk_setAccessibilityIdentifier: @"SettingsVCNoHSSupportOfLazyLoading"]; + [self presentViewController:self->currentAlert animated:YES completion:nil]; } - } failure:onFailure]; + }]; } } } From 045a840c96ef0a3f28f6c87dbe4c380f1816ee6d Mon Sep 17 00:00:00 2001 From: manuroe Date: Tue, 25 Sep 2018 15:46:07 +0200 Subject: [PATCH 2/2] Lazy-Loading: On logout, reenable LL --- CHANGES.rst | 1 + Riot/AppDelegate.m | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 166bbb0df..2aaec5971 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -3,6 +3,7 @@ Changes in 0.7.4 (2018-09-) Improvements: * Upgrade MatrixKit version (v0.8.4). +* Lazy loading: Enable it by default (if the homeserver supports it). * i18n: Add Spanish (sp). * Settings: Make advanced info copyable (#2023). * Settings: Made cryptography info copyable, thanks to @daverPL (PR #1999). diff --git a/Riot/AppDelegate.m b/Riot/AppDelegate.m index 84500155a..5952ea06d 100644 --- a/Riot/AppDelegate.m +++ b/Riot/AppDelegate.m @@ -2683,6 +2683,8 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN [_masterTabBarController showAuthenticationScreen]; // Note: Keep App settings + // But enforce usage of member lazy loading + [MXKAppSettings standardAppSettings].syncWithLazyLoadOfRoomMembers = YES; // Reset the contact manager [[MXKContactManager sharedManager] reset];