SP3.1: Update room settings for Spaces element-ios#5231

- Changed the Room Settings screen according to the new design
- Implemented the room access flow
- Added room upgrade support
- Implemented the room suggestion screen
This commit is contained in:
Gil Eluard
2022-01-13 15:53:45 +01:00
parent 085fc7d5b0
commit ce226cff8a
78 changed files with 3755 additions and 196 deletions
@@ -20,6 +20,7 @@
#import "TableViewCellWithCheckBoxes.h"
@class AnalyticsScreenTimer;
@protocol RoomSettingsViewControllerDelegate;
/**
List the settings fields. Used to preselect/edit a field
@@ -59,5 +60,15 @@ typedef enum : NSUInteger {
*/
@property (nonatomic) AnalyticsScreenTimer *screenTimer;
/**
Delegate of this view controller.
*/
@property (nonatomic, weak) id<RoomSettingsViewControllerDelegate> delegate;
@end
@protocol RoomSettingsViewControllerDelegate <NSObject>
- (void)roomSettingsViewController:(RoomSettingsViewController *)controller didMoveRoomTo:(NSString *)newRoomId;
@end
@@ -38,6 +38,7 @@ enum
{
SECTION_TAG_MAIN,
SECTION_TAG_ACCESS,
SECTION_TAG_PROMOTION,
SECTION_TAG_HISTORY,
SECTION_TAG_ADDRESSES,
SECTION_TAG_FLAIR,
@@ -58,6 +59,7 @@ enum
enum
{
ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_ACCESS,
ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_INVITED_ONLY,
ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_ANYONE_APART_FROM_GUEST,
ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_ANYONE,
@@ -65,6 +67,11 @@ enum
ROOM_SETTINGS_ROOM_ACCESS_MISSING_ADDRESS_WARNING
};
enum
{
ROOM_SETTINGS_ROOM_PROMOTE_SECTION_ROW_SUGGEST
};
enum
{
ROOM_SETTINGS_HISTORY_VISIBILITY_SECTION_ROW_ANYONE,
@@ -126,7 +133,7 @@ NSString *const kRoomSettingsAdvancedCellViewIdentifier = @"kRoomSettingsAdvance
NSString *const kRoomSettingsAdvancedEnableE2eCellViewIdentifier = @"kRoomSettingsAdvancedEnableE2eCellViewIdentifier";
NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSettingsAdvancedE2eEnabledCellViewIdentifier";
@interface RoomSettingsViewController () <SingleImagePickerPresenterDelegate, TableViewSectionsDelegate>
@interface RoomSettingsViewController () <SingleImagePickerPresenterDelegate, TableViewSectionsDelegate, RoomAccessCoordinatorBridgePresenterDelegate, RoomSuggestionCoordinatorBridgePresenterDelegate>
{
// The updated user data
NSMutableDictionary<NSString*, id> *updatedItemsDict;
@@ -181,6 +188,10 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
// Observe kThemeServiceDidChangeThemeNotification to handle user interface theme change.
id kThemeServiceDidChangeThemeNotificationObserver;
RoomAccessCoordinatorBridgePresenter *roomAccessPresenter;
RoomSuggestionCoordinatorBridgePresenter *roomSuggestionPresenter;
}
@property (nonatomic, strong) SingleImagePickerPresenter *imagePickerPresenter;
@@ -264,6 +275,7 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
[self.tableView registerClass:TableViewCellWithCheckBoxes.class forCellReuseIdentifier:[TableViewCellWithCheckBoxes defaultReuseIdentifier]];
[self.tableView registerClass:TableViewCellWithCheckBoxAndLabel.class forCellReuseIdentifier:[TableViewCellWithCheckBoxAndLabel defaultReuseIdentifier]];
[self.tableView registerClass:MXKTableViewCell.class forCellReuseIdentifier:[MXKTableViewCell defaultReuseIdentifier]];
[self.tableView registerClass:TitleAndRightDetailTableViewCell.class forCellReuseIdentifier:[TitleAndRightDetailTableViewCell defaultReuseIdentifier]];
// Enable self sizing cells
self.tableView.rowHeight = UITableViewAutomaticDimension;
@@ -543,34 +555,66 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
if (RiotSettings.shared.roomSettingsScreenAllowChangingAccessSettings)
{
Section *sectionAccess = [Section sectionWithTag:SECTION_TAG_ACCESS];
[sectionAccess addRowWithTag:ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_INVITED_ONLY];
[sectionAccess addRowWithTag:ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_ANYONE_APART_FROM_GUEST];
[sectionAccess addRowWithTag:ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_ANYONE];
// Check whether a room address is required for the current join rule
NSString *joinRule = updatedItemsDict[kRoomSettingsJoinRuleKey];
if (!joinRule)
if (@available(iOS 14, *))
{
// Use the actual values if no change is pending.
joinRule = mxRoomState.joinRule;
[sectionAccess addRowWithTag:ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_ACCESS];
// Check whether a room address is required for the current join rule
NSString *joinRule = updatedItemsDict[kRoomSettingsJoinRuleKey];
if (!joinRule)
{
// Use the actual values if no change is pending.
joinRule = mxRoomState.joinRule;
}
if ([joinRule isEqualToString:kMXRoomJoinRulePublic] && !roomAddresses.count)
{
// Notify the user that a room address is required.
[sectionAccess addRowWithTag:ROOM_SETTINGS_ROOM_ACCESS_MISSING_ADDRESS_WARNING];
}
}
if ([joinRule isEqualToString:kMXRoomJoinRulePublic] && !roomAddresses.count)
else
{
// Notify the user that a room address is required.
[sectionAccess addRowWithTag:ROOM_SETTINGS_ROOM_ACCESS_MISSING_ADDRESS_WARNING];
[sectionAccess addRowWithTag:ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_INVITED_ONLY];
[sectionAccess addRowWithTag:ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_ANYONE_APART_FROM_GUEST];
[sectionAccess addRowWithTag:ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_ANYONE];
// Check whether a room address is required for the current join rule
NSString *joinRule = updatedItemsDict[kRoomSettingsJoinRuleKey];
if (!joinRule)
{
// Use the actual values if no change is pending.
joinRule = mxRoomState.joinRule;
}
if ([joinRule isEqualToString:kMXRoomJoinRulePublic] && !roomAddresses.count)
{
// Notify the user that a room address is required.
[sectionAccess addRowWithTag:ROOM_SETTINGS_ROOM_ACCESS_MISSING_ADDRESS_WARNING];
}
[sectionAccess addRowWithTag:ROOM_SETTINGS_ROOM_ACCESS_DIRECTORY_VISIBILITY];
}
[sectionAccess addRowWithTag:ROOM_SETTINGS_ROOM_ACCESS_DIRECTORY_VISIBILITY];
if (mxRoom.isDirect)
{
sectionAccess.headerTitle = [VectorL10n roomDetailsAccessSectionAnyoneForDm];
sectionAccess.headerTitle = [VectorL10n roomDetailsAccessSectionForDm];
}
else
{
sectionAccess.headerTitle = [VectorL10n roomDetailsAccessSection];
}
[tmpSections addObject:sectionAccess];
if (@available(iOS 14, *)) {
if (RiotSettings.shared.roomSettingsScreenAllowChangingAccessSettings)
{
Section *promotionAccess = [Section sectionWithTag:SECTION_TAG_PROMOTION];
promotionAccess.headerTitle = VectorL10n.roomDetailsPromoteRoomTitle;
[promotionAccess addRowWithTag:ROOM_SETTINGS_ROOM_ACCESS_DIRECTORY_VISIBILITY];
[promotionAccess addRowWithTag:ROOM_SETTINGS_ROOM_PROMOTE_SECTION_ROW_SUGGEST];
[tmpSections addObject:promotionAccess];
}
}
}
if (RiotSettings.shared.roomSettingsScreenAllowChangingHistorySettings)
@@ -2494,6 +2538,41 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.text = [VectorL10n roomDetailsAccessSectionNoAddressWarning];
}
else if (row == ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_ACCESS)
{
TitleAndRightDetailTableViewCell *roomAccessCell = [tableView dequeueReusableCellWithIdentifier:[TitleAndRightDetailTableViewCell defaultReuseIdentifier] forIndexPath:indexPath];
// Retrieve the potential updated values for joinRule and guestAccess
NSString *joinRule = updatedItemsDict[kRoomSettingsJoinRuleKey];
NSString *guestAccess = updatedItemsDict[kRoomSettingsGuestAccessKey];
// Use the actual values if no change is pending
if (!joinRule)
{
joinRule = mxRoomState.joinRule;
}
if (!guestAccess)
{
guestAccess = mxRoomState.guestAccess;
}
roomAccessCell.titleLabel.text = [VectorL10n roomDetailsAccessRowTitle];
NSString *access = VectorL10n.private;
if ([joinRule isEqualToString:kMXRoomJoinRulePublic])
{
access = VectorL10n.public;
}
else if ([joinRule isEqualToString:kMXRoomJoinRuleRestricted])
{
access = VectorL10n.createRoomTypeRestricted;
}
roomAccessCell.detailLabel.text = access;
// Check whether the user can change this option
roomAccessCell.userInteractionEnabled = (oneSelfPowerLevel >= [powerLevels minimumPowerLevelForSendingEventAsStateEvent:kMXEventTypeStringRoomJoinRules]);
cell = roomAccessCell;
}
else
{
TableViewCellWithCheckBoxAndLabel *roomAccessCell = [tableView dequeueReusableCellWithIdentifier:[TableViewCellWithCheckBoxAndLabel defaultReuseIdentifier] forIndexPath:indexPath];
@@ -2560,6 +2639,54 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
cell = roomAccessCell;
}
}
else if (section == SECTION_TAG_PROMOTION)
{
if (row == ROOM_SETTINGS_ROOM_ACCESS_DIRECTORY_VISIBILITY)
{
MXKTableViewCellWithLabelAndSwitch *directoryToggleCell = [self getLabelAndSwitchCell:tableView forIndexPath:indexPath];
if (mxRoom.isDirect)
{
directoryToggleCell.mxkLabel.text = [VectorL10n roomDetailsAccessSectionDirectoryToggleForDm];
}
else
{
directoryToggleCell.mxkLabel.text = [VectorL10n roomDetailsAccessSectionDirectoryToggle];
}
[directoryToggleCell.mxkSwitch addTarget:self action:@selector(toggleDirectoryVisibility:) forControlEvents:UIControlEventValueChanged];
if (updatedItemsDict[kRoomSettingsDirectoryKey])
{
directoryToggleCell.mxkSwitch.on = ((NSNumber*) updatedItemsDict[kRoomSettingsDirectoryKey]).boolValue;
}
else
{
// Use the last retrieved value if any
directoryToggleCell.mxkSwitch.on = actualDirectoryVisibility ? [actualDirectoryVisibility isEqualToString:kMXRoomDirectoryVisibilityPublic] : NO;
}
// Check whether the user can change this option
directoryToggleCell.mxkSwitch.enabled = (oneSelfPowerLevel >= powerLevels.stateDefault);
// Store the switch to be able to update it
directoryVisibilitySwitch = directoryToggleCell.mxkSwitch;
cell = directoryToggleCell;
}
else if (row == ROOM_SETTINGS_ROOM_PROMOTE_SECTION_ROW_SUGGEST)
{
TitleAndRightDetailTableViewCell *roomSuggestionCell = [tableView dequeueReusableCellWithIdentifier:[TitleAndRightDetailTableViewCell defaultReuseIdentifier] forIndexPath:indexPath];
roomSuggestionCell.titleLabel.text = [VectorL10n roomDetailsPromoteRoomSuggestTitle];
roomSuggestionCell.detailLabel.text = [self.mainSession.spaceService directParentIdsOfRoomWithId:self.roomId isRoomSuggested:YES].count ? [VectorL10n on] : [VectorL10n off];
// Check whether the user can change this option
roomSuggestionCell.userInteractionEnabled = (oneSelfPowerLevel >= [powerLevels minimumPowerLevelForSendingEventAsStateEvent:kMXEventTypeStringRoomJoinRules]);
cell = roomSuggestionCell;
}
}
else if (section == SECTION_TAG_HISTORY)
{
TableViewCellWithCheckBoxAndLabel *historyVisibilityCell = [tableView dequeueReusableCellWithIdentifier:[TableViewCellWithCheckBoxAndLabel defaultReuseIdentifier] forIndexPath:indexPath];
@@ -3144,6 +3271,10 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
}
}
}
else if (row == ROOM_SETTINGS_ROOM_ACCESS_SECTION_ROW_ACCESS)
{
[self showRoomAccessFlow];
}
if (isUpdated)
{
@@ -3152,6 +3283,13 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
}
}
else if (section == SECTION_TAG_PROMOTION)
{
if (row == ROOM_SETTINGS_ROOM_PROMOTE_SECTION_ROW_SUGGEST)
{
[self showSuggestToSpaceMembers];
}
}
else if (section == SECTION_TAG_HISTORY)
{
// Ignore the selection if the option is already enabled
@@ -3670,6 +3808,28 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
[self getNavigationItem].rightBarButtonItem.enabled = (updatedItemsDict.count != 0);
}
- (void)showRoomAccessFlow
{
MXRoom *room = [self.mainSession roomWithRoomId:self.roomId];
if (room) {
roomAccessPresenter = [[RoomAccessCoordinatorBridgePresenter alloc] initWithRoom:room];
roomAccessPresenter.delegate = self;
[roomAccessPresenter presentFrom:self animated:YES];
}
}
- (void)showSuggestToSpaceMembers
{
MXRoom *room = [self.mainSession roomWithRoomId:self.roomId];
if (room) {
roomSuggestionPresenter = [[RoomSuggestionCoordinatorBridgePresenter alloc] initWithRoom:room];
roomSuggestionPresenter.delegate = self;
[roomSuggestionPresenter presentFrom:self animated:YES];
}
}
- (void)setRoomAliasAsMainAddress:(NSString *)alias
{
NSString *currentCanonicalAlias = mxRoomState.canonicalAlias;
@@ -4040,4 +4200,42 @@ NSString *const kRoomSettingsAdvancedE2eEnabledCellViewIdentifier = @"kRoomSetti
[self.tableView reloadData];
}
#pragma mark - RoomAccessCoordinatorBridgePresenterDelegate
- (void)roomAccessCoordinatorBridgePresenterDelegateDidCancel:(RoomAccessCoordinatorBridgePresenter *)coordinatorBridgePresenter
{
[roomAccessPresenter dismissWithAnimated:YES completion:nil];
roomAccessPresenter = nil;
}
- (void)roomAccessCoordinatorBridgePresenterDelegate:(RoomAccessCoordinatorBridgePresenter *)coordinatorBridgePresenter didCompleteRoomWithId:(NSString *)roomId
{
if (![roomId isEqualToString: self.roomId]) {
// Room Access Coordinator upgraded the actual room -> Need to move to replacement room
[self.delegate roomSettingsViewController:self didMoveRoomTo:roomId];
}
MXWeakify(self);
[roomAccessPresenter dismissWithAnimated:YES completion:^{
MXStrongifyAndReturnIfNil(self);
self->roomAccessPresenter = nil;
}];
}
#pragma mark - RoomSuggestionCoordinatorBridgePresenterDelegate
- (void)roomSuggestionCoordinatorBridgePresenterDelegateDidCancel:(RoomSuggestionCoordinatorBridgePresenter *)coordinatorBridgePresenter
{
[roomSuggestionPresenter dismissWithAnimated:YES completion:nil];
roomSuggestionPresenter = nil;
}
- (void)roomSuggestionCoordinatorBridgePresenterDelegateDidComplete:(RoomSuggestionCoordinatorBridgePresenter *)coordinatorBridgePresenter
{
[roomSuggestionPresenter dismissWithAnimated:YES completion:^{
self->roomSuggestionPresenter = nil;
[self refreshRoomSettings];
}];
}
@end
@@ -0,0 +1,48 @@
//
// Copyright 2021 New Vector 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 UIKit
class TitleAndRightDetailTableViewCell: MXKTableViewCell {
// MARK: Outlet
@IBOutlet var titleLabel: UILabel!
@IBOutlet var detailLabel: UILabel!
// MARK: Properties
override var isUserInteractionEnabled: Bool {
didSet {
titleLabel.alpha = isUserInteractionEnabled ? 1 : 0.3
detailLabel.alpha = isUserInteractionEnabled ? 1 : 0.3
}
}
// MARK: - MXKTableViewCell
override func customizeRendering() {
super.customizeRendering()
let theme = ThemeService.shared().theme
titleLabel.textColor = theme.colors.primaryContent
titleLabel.font = theme.fonts.body
detailLabel.textColor = theme.colors.secondaryContent
detailLabel.font = theme.fonts.body
}
}
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" id="Tgv-My-C1l" customClass="TitleAndRightDetailTableViewCell" customModule="Riot" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="414" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="Tgv-My-C1l" id="BJV-sE-Mvs">
<rect key="frame" x="0.0" y="0.0" width="384.5" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="3wR-ut-4aU">
<rect key="frame" x="0.0" y="0.0" width="0.0" height="44"/>
<state key="normal" title="Button"/>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalHuggingPriority="251" text="title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="alK-rA-Dk5">
<rect key="frame" x="16" y="12" width="310.5" height="20"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="250" text="detail" textAlignment="natural" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="h19-3t-q46">
<rect key="frame" x="334.5" y="12" width="42" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="alK-rA-Dk5" secondAttribute="bottom" constant="12" id="1Dg-X4-7xc"/>
<constraint firstItem="3wR-ut-4aU" firstAttribute="top" secondItem="BJV-sE-Mvs" secondAttribute="top" id="298-Q8-nW7"/>
<constraint firstItem="alK-rA-Dk5" firstAttribute="leading" secondItem="BJV-sE-Mvs" secondAttribute="leading" constant="16" id="2zu-HX-e3O"/>
<constraint firstAttribute="leading" secondItem="3wR-ut-4aU" secondAttribute="trailing" id="5dd-tf-Z9d"/>
<constraint firstAttribute="bottom" secondItem="3wR-ut-4aU" secondAttribute="bottom" id="Eqc-lA-4Vh"/>
<constraint firstItem="alK-rA-Dk5" firstAttribute="top" secondItem="BJV-sE-Mvs" secondAttribute="top" constant="12" id="SpX-3q-4E6"/>
<constraint firstItem="3wR-ut-4aU" firstAttribute="leading" secondItem="BJV-sE-Mvs" secondAttribute="leading" id="gxw-sS-kSr"/>
<constraint firstItem="h19-3t-q46" firstAttribute="firstBaseline" secondItem="alK-rA-Dk5" secondAttribute="firstBaseline" id="i5e-qN-Zqj"/>
<constraint firstAttribute="trailing" secondItem="h19-3t-q46" secondAttribute="trailing" constant="8" id="qwJ-h7-jFe"/>
<constraint firstItem="h19-3t-q46" firstAttribute="leading" secondItem="alK-rA-Dk5" secondAttribute="trailing" constant="8" id="wev-Ez-iia"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="detailLabel" destination="h19-3t-q46" id="WBD-Jq-908"/>
<outlet property="titleLabel" destination="alK-rA-Dk5" id="HPw-Ub-A6A"/>
</connections>
<point key="canvasLocation" x="-59" y="-21"/>
</tableViewCell>
</objects>
</document>