mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
handle the case where a non parent joined space is already available in the existing restricted join rule
This commit is contained in:
+10
-9
@@ -38,11 +38,12 @@ struct SecurityAndPrivacyScreenViewState: BindableState {
|
||||
var canEditJoinRule = false
|
||||
var canEnableEncryption = false
|
||||
var canEditHistoryVisibility = false
|
||||
var joinedParentSpaces: [SpaceRoomProxyProtocol] = []
|
||||
/// The union of joined parent spaces and the joined spaces in the current access type
|
||||
var selectableJoinedSpaces: [SpaceRoomProxyProtocol] = []
|
||||
|
||||
/// The count of the intersection between the set of joined parent spaces and the set of spaces in the current access type
|
||||
var selectableSpacesCount: Int {
|
||||
Set(joinedParentSpaces.map(\.id) + currentSettings.accessType.spaceIDs).count
|
||||
Set(selectableJoinedSpaces.map(\.id) + currentSettings.accessType.spaceIDs).count
|
||||
}
|
||||
|
||||
private var hasChanges: Bool {
|
||||
@@ -85,8 +86,8 @@ struct SecurityAndPrivacyScreenViewState: BindableState {
|
||||
var spaceMembersDescription: String {
|
||||
if isSpaceMembersOptionSelectable {
|
||||
switch spaceSelection {
|
||||
case .singleJoined(let joinedParentSpace):
|
||||
L10n.screenSecurityAndPrivacyRoomAccessSpaceMembersOptionSingleParentDescription(joinedParentSpace.name)
|
||||
case .singleJoined(let joinedSpace):
|
||||
L10n.screenSecurityAndPrivacyRoomAccessSpaceMembersOptionSingleParentDescription(joinedSpace.name)
|
||||
case .singleUnknown(let id):
|
||||
L10n.screenSecurityAndPrivacyRoomAccessSpaceMembersOptionSingleParentDescription(id)
|
||||
case .multiple, .empty:
|
||||
@@ -100,8 +101,8 @@ struct SecurityAndPrivacyScreenViewState: BindableState {
|
||||
var askToJoinWithSpaceMembersDescription: String {
|
||||
if isAskToJoinWithSpaceMembersOptionSelectable {
|
||||
switch spaceSelection {
|
||||
case .singleJoined(let joinedParentSpace):
|
||||
L10n.screenSecurityAndPrivacyAskToJoinSingleSpaceMembersOptionDescription(joinedParentSpace.name)
|
||||
case .singleJoined(let joinedSpace):
|
||||
L10n.screenSecurityAndPrivacyAskToJoinSingleSpaceMembersOptionDescription(joinedSpace.name)
|
||||
case .singleUnknown(let id):
|
||||
L10n.screenSecurityAndPrivacyAskToJoinSingleSpaceMembersOptionDescription(id)
|
||||
case .multiple, .empty:
|
||||
@@ -140,17 +141,17 @@ struct SecurityAndPrivacyScreenViewState: BindableState {
|
||||
.empty
|
||||
} else if selectableSpacesCount > 1 {
|
||||
.multiple
|
||||
} else if let joinedParent = joinedParentSpaces.first {
|
||||
} else if let joinedSpace = selectableJoinedSpaces.first {
|
||||
if currentSettings.accessType.isSpaceMembers || currentSettings.accessType.isAskToJoinWithSpaceMembers {
|
||||
if currentSettings.accessType.spaceIDs.isEmpty {
|
||||
// Edge case where the access type is already space members, but it does not contain any id
|
||||
// So if the user wants to add their own parent they need to do it from the selection menu
|
||||
.multiple
|
||||
} else {
|
||||
.singleJoined(joinedParent)
|
||||
.singleJoined(joinedSpace)
|
||||
}
|
||||
} else {
|
||||
.singleJoined(joinedParent)
|
||||
.singleJoined(joinedSpace)
|
||||
}
|
||||
} else if let unknownSpaceID = currentSettings.accessType.spaceIDs.first {
|
||||
// The space is not joined by the user but is currently selected
|
||||
|
||||
+32
-13
@@ -47,12 +47,7 @@ class SecurityAndPrivacyScreenViewModel: SecurityAndPrivacyScreenViewModelType,
|
||||
setupRoomDirectoryVisibility()
|
||||
setupSubscriptions()
|
||||
Task {
|
||||
switch await clientProxy.spaceService.joinedParents(childID: roomProxy.id) {
|
||||
case .success(let joinedParentSpaces):
|
||||
state.joinedParentSpaces = joinedParentSpaces
|
||||
case .failure:
|
||||
break
|
||||
}
|
||||
await setupSelectableJoinedSpaces()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,6 +228,8 @@ class SecurityAndPrivacyScreenViewModel: SecurityAndPrivacyScreenViewModelType,
|
||||
|
||||
if shouldDismiss, !hasFailures {
|
||||
actionsSubject.send(.dismiss)
|
||||
} else if !shouldDismiss {
|
||||
await setupSelectableJoinedSpaces()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,8 +240,8 @@ class SecurityAndPrivacyScreenViewModel: SecurityAndPrivacyScreenViewModelType,
|
||||
}
|
||||
|
||||
switch state.spaceSelection {
|
||||
case .singleJoined(let joinedParent):
|
||||
state.bindings.desiredSettings.accessType = .spaceMembers(spaceIDs: [joinedParent.id])
|
||||
case .singleJoined(let joinedSpace):
|
||||
state.bindings.desiredSettings.accessType = .spaceMembers(spaceIDs: [joinedSpace.id])
|
||||
case .singleUnknown(let id):
|
||||
state.bindings.desiredSettings.accessType = .spaceMembers(spaceIDs: [id])
|
||||
case .empty:
|
||||
@@ -261,8 +258,8 @@ class SecurityAndPrivacyScreenViewModel: SecurityAndPrivacyScreenViewModelType,
|
||||
}
|
||||
|
||||
switch state.spaceSelection {
|
||||
case .singleJoined(let joinedParent):
|
||||
state.bindings.desiredSettings.accessType = .askToJoinWithSpaceMembers(spaceIDs: [joinedParent.id])
|
||||
case .singleJoined(let joinedSpace):
|
||||
state.bindings.desiredSettings.accessType = .askToJoinWithSpaceMembers(spaceIDs: [joinedSpace.id])
|
||||
case .singleUnknown(let id):
|
||||
state.bindings.desiredSettings.accessType = .askToJoinWithSpaceMembers(spaceIDs: [id])
|
||||
case .empty:
|
||||
@@ -273,12 +270,12 @@ class SecurityAndPrivacyScreenViewModel: SecurityAndPrivacyScreenViewModelType,
|
||||
}
|
||||
|
||||
private func displayManageAuthorizedSpacesScreen(isAskToJoin: Bool) {
|
||||
let joinedParentSpaces = state.joinedParentSpaces
|
||||
let joinedSpaces = state.selectableJoinedSpaces
|
||||
let unknownSpaceIDs = state.currentSettings.accessType.spaceIDs.filter { id in
|
||||
!joinedParentSpaces.contains { $0.id == id }
|
||||
!joinedSpaces.contains { $0.id == id }
|
||||
}
|
||||
let selectedIDs = Set(state.bindings.desiredSettings.accessType.spaceIDs)
|
||||
let authorizedSpacesSelection = AuthorizedSpacesSelection(joinedParentSpaces: joinedParentSpaces,
|
||||
let authorizedSpacesSelection = AuthorizedSpacesSelection(joinedSpaces: joinedSpaces,
|
||||
unknownSpacesIDs: unknownSpaceIDs,
|
||||
initialSelectedIDs: selectedIDs)
|
||||
authorizedSpacesSelection.selectedIDs
|
||||
@@ -291,6 +288,28 @@ class SecurityAndPrivacyScreenViewModel: SecurityAndPrivacyScreenViewModelType,
|
||||
actionsSubject.send(.displayManageAuthorizedSpacesScreen(authorizedSpacesSelection))
|
||||
}
|
||||
|
||||
private func setupSelectableJoinedSpaces() async {
|
||||
var joinedParentSpaces: [SpaceRoomProxyProtocol] = []
|
||||
switch await clientProxy.spaceService.joinedParents(childID: roomProxy.id) {
|
||||
case .success(let value):
|
||||
joinedParentSpaces = value
|
||||
case .failure:
|
||||
break
|
||||
}
|
||||
|
||||
var nonParentJoinedSpaces: [SpaceRoomProxyProtocol] = []
|
||||
for spaceID in state.currentSettings.accessType.spaceIDs where !joinedParentSpaces.contains(where: { $0.id == spaceID }) {
|
||||
if case let .success(.some(space)) = await clientProxy.spaceService.spaceForIdentifier(spaceID: spaceID) {
|
||||
nonParentJoinedSpaces.append(space)
|
||||
}
|
||||
}
|
||||
|
||||
// By default we only want to allow selection among joined parents but
|
||||
// if there is a non parent joined space already set in the access type
|
||||
// we also include it in the known spaces selection list.
|
||||
state.selectableJoinedSpaces = joinedParentSpaces + nonParentJoinedSpaces
|
||||
}
|
||||
|
||||
private static let loadingIndicatorIdentifier = "\(EditRoomAddressScreenViewModel.self)-Loading"
|
||||
|
||||
private func showLoadingIndicator() {
|
||||
|
||||
Reference in New Issue
Block a user