mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 01:20:12 +00:00
Space Settings: Leave Room (#4700)
* Implementation for all navigations inside the space settings aside the left space action # Conflicts: # ElementX/Sources/FlowCoordinators/SpaceSettingsFlowCoordinator.swift * refactored the leave space view to use its own view model # Conflicts: # ElementX.xcodeproj/project.pbxproj * implemented the leave space view model also in the settings screen, and corrected some tests * reusing the details coordinator for the space settings screen * leave space from settings implemented * fix project * minor pr fixes * code improvements
This commit is contained in:
@@ -39,6 +39,7 @@ enum RoomDetailsScreenCoordinatorAction {
|
||||
|
||||
final class RoomDetailsScreenCoordinator: CoordinatorProtocol {
|
||||
private var viewModel: RoomDetailsScreenViewModelProtocol
|
||||
private let isSpace: Bool
|
||||
|
||||
private let actionsSubject: PassthroughSubject<RoomDetailsScreenCoordinatorAction, Never> = .init()
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
@@ -48,6 +49,7 @@ final class RoomDetailsScreenCoordinator: CoordinatorProtocol {
|
||||
}
|
||||
|
||||
init(parameters: RoomDetailsScreenCoordinatorParameters) {
|
||||
isSpace = parameters.roomProxy.infoPublisher.value.isSpace
|
||||
viewModel = RoomDetailsScreenViewModel(roomProxy: parameters.roomProxy,
|
||||
userSession: parameters.userSession,
|
||||
analyticsService: parameters.analyticsService,
|
||||
@@ -105,6 +107,10 @@ final class RoomDetailsScreenCoordinator: CoordinatorProtocol {
|
||||
}
|
||||
|
||||
func toPresentable() -> AnyView {
|
||||
AnyView(RoomDetailsScreen(context: viewModel.context))
|
||||
if isSpace {
|
||||
AnyView(SpaceSettingsScreen(context: viewModel.context))
|
||||
} else {
|
||||
AnyView(RoomDetailsScreen(context: viewModel.context))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,6 +172,9 @@ struct RoomDetailsScreenViewStateBindings {
|
||||
|
||||
/// A media item that will be previewed with QuickLook.
|
||||
var mediaPreviewItem: MediaPreviewItem?
|
||||
|
||||
/// The view model used to display the leave space sheet, will only be used if the room is a space.
|
||||
var leaveSpaceViewModel: LeaveSpaceViewModel?
|
||||
}
|
||||
|
||||
struct LeaveRoomAlertItem: AlertProtocol {
|
||||
|
||||
@@ -209,10 +209,29 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
||||
|
||||
private func processLeaveSpace() async {
|
||||
switch await userSession.clientProxy.spaceService.leaveSpace(spaceID: roomProxy.id) {
|
||||
case .success:
|
||||
// TODO: Handle leave space
|
||||
break
|
||||
case .failure(let failure):
|
||||
case .success(let leaveHandle):
|
||||
let leaveSpaceViewModel = LeaveSpaceViewModel(spaceName: state.details.name ?? state.details.id,
|
||||
canEditRolesAndPermissions: state.canEditRolesOrPermissions,
|
||||
leaveHandle: leaveHandle,
|
||||
userIndicatorController: userIndicatorController,
|
||||
mediaProvider: userSession.mediaProvider)
|
||||
leaveSpaceViewModel.actions.sink { [weak self] action in
|
||||
guard let self else { return }
|
||||
switch action {
|
||||
case .didCancel:
|
||||
state.bindings.leaveSpaceViewModel = nil
|
||||
case .presentRolesAndPermissions:
|
||||
state.bindings.leaveSpaceViewModel = nil
|
||||
actionsSubject.send(.requestRolesAndPermissionsPresentation)
|
||||
case .didLeaveSpace:
|
||||
state.bindings.leaveSpaceViewModel = nil
|
||||
actionsSubject.send(.leftRoom)
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
state.bindings.leaveSpaceViewModel = leaveSpaceViewModel
|
||||
case .failure:
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// Copyright 2025 Element Creations Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
enum LeaveSpaceViewAction {
|
||||
case confirmLeaveSpace
|
||||
case deselectAll
|
||||
case selectAll
|
||||
case toggleRoom(roomID: String)
|
||||
case rolesAndPermissions
|
||||
case cancel
|
||||
}
|
||||
|
||||
struct LeaveSpaceViewState: BindableState {
|
||||
let spaceName: String
|
||||
let canEditRolesAndPermissions: Bool
|
||||
let leaveHandle: LeaveSpaceHandleProxy
|
||||
|
||||
var title: String {
|
||||
switch leaveHandle.mode {
|
||||
case .lastSpaceAdmin: L10n.screenLeaveSpaceTitleLastAdmin(spaceName)
|
||||
default: L10n.screenLeaveSpaceTitle(spaceName)
|
||||
}
|
||||
}
|
||||
|
||||
var subtitle: String? {
|
||||
switch leaveHandle.mode {
|
||||
case .manyRooms: L10n.screenLeaveSpaceSubtitle
|
||||
case .onlyAdminRooms: L10n.screenLeaveSpaceSubtitleOnlyLastAdmin
|
||||
case .noRooms: nil
|
||||
case .lastSpaceAdmin: L10n.screenLeaveSpaceSubtitleLastAdmin
|
||||
}
|
||||
}
|
||||
|
||||
var confirmationTitle: String {
|
||||
let selectedCount = leaveHandle.selectedCount
|
||||
return selectedCount > 0 ? L10n.screenLeaveSpaceSubmit(selectedCount) : L10n.actionLeaveSpace
|
||||
}
|
||||
}
|
||||
|
||||
enum LeaveSpaceViewModelAction {
|
||||
case didLeaveSpace
|
||||
case presentRolesAndPermissions
|
||||
case didCancel
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
//
|
||||
// Copyright 2025 Element Creations Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
typealias LeaveSpaceViewModelType = StateStoreViewModelV2<LeaveSpaceViewState, LeaveSpaceViewAction>
|
||||
|
||||
class LeaveSpaceViewModel: LeaveSpaceViewModelType {
|
||||
let actionsSubject = PassthroughSubject<LeaveSpaceViewModelAction, Never>()
|
||||
var actions: AnyPublisher<LeaveSpaceViewModelAction, Never> { actionsSubject.eraseToAnyPublisher() }
|
||||
private let userIndicatorController: UserIndicatorControllerProtocol
|
||||
private let mediaProvider: MediaProviderProtocol
|
||||
|
||||
init(spaceName: String, canEditRolesAndPermissions: Bool, leaveHandle: LeaveSpaceHandleProxy, userIndicatorController: UserIndicatorControllerProtocol, mediaProvider: MediaProviderProtocol) {
|
||||
self.userIndicatorController = userIndicatorController
|
||||
self.mediaProvider = mediaProvider
|
||||
super.init(initialViewState: LeaveSpaceViewState(spaceName: spaceName, canEditRolesAndPermissions: canEditRolesAndPermissions, leaveHandle: leaveHandle), mediaProvider: mediaProvider)
|
||||
}
|
||||
|
||||
override func process(viewAction: LeaveSpaceViewAction) {
|
||||
switch viewAction {
|
||||
case .confirmLeaveSpace:
|
||||
Task { await confirmLeaveSpace() }
|
||||
case .rolesAndPermissions:
|
||||
actionsSubject.send(.presentRolesAndPermissions)
|
||||
case .cancel:
|
||||
actionsSubject.send(.didCancel)
|
||||
case .deselectAll:
|
||||
state.leaveHandle.deselectAll()
|
||||
case .selectAll:
|
||||
state.leaveHandle.selectAll()
|
||||
case .toggleRoom(let roomID):
|
||||
withTransaction(\.disablesAnimations, true) { // The button is adding an unwanted animation.
|
||||
state.leaveHandle.toggleRoom(roomID: roomID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func confirmLeaveSpace() async {
|
||||
showLeavingIndicator()
|
||||
defer { hideLeavingIndicator() }
|
||||
|
||||
switch await state.leaveHandle.leave() {
|
||||
case .success:
|
||||
actionsSubject.send(.didLeaveSpace)
|
||||
case .failure:
|
||||
showFailureIndicator()
|
||||
}
|
||||
}
|
||||
|
||||
private static var leavingIndicatorID: String { "\(Self.self)-Leaving" }
|
||||
private static var failureIndicatorID: String { "\(Self.self)-Failure" }
|
||||
|
||||
private func showLeavingIndicator() {
|
||||
userIndicatorController.submitIndicator(UserIndicator(id: Self.leavingIndicatorID,
|
||||
type: .modal(progress: .indeterminate, interactiveDismissDisabled: true, allowsInteraction: false),
|
||||
title: L10n.commonLeavingSpace))
|
||||
}
|
||||
|
||||
private func hideLeavingIndicator() {
|
||||
userIndicatorController.retractIndicatorWithId(Self.leavingIndicatorID)
|
||||
}
|
||||
|
||||
private func showFailureIndicator() {
|
||||
userIndicatorController.submitIndicator(UserIndicator(id: Self.failureIndicatorID,
|
||||
type: .toast,
|
||||
title: L10n.errorUnknown,
|
||||
iconName: "xmark"))
|
||||
}
|
||||
}
|
||||
|
||||
extension LeaveSpaceViewModel: Identifiable {
|
||||
var id: String { state.leaveHandle.id }
|
||||
}
|
||||
+30
-58
@@ -12,8 +12,7 @@ import SwiftUI
|
||||
struct LeaveSpaceView: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
let context: SpaceScreenViewModel.Context
|
||||
let leaveHandle: LeaveSpaceHandleProxy
|
||||
let context: LeaveSpaceViewModel.Context
|
||||
|
||||
@State private var scrollViewHeight: CGFloat = .zero
|
||||
@State private var buttonsHeight: CGFloat = .zero
|
||||
@@ -43,12 +42,12 @@ struct LeaveSpaceView: View {
|
||||
BigIcon(icon: \.errorSolid, style: .alertSolid)
|
||||
|
||||
VStack(spacing: 8) {
|
||||
Text(leaveHandle.title(spaceName: context.viewState.space.name))
|
||||
Text(context.viewState.title)
|
||||
.font(.compound.headingMDBold)
|
||||
.foregroundStyle(.compound.textPrimary)
|
||||
.multilineTextAlignment(.center)
|
||||
|
||||
if let subtitle = leaveHandle.subtitle {
|
||||
if let subtitle = context.viewState.subtitle {
|
||||
Text(subtitle)
|
||||
.font(.compound.bodyMD)
|
||||
.foregroundStyle(.compound.textSecondary)
|
||||
@@ -61,21 +60,22 @@ struct LeaveSpaceView: View {
|
||||
|
||||
@ViewBuilder
|
||||
var rooms: some View {
|
||||
if !leaveHandle.rooms.isEmpty, leaveHandle.canLeave {
|
||||
if !context.viewState.leaveHandle.rooms.isEmpty,
|
||||
context.viewState.leaveHandle.canLeave {
|
||||
LazyVStack(spacing: 0, pinnedViews: .sectionHeaders) {
|
||||
Section {
|
||||
ForEach(leaveHandle.rooms, id: \.spaceRoomProxy.id) { room in
|
||||
ForEach(context.viewState.leaveHandle.rooms, id: \.spaceRoomProxy.id) { room in
|
||||
LeaveSpaceRoomDetailsCell(room: room,
|
||||
hideSelection: leaveHandle.mode == .onlyAdminRooms,
|
||||
hideSelection: context.viewState.leaveHandle.mode == .onlyAdminRooms,
|
||||
mediaProvider: context.mediaProvider) {
|
||||
context.send(viewAction: .toggleLeaveSpaceRoomDetails(id: room.spaceRoomProxy.id))
|
||||
context.send(viewAction: .toggleRoom(roomID: room.spaceRoomProxy.id))
|
||||
}
|
||||
.disabled(room.isLastAdmin)
|
||||
}
|
||||
} header: {
|
||||
if leaveHandle.mode == .manyRooms {
|
||||
Button(leaveHandle.selectedCount > 0 ? L10n.actionDeselectAll : L10n.actionSelectAll) {
|
||||
context.send(viewAction: leaveHandle.selectedCount > 0 ? .deselectAllLeaveRoomDetails : .selectAllLeaveRoomDetails)
|
||||
if context.viewState.leaveHandle.mode == .manyRooms {
|
||||
Button(context.viewState.leaveHandle.selectedCount > 0 ? L10n.actionDeselectAll : L10n.actionSelectAll) {
|
||||
context.send(viewAction: context.viewState.leaveHandle.selectedCount > 0 ? .deselectAll : .selectAll)
|
||||
}
|
||||
.buttonStyle(.compound(.textLink, size: .small))
|
||||
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||
@@ -90,11 +90,11 @@ struct LeaveSpaceView: View {
|
||||
|
||||
var buttons: some View {
|
||||
VStack(spacing: 16) {
|
||||
if leaveHandle.canLeave {
|
||||
if context.viewState.leaveHandle.canLeave {
|
||||
Button(role: .destructive) {
|
||||
context.send(viewAction: .confirmLeaveSpace)
|
||||
} label: {
|
||||
Label(leaveHandle.confirmationTitle, icon: \.leave)
|
||||
Label(context.viewState.confirmationTitle, icon: \.leave)
|
||||
}
|
||||
.buttonStyle(.compound(.primary))
|
||||
} else if context.viewState.canEditRolesAndPermissions {
|
||||
@@ -114,44 +114,24 @@ struct LeaveSpaceView: View {
|
||||
}
|
||||
}
|
||||
|
||||
private extension LeaveSpaceHandleProxy {
|
||||
func title(spaceName: String) -> String {
|
||||
switch mode {
|
||||
case .lastSpaceAdmin: L10n.screenLeaveSpaceTitleLastAdmin(spaceName)
|
||||
default: L10n.screenLeaveSpaceTitle(spaceName)
|
||||
}
|
||||
}
|
||||
|
||||
var subtitle: String? {
|
||||
switch mode {
|
||||
case .manyRooms: L10n.screenLeaveSpaceSubtitle
|
||||
case .onlyAdminRooms: L10n.screenLeaveSpaceSubtitleOnlyLastAdmin
|
||||
case .noRooms: nil
|
||||
case .lastSpaceAdmin: L10n.screenLeaveSpaceSubtitleLastAdmin
|
||||
}
|
||||
}
|
||||
|
||||
var confirmationTitle: String {
|
||||
let selectedCount = selectedCount
|
||||
return selectedCount > 0 ? L10n.screenLeaveSpaceSubmit(selectedCount) : L10n.actionLeaveSpace
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
import MatrixRustSDK
|
||||
|
||||
struct LeaveSpaceView_Previews: PreviewProvider, TestablePreview {
|
||||
static let viewModel = makeViewModel()
|
||||
static let manyViewModel = makeViewModel(mode: .manyRooms)
|
||||
static let onlyAdminViewModel = makeViewModel(mode: .onlyAdminRooms)
|
||||
static let noRoomsViewModel = makeViewModel(mode: .noRooms)
|
||||
static let lastAdminViewModel = makeViewModel(mode: .lastSpaceAdmin)
|
||||
|
||||
static var previews: some View {
|
||||
LeaveSpaceView(context: viewModel.context, leaveHandle: makeLeaveHandle(mode: .manyRooms))
|
||||
LeaveSpaceView(context: manyViewModel.context)
|
||||
.previewDisplayName("Many Rooms")
|
||||
LeaveSpaceView(context: viewModel.context, leaveHandle: makeLeaveHandle(mode: .onlyAdminRooms))
|
||||
LeaveSpaceView(context: onlyAdminViewModel.context)
|
||||
.previewDisplayName("Only Admin Rooms")
|
||||
LeaveSpaceView(context: viewModel.context, leaveHandle: makeLeaveHandle(mode: .noRooms))
|
||||
LeaveSpaceView(context: noRoomsViewModel.context)
|
||||
.previewDisplayName("No Rooms")
|
||||
LeaveSpaceView(context: viewModel.context, leaveHandle: makeLeaveHandle(mode: .lastSpaceAdmin))
|
||||
LeaveSpaceView(context: lastAdminViewModel.context)
|
||||
.previewDisplayName("Last Space Admin")
|
||||
}
|
||||
|
||||
@@ -164,21 +144,7 @@ struct LeaveSpaceView_Previews: PreviewProvider, TestablePreview {
|
||||
topic: "Description of the space goes right here. Lorem ipsum dolor sit amet consectetur. Leo viverra morbi habitant in.",
|
||||
joinRule: .knockRestricted(rules: [.roomMembership(roomId: "")])))
|
||||
|
||||
static func makeViewModel() -> SpaceScreenViewModel {
|
||||
let spaceRoomListProxy = SpaceRoomListProxyMock(.init(spaceRoomProxy: spaceRoomProxy,
|
||||
initialSpaceRooms: .mockSpaceList))
|
||||
let spaceServiceProxy = SpaceServiceProxyMock(.init())
|
||||
|
||||
let viewModel = SpaceScreenViewModel(spaceRoomListProxy: spaceRoomListProxy,
|
||||
spaceServiceProxy: spaceServiceProxy,
|
||||
selectedSpaceRoomPublisher: .init(nil),
|
||||
userSession: UserSessionMock(.init()),
|
||||
appSettings: AppSettings(),
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
return viewModel
|
||||
}
|
||||
|
||||
static func makeLeaveHandle(mode: LeaveSpaceHandleProxy.Mode) -> LeaveSpaceHandleProxy {
|
||||
static func makeViewModel(mode: LeaveSpaceHandleProxy.Mode) -> LeaveSpaceViewModel {
|
||||
let rooms: [LeaveSpaceRoom] = switch mode {
|
||||
case .manyRooms: .mockRooms
|
||||
case .onlyAdminRooms: .mockAdminRooms
|
||||
@@ -186,7 +152,13 @@ struct LeaveSpaceView_Previews: PreviewProvider, TestablePreview {
|
||||
case .lastSpaceAdmin: .mockLastSpaceAdmin(spaceRoomProxy: spaceRoomProxy)
|
||||
}
|
||||
|
||||
return LeaveSpaceHandleProxy(spaceID: spaceRoomProxy.id,
|
||||
leaveHandle: LeaveSpaceHandleSDKMock(.init(rooms: rooms)))
|
||||
let leaveHandle = LeaveSpaceHandleProxy(spaceID: spaceRoomProxy.id,
|
||||
leaveHandle: LeaveSpaceHandleSDKMock(.init(rooms: rooms)))
|
||||
|
||||
return LeaveSpaceViewModel(spaceName: spaceRoomProxy.name,
|
||||
canEditRolesAndPermissions: true,
|
||||
leaveHandle: leaveHandle,
|
||||
userIndicatorController: UserIndicatorControllerMock(),
|
||||
mediaProvider: MediaProviderMock(configuration: .init()))
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ enum SpaceScreenCoordinatorAction {
|
||||
case leftSpace
|
||||
case displayMembers(roomProxy: JoinedRoomProxyProtocol)
|
||||
case displaySpaceSettings(roomProxy: JoinedRoomProxyProtocol)
|
||||
case displayRolesAndPermissions(roomProxy: JoinedRoomProxyProtocol)
|
||||
}
|
||||
|
||||
final class SpaceScreenCoordinator: CoordinatorProtocol {
|
||||
@@ -69,6 +70,8 @@ final class SpaceScreenCoordinator: CoordinatorProtocol {
|
||||
actionsSubject.send(.displayMembers(roomProxy: roomProxy))
|
||||
case .displaySpaceSettings(let roomProxy):
|
||||
actionsSubject.send(.displaySpaceSettings(roomProxy: roomProxy))
|
||||
case .presentRolesAndPermissions(let roomProxy):
|
||||
actionsSubject.send(.displayRolesAndPermissions(roomProxy: roomProxy))
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
@@ -13,6 +13,7 @@ enum SpaceScreenViewModelAction {
|
||||
case selectUnjoinedSpace(SpaceRoomProxyProtocol)
|
||||
case selectRoom(roomID: String)
|
||||
case leftSpace
|
||||
case presentRolesAndPermissions(roomProxy: JoinedRoomProxyProtocol)
|
||||
case displayMembers(roomProxy: JoinedRoomProxyProtocol)
|
||||
case displaySpaceSettings(roomProxy: JoinedRoomProxyProtocol)
|
||||
}
|
||||
@@ -39,17 +40,12 @@ struct SpaceScreenViewState: BindableState {
|
||||
}
|
||||
|
||||
struct SpaceScreenViewStateBindings {
|
||||
var leaveHandle: LeaveSpaceHandleProxy?
|
||||
var leaveSpaceViewModel: LeaveSpaceViewModel?
|
||||
}
|
||||
|
||||
enum SpaceScreenViewAction {
|
||||
case spaceAction(SpaceRoomCell.Action)
|
||||
case leaveSpace
|
||||
case deselectAllLeaveRoomDetails
|
||||
case selectAllLeaveRoomDetails
|
||||
case toggleLeaveSpaceRoomDetails(id: String)
|
||||
case confirmLeaveSpace
|
||||
case spaceSettings(roomProxy: JoinedRoomProxyProtocol)
|
||||
case rolesAndPermissions
|
||||
case displayMembers(roomProxy: JoinedRoomProxyProtocol)
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ class SpaceScreenViewModel: SpaceScreenViewModelType, SpaceScreenViewModelProtoc
|
||||
private let spaceRoomListProxy: SpaceRoomListProxyProtocol
|
||||
private let spaceServiceProxy: SpaceServiceProxyProtocol
|
||||
private let clientProxy: ClientProxyProtocol
|
||||
private let mediaProvider: MediaProviderProtocol
|
||||
private let appSettings: AppSettings
|
||||
private let userIndicatorController: UserIndicatorControllerProtocol
|
||||
|
||||
@@ -32,6 +33,7 @@ class SpaceScreenViewModel: SpaceScreenViewModelType, SpaceScreenViewModelProtoc
|
||||
self.spaceRoomListProxy = spaceRoomListProxy
|
||||
self.spaceServiceProxy = spaceServiceProxy
|
||||
clientProxy = userSession.clientProxy
|
||||
mediaProvider = userSession.mediaProvider
|
||||
self.userIndicatorController = userIndicatorController
|
||||
self.appSettings = appSettings
|
||||
|
||||
@@ -117,31 +119,10 @@ class SpaceScreenViewModel: SpaceScreenViewModelType, SpaceScreenViewModelProtoc
|
||||
Task { await join(spaceRoomProxy) }
|
||||
case .leaveSpace:
|
||||
Task { await showLeaveSpaceConfirmation() }
|
||||
case .deselectAllLeaveRoomDetails:
|
||||
guard let leaveHandle = state.bindings.leaveHandle else { fatalError("The leave handle should be available.") }
|
||||
for room in leaveHandle.rooms {
|
||||
room.isSelected = false
|
||||
}
|
||||
case .selectAllLeaveRoomDetails:
|
||||
guard let leaveHandle = state.bindings.leaveHandle else { fatalError("The leave handle should be available.") }
|
||||
for room in leaveHandle.rooms where !room.isLastAdmin {
|
||||
room.isSelected = true
|
||||
}
|
||||
case .toggleLeaveSpaceRoomDetails(let spaceRoomID):
|
||||
guard let room = state.bindings.leaveHandle?.rooms.first(where: { $0.spaceRoomProxy.id == spaceRoomID }) else {
|
||||
fatalError("The space room to toggle is not in the list of rooms to leave.")
|
||||
}
|
||||
withTransaction(\.disablesAnimations, true) { // The button is adding an unwanted animation.
|
||||
room.isSelected.toggle()
|
||||
}
|
||||
case .confirmLeaveSpace:
|
||||
Task { await confirmLeaveSpace() }
|
||||
case .displayMembers(let roomProxy):
|
||||
actionsSubject.send(.displayMembers(roomProxy: roomProxy))
|
||||
case .spaceSettings(let roomProxy):
|
||||
actionsSubject.send(.displaySpaceSettings(roomProxy: roomProxy))
|
||||
case .rolesAndPermissions:
|
||||
break // Not implemented yet
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,41 +161,37 @@ class SpaceScreenViewModel: SpaceScreenViewModelType, SpaceScreenViewModelProtoc
|
||||
return
|
||||
}
|
||||
|
||||
state.bindings.leaveHandle = leaveHandle
|
||||
}
|
||||
|
||||
private func confirmLeaveSpace() async {
|
||||
guard let leaveHandle = state.bindings.leaveHandle else { fatalError("Leaving without a handle is impossible.") }
|
||||
|
||||
showLeavingIndicator()
|
||||
defer { hideLeavingIndicator() }
|
||||
|
||||
switch await leaveHandle.leave() {
|
||||
case .success:
|
||||
state.bindings.leaveHandle = nil
|
||||
actionsSubject.send(.leftSpace)
|
||||
case .failure:
|
||||
showFailureIndicator()
|
||||
let leaveSpaceViewModel = LeaveSpaceViewModel(spaceName: state.space.name,
|
||||
canEditRolesAndPermissions: appSettings.spaceSettingsEnabled && state.canEditRolesAndPermissions,
|
||||
leaveHandle: leaveHandle,
|
||||
userIndicatorController: userIndicatorController,
|
||||
mediaProvider: mediaProvider)
|
||||
leaveSpaceViewModel.actions.sink { [weak self] action in
|
||||
guard let self else { return }
|
||||
switch action {
|
||||
case .didCancel:
|
||||
state.bindings.leaveSpaceViewModel = nil
|
||||
case .presentRolesAndPermissions:
|
||||
guard let roomProxy = state.roomProxy else {
|
||||
fatalError("The space screen should always have a room proxy")
|
||||
}
|
||||
state.bindings.leaveSpaceViewModel = nil
|
||||
actionsSubject.send(.presentRolesAndPermissions(roomProxy: roomProxy))
|
||||
case .didLeaveSpace:
|
||||
state.bindings.leaveSpaceViewModel = nil
|
||||
actionsSubject.send(.leftSpace)
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
state.bindings.leaveSpaceViewModel = leaveSpaceViewModel
|
||||
}
|
||||
|
||||
private func updatePermissions() { }
|
||||
|
||||
|
||||
// MARK: - Indicators
|
||||
|
||||
private static var leavingIndicatorID: String { "\(Self.self)-Leaving" }
|
||||
private static var failureIndicatorID: String { "\(Self.self)-Failure" }
|
||||
|
||||
private func showLeavingIndicator() {
|
||||
userIndicatorController.submitIndicator(UserIndicator(id: Self.leavingIndicatorID,
|
||||
type: .modal(progress: .indeterminate, interactiveDismissDisabled: true, allowsInteraction: false),
|
||||
title: L10n.commonLeavingSpace))
|
||||
}
|
||||
|
||||
private func hideLeavingIndicator() {
|
||||
userIndicatorController.retractIndicatorWithId(Self.leavingIndicatorID)
|
||||
}
|
||||
|
||||
private func showFailureIndicator() {
|
||||
userIndicatorController.submitIndicator(UserIndicator(id: Self.failureIndicatorID,
|
||||
type: .toast,
|
||||
|
||||
@@ -25,8 +25,8 @@ struct SpaceScreen: View {
|
||||
.navigationTitle(context.viewState.space.name)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar { toolbar }
|
||||
.sheet(item: $context.leaveHandle) { leaveHandle in
|
||||
LeaveSpaceView(context: context, leaveHandle: leaveHandle)
|
||||
.sheet(item: $context.leaveSpaceViewModel) { leaveSpaceViewModel in
|
||||
LeaveSpaceView(context: leaveSpaceViewModel.context)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-76
@@ -1,76 +0,0 @@
|
||||
//
|
||||
// Copyright 2025 Element Creations Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
struct SpaceSettingsScreenCoordinatorParameters {
|
||||
let roomProxy: JoinedRoomProxyProtocol
|
||||
let userSession: UserSessionProtocol
|
||||
let analyticsService: AnalyticsService
|
||||
let userIndicator: UserIndicatorControllerProtocol
|
||||
let notificationSettingsProxy: NotificationSettingsProxyProtocol
|
||||
let attributedStringBuilder: AttributedStringBuilderProtocol
|
||||
let appSettings: AppSettings
|
||||
}
|
||||
|
||||
enum SpaceSettingsScreenCoordinatorAction {
|
||||
case presentEditDetailsScreen
|
||||
case presentSecurityAndPrivacyScreen
|
||||
case presentMembersListScreen
|
||||
case presentRolesAndPermissionsScreen
|
||||
}
|
||||
|
||||
final class SpaceSettingsScreenCoordinator: CoordinatorProtocol {
|
||||
private let viewModel: RoomDetailsScreenViewModelProtocol
|
||||
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
private let actionsSubject: PassthroughSubject<SpaceSettingsScreenCoordinatorAction, Never> = .init()
|
||||
var actionsPublisher: AnyPublisher<SpaceSettingsScreenCoordinatorAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init(parameters: SpaceSettingsScreenCoordinatorParameters) {
|
||||
viewModel = RoomDetailsScreenViewModel(roomProxy: parameters.roomProxy,
|
||||
userSession: parameters.userSession,
|
||||
analyticsService: parameters.analyticsService,
|
||||
userIndicatorController: parameters.userIndicator,
|
||||
notificationSettingsProxy: parameters.notificationSettingsProxy,
|
||||
attributedStringBuilder: parameters.attributedStringBuilder,
|
||||
appSettings: parameters.appSettings)
|
||||
}
|
||||
|
||||
func start() {
|
||||
viewModel.actions.sink { [weak self] action in
|
||||
MXLog.info("Coordinator: received view model action: \(action)")
|
||||
guard let self else { return }
|
||||
|
||||
switch action {
|
||||
case .requestNotificationSettingsPresentation, .requestRecipientDetailsPresentation, .requestInvitePeoplePresentation, .requestPollsHistoryPresentation,
|
||||
.startCall, .displayPinnedEventsTimeline, .displayMediaEventsTimeline, .displayKnockingRequests,
|
||||
.displayReportRoom, .transferOwnership:
|
||||
break // Not handled in this context
|
||||
case .requestEditDetailsPresentation:
|
||||
actionsSubject.send(.presentEditDetailsScreen)
|
||||
case .displaySecurityAndPrivacy:
|
||||
actionsSubject.send(.presentSecurityAndPrivacyScreen)
|
||||
case .requestMemberDetailsPresentation:
|
||||
actionsSubject.send(.presentMembersListScreen)
|
||||
case .requestRolesAndPermissionsPresentation:
|
||||
actionsSubject.send(.presentRolesAndPermissionsScreen)
|
||||
case .leftRoom:
|
||||
break // TODO:
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
func toPresentable() -> AnyView {
|
||||
AnyView(SpaceSettingsScreen(context: viewModel.context))
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,9 @@ struct SpaceSettingsScreen: View {
|
||||
}
|
||||
.compoundList()
|
||||
.navigationTitle(L10n.commonSettings)
|
||||
.sheet(item: $context.leaveSpaceViewModel) { viewModel in
|
||||
LeaveSpaceView(context: viewModel.context)
|
||||
}
|
||||
}
|
||||
|
||||
private var editSection: some View {
|
||||
|
||||
Reference in New Issue
Block a user