Lazy-loading server side: Add "Settings > LABS > Lazy load rooms members" option

This commit is contained in:
manuroe 2018-08-02 16:29:50 +02:00
parent 02a87a1b62
commit 18234ad4f9
2 changed files with 81 additions and 5 deletions

View file

@ -374,6 +374,8 @@
"settings_labs_e2e_encryption" = "End-to-End Encryption";
"settings_labs_e2e_encryption_prompt_message" = "To finish setting up encryption you must log in again.";
"settings_labs_room_members_lazy_loading" = "Lazy load rooms members";
"settings_labs_room_members_lazy_loading_error_message" = "Your homeserver does not support lazy loading of room members yet. Try later.";
"settings_labs_create_conference_with_jitsi" = "Create conference calls with jitsi";
"settings_version" = "Version %@";

View file

@ -117,7 +117,8 @@ enum
enum
{
LABS_USE_JITSI_WIDGET_INDEX = 0,
LABS_USE_ROOM_MEMBERS_LAZY_LOADING_INDEX = 0,
LABS_USE_JITSI_WIDGET_INDEX,
LABS_CRYPTO_INDEX,
LABS_COUNT
};
@ -2040,7 +2041,18 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
}
else if (section == SETTINGS_SECTION_LABS_INDEX)
{
if (row == LABS_USE_JITSI_WIDGET_INDEX)
if (row == LABS_USE_ROOM_MEMBERS_LAZY_LOADING_INDEX)
{
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;
[labelAndSwitchCell.mxkSwitch addTarget:self action:@selector(toggleSyncWithLazyLoadOfRoomMembers:) forControlEvents:UIControlEventTouchUpInside];
cell = labelAndSwitchCell;
}
else if (row == LABS_USE_JITSI_WIDGET_INDEX)
{
MXKTableViewCellWithLabelAndSwitch* labelAndSwitchCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath];
@ -2884,6 +2896,62 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
}
}
- (void)toggleSyncWithLazyLoadOfRoomMembers:(id)sender
{
if (sender && [sender isKindOfClass:UISwitch.class])
{
UISwitch *switchButton = (UISwitch*)sender;
if (!switchButton.isOn)
{
[MXKAppSettings standardAppSettings].syncWithLazyLoadOfRoomMembers = NO;
[self launchClearCache];
}
else
{
switchButton.enabled = NO;
[self startActivityIndicator];
// Check the user homeserver supports lazy-loading
MXSession* session = [AppDelegate theDelegate].mxSessions.firstObject;
MXWeakify(self);
[session setFilter:[MXFilterJSONModel syncFilterForLazyLoading] success:^(NSString *filterId) {
// Lazy-loading is supported, enable it
[MXKAppSettings standardAppSettings].syncWithLazyLoadOfRoomMembers = YES;
[self launchClearCache];
} failure:^(NSError *error) {
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];
}];
}
}
}
- (void)toggleJitsiForConference:(id)sender
{
if (sender && [sender isKindOfClass:UISwitch.class])
@ -3085,12 +3153,18 @@ typedef void (^blockSettingsViewController_onReadyToDestroy)();
// Feedback: disable button and run activity indicator
UIButton *button = (UIButton*)sender;
button.enabled = NO;
[self launchClearCache];
}
- (void)launchClearCache
{
[self startActivityIndicator];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[[AppDelegate theDelegate] reloadMatrixSessions:YES];
});
}