mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-22 01:22:46 +02:00
MESSENGER-5410 add room federation setting
This commit is contained in:
@@ -67,7 +67,8 @@ enum
|
||||
ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_ANYONE,
|
||||
ROOM_SETTINGS_ROOM_ACCESS_DIRECTORY_VISIBILITY,
|
||||
ROOM_SETTINGS_ROOM_ACCESS_MISSING_ADDRESS_WARNING,
|
||||
ROOM_SETTINGS_ROOM_ACCESS_BW
|
||||
ROOM_SETTINGS_ROOM_ACCESS_BW,
|
||||
ROOM_SETTINGS_ROOM_ACCESS_FEDERATION
|
||||
};
|
||||
|
||||
enum
|
||||
@@ -75,11 +76,6 @@ enum
|
||||
ROOM_SETTINGS_ROOM_PROMOTE_SECTION_ROW_SUGGEST
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
ROOM_SETTINGS_ROOM_FEDERATION
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_ANYONE,
|
||||
@@ -123,6 +119,7 @@ NSString *const kRoomSettingsCanonicalAliasKey = @"kRoomSettingsCanonicalAliasKe
|
||||
NSString *const kRoomSettingsEncryptionKey = @"kRoomSettingsEncryptionKey";
|
||||
NSString *const kRoomSettingsEncryptionBlacklistUnverifiedDevicesKey = @"kRoomSettingsEncryptionBlacklistUnverifiedDevicesKey";
|
||||
NSString *const kRoomSettingsNotificationTimesKey = @"kRoomSettingsNotificationTimesKey";
|
||||
NSString *const kRoomSettingsFederationKey = @"kRoomSettingsFederationKey"; // bwi: #5410
|
||||
|
||||
NSString *const kRoomSettingsNameCellViewIdentifier = @"kRoomSettingsNameCellViewIdentifier";
|
||||
NSString *const kRoomSettingsTopicCellViewIdentifier = @"kRoomSettingsTopicCellViewIdentifier";
|
||||
@@ -134,6 +131,10 @@ NSString *const kRoomSettingsAdvancedEnableE2eCellViewIdentifier = @"kRoomSettin
|
||||
NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSettingsAdvancedE2eEnabledCellViewIdentifier";
|
||||
NSString *const kRoomSettingsFederationCellViewIdentifier = @"kRoomSettingsFederationCellViewIdentifier";
|
||||
|
||||
// bwi: #5410 add federation setting
|
||||
BWIToggleWithLabelAndSubLabelCellData *bwiFederationToggleCellData;
|
||||
BOOL reloadToggleCell = false;
|
||||
|
||||
@interface RoomSettingsViewController () <SingleImagePickerPresenterDelegate, TableViewSectionsDelegate, RoomAccessCoordinatorBridgePresenterDelegate, RoomSuggestionCoordinatorBridgePresenterDelegate>
|
||||
{
|
||||
// The updated user data
|
||||
@@ -352,6 +353,11 @@ NSString *const kRoomSettingsFederationCellViewIdentifier = @"kRoomSettingsFeder
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:appDelegateDidTapStatusBarNotificationObserver];
|
||||
appDelegateDidTapStatusBarNotificationObserver = nil;
|
||||
}
|
||||
|
||||
// bwi: #5410 reset toggleview
|
||||
reloadToggleCell = true;
|
||||
[self->updatedItemsDict removeObjectForKey:kRoomSettingsFederationKey];
|
||||
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
|
||||
}
|
||||
|
||||
// Those methods are called when the viewcontroller is added or removed from a container view controller.
|
||||
@@ -1683,6 +1689,48 @@ NSString *const kRoomSettingsFederationCellViewIdentifier = @"kRoomSettingsFeder
|
||||
return;
|
||||
}
|
||||
|
||||
// bwi: #5410 add federation setting
|
||||
NSString *serverACLRule = updatedItemsDict[kRoomSettingsFederationKey];
|
||||
if (serverACLRule)
|
||||
{
|
||||
NSMutableDictionary *content = [[NSMutableDictionary alloc] initWithDictionary:@{
|
||||
@"allow": @[serverACLRule],
|
||||
@"allowIPLiterals" : @false
|
||||
}];
|
||||
|
||||
pendingOperation = [mxRoom sendStateEventOfType:kMXEventTypeStringRoomServerACL content:content stateKey:nil success:^(NSString *eventId) {
|
||||
if (weakSelf)
|
||||
{
|
||||
typeof(self) self = weakSelf;
|
||||
|
||||
self->pendingOperation = nil;
|
||||
[self->updatedItemsDict removeObjectForKey:kRoomSettingsFederationKey];
|
||||
[self onSave:nil];
|
||||
}
|
||||
} failure:^(NSError *error) {
|
||||
MXLogDebug(@"[RoomSettingsViewController] Update serverACL setting failed");
|
||||
if (weakSelf)
|
||||
{
|
||||
typeof(self) self = weakSelf;
|
||||
|
||||
self->pendingOperation = nil;
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
||||
NSString* message = error.localizedDescription;
|
||||
if (!message.length)
|
||||
{
|
||||
message = [BWIL10n roomDetailsFailedToUpdateRoomServerAclRule];
|
||||
}
|
||||
[self onSaveFailed:message withKeys:@[kRoomSettingsFederationKey]];
|
||||
|
||||
});
|
||||
}
|
||||
}];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Room join rule
|
||||
MXRoomJoinRule joinRule = updatedItemsDict[kRoomSettingsJoinRuleKey];
|
||||
if (joinRule)
|
||||
@@ -2498,7 +2546,9 @@ NSString *const kRoomSettingsFederationCellViewIdentifier = @"kRoomSettingsFeder
|
||||
{
|
||||
cell = [self cellForAccessSwitch:tableView indexPath:indexPath];
|
||||
}
|
||||
else if (row == ROOM_SETTINGS_ROOM_FEDERATION)
|
||||
|
||||
// bwi: #5410 add federation setting
|
||||
else if (row == ROOM_SETTINGS_ROOM_ACCESS_FEDERATION)
|
||||
{
|
||||
cell = [self cellForFederationSwitch:tableView indexPath:indexPath];
|
||||
}
|
||||
@@ -2948,26 +2998,125 @@ NSString *const kRoomSettingsFederationCellViewIdentifier = @"kRoomSettingsFeder
|
||||
return cell;
|
||||
}
|
||||
|
||||
// bwi: #5410 add federation setting
|
||||
- (TableViewCellWithLabelSubLabelAndSwitch*)getLabelSubLabelAndSwitchCell:(UITableView*)tableView forIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
TableViewCellWithLabelSubLabelAndSwitch *cell = [tableView dequeueReusableCellWithIdentifier:kRoomSettingsFederationCellViewIdentifier forIndexPath:indexPath];
|
||||
|
||||
[cell makeViewControllerWithParent:self toggleText:BWIL10n.createRoomTypeFederated subText:BWIL10n.createRoomTypeFederatedSubtext initalToggleValue:false onValueChanged:^(BOOL newValue) {
|
||||
/* TODO:
|
||||
- Trigger Alert
|
||||
- Change Value
|
||||
- Reset Toggle
|
||||
- Update ACLs
|
||||
- Check Permission
|
||||
*/
|
||||
}];
|
||||
|
||||
// Force layout before reusing a cell (fix switch displayed outside the screen)
|
||||
[cell layoutIfNeeded];
|
||||
// check users power level, only admins or moderators are allowed to change the federation
|
||||
MXRoomPowerLevels *powerLevels = [mxRoomState powerLevels];
|
||||
BOOL isToggleDisabled = ([powerLevels powerLevelOfUserWithUserID:self.mainSession.myUser.userId] != RoomPowerLevelAdmin);
|
||||
|
||||
// reuse view on layout refresh
|
||||
if (reloadToggleCell || ![cell hasBeenInitialized]) {
|
||||
reloadToggleCell = false;
|
||||
|
||||
// Get current serverACL settings
|
||||
[mxRoom getCurrentRoomServerACLSettingsWithCompletion:^(NSString* serverACLSettings) {
|
||||
// Hide view if no previous setting exists
|
||||
if (serverACLSettings)
|
||||
{
|
||||
// Check current serverACL settings
|
||||
BOOL initalToggleValue = false;
|
||||
if ([serverACLSettings isEqual:@"*"])
|
||||
{
|
||||
initalToggleValue = true;
|
||||
}
|
||||
|
||||
bwiFederationToggleCellData = [[BWIToggleWithLabelAndSubLabelCellData alloc] initWithInitalToggleValue:initalToggleValue isToggleDisabled:isToggleDisabled toggleText:BWIL10n.createRoomTypeFederated subText:BWIL10n.createRoomTypeFederatedSubtext];
|
||||
|
||||
[cell makeViewControllerWithParent:self toggleData:bwiFederationToggleCellData onValueChanged:^(BOOL newToggleValue) {
|
||||
// Warn the user if they try to disable federation
|
||||
if (!newToggleValue)
|
||||
{
|
||||
// ensure that the user understands that the updates will be lost if
|
||||
[currentAlert dismissViewControllerAnimated:NO completion:nil];
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
|
||||
self->currentAlert = [UIAlertController alertControllerWithTitle:[BWIL10n bwiRoomSettingsFederationAlertTitle] message:[BWIL10n bwiRoomSettingsFederationAlertMessage] preferredStyle:UIAlertControllerStyleAlert];
|
||||
|
||||
[self->currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n cancel]
|
||||
style:UIAlertActionStyleDestructive
|
||||
handler:^(UIAlertAction * action) {
|
||||
bwiFederationToggleCellData.toggleValue = true;
|
||||
[self toggleFederation: true];
|
||||
}]];
|
||||
|
||||
[self->currentAlert addAction:[UIAlertAction actionWithTitle:[BWIL10n bwiRoomSettingsFederationAlertWithdrawButton]
|
||||
style:UIAlertActionStyleDefault
|
||||
handler:^(UIAlertAction * action) {
|
||||
[self toggleFederation: newToggleValue];
|
||||
}]];
|
||||
|
||||
[self->currentAlert mxk_setAccessibilityIdentifier:@"RoomSettingsVCChangeFederationAlert"];
|
||||
[self presentViewController:self->currentAlert animated:YES completion:nil];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Update the settings View
|
||||
[self toggleFederation: newToggleValue];
|
||||
}
|
||||
}];
|
||||
// Force layout before reusing a cell (fix switch displayed outside the screen)
|
||||
[cell layoutIfNeeded];
|
||||
}
|
||||
else
|
||||
{
|
||||
[cell setHidden:true];
|
||||
}
|
||||
}];
|
||||
}
|
||||
return cell;
|
||||
}
|
||||
|
||||
// bwi: #5410 add federation setting
|
||||
- (void)toggleFederation:(BOOL)toggleValue
|
||||
{
|
||||
// Check whether the initial serverACL settings have changed
|
||||
if (toggleValue != bwiFederationToggleCellData.initalToggleValue)
|
||||
{
|
||||
if (toggleValue)
|
||||
{
|
||||
updatedItemsDict[kRoomSettingsFederationKey] = @"*";
|
||||
}
|
||||
else
|
||||
{
|
||||
NSString *myUserId = self.mainSession.myUserId;
|
||||
NSArray *myUserIdComponents = [myUserId componentsSeparatedByString:@":"];
|
||||
if (myUserIdComponents.count == 2)
|
||||
{
|
||||
updatedItemsDict[kRoomSettingsFederationKey] = myUserIdComponents[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
// ensure that the user understands that the updates will be lost if
|
||||
[currentAlert dismissViewControllerAnimated:NO completion:nil];
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
|
||||
self->currentAlert = [UIAlertController alertControllerWithTitle:[BWIL10n roomDetailsFailedToChangeFederationForRoomErrorTitle] message:[BWIL10n roomDetailsFailedToChangeFederationForRoomErrorText] preferredStyle:UIAlertControllerStyleAlert];
|
||||
[self->currentAlert addAction:[UIAlertAction actionWithTitle:[BWIL10n roomDetailsFailedToChangeFederationAlertDismissButton]
|
||||
style:UIAlertActionStyleDefault
|
||||
handler:^(UIAlertAction * action) {
|
||||
|
||||
bwiFederationToggleCellData.toggleValue = bwiFederationToggleCellData.initalToggleValue;
|
||||
}]];
|
||||
[self->currentAlert mxk_setAccessibilityIdentifier:@"RoomSettingsVCChangeFederationErrorAlert"];
|
||||
[self presentViewController:self->currentAlert animated:YES completion:nil];
|
||||
}
|
||||
}
|
||||
|
||||
[self getNavigationItem].rightBarButtonItem.enabled = self->updatedItemsDict.count;
|
||||
}
|
||||
else
|
||||
{
|
||||
[updatedItemsDict removeObjectForKey:kRoomSettingsFederationKey];
|
||||
}
|
||||
|
||||
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
|
||||
}
|
||||
|
||||
#pragma mark - UITableViewDelegate
|
||||
|
||||
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
|
||||
@@ -3785,9 +3934,10 @@ NSString *const kRoomSettingsFederationCellViewIdentifier = @"kRoomSettingsFeder
|
||||
return sectionAccess;
|
||||
}
|
||||
|
||||
// bwi: #5410 add federation setting
|
||||
- (Section*) sectionForFederationSwitch {
|
||||
Section *sectionAccess = [Section sectionWithTag:SECTION_TAG_ACCESS];
|
||||
[sectionAccess addRowWithTag:ROOM_SETTINGS_ROOM_FEDERATION];
|
||||
[sectionAccess addRowWithTag:ROOM_SETTINGS_ROOM_ACCESS_FEDERATION];
|
||||
return sectionAccess;
|
||||
}
|
||||
|
||||
@@ -3820,16 +3970,9 @@ NSString *const kRoomSettingsFederationCellViewIdentifier = @"kRoomSettingsFeder
|
||||
return roomAccessToggleCell;
|
||||
}
|
||||
|
||||
// bwi: #5410 add federation setting
|
||||
- (UITableViewCell*) cellForFederationSwitch:(UITableView*)tableView indexPath:(NSIndexPath*)indexPath {
|
||||
TableViewCellWithLabelSubLabelAndSwitch *roomAccessToggleCell = [self getLabelSubLabelAndSwitchCell:tableView forIndexPath:indexPath];
|
||||
|
||||
|
||||
MXRoomPowerLevels *powerLevels = [mxRoomState powerLevels];
|
||||
|
||||
if ([powerLevels powerLevelOfUserWithUserID:self.mainSession.myUser.userId] != RoomPowerLevelAdmin) {
|
||||
|
||||
}
|
||||
|
||||
return roomAccessToggleCell;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user