mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 01:20:12 +00:00
reused the room details view model for the space settings screen
This commit is contained in:
@@ -77,7 +77,7 @@ struct RoomDetailsScreenViewState: BindableState {
|
||||
knockingEnabled && dmRecipientInfo == nil && canEditRolesOrPermissions
|
||||
}
|
||||
|
||||
var canEdit: Bool {
|
||||
var canEditBaseInfo: Bool {
|
||||
!isDirect && (canEditRoomName || canEditRoomTopic || canEditRoomAvatar)
|
||||
}
|
||||
|
||||
|
||||
@@ -169,6 +169,11 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
||||
// MARK: - Private
|
||||
|
||||
private func processTapToLeave() {
|
||||
guard !roomProxy.infoPublisher.value.isSpace else {
|
||||
Task { await processLeaveSpace() }
|
||||
return
|
||||
}
|
||||
|
||||
guard state.joinedMembersCount > 1 else {
|
||||
state.bindings.leaveRoomAlertItem = LeaveRoomAlertItem(roomID: roomProxy.id,
|
||||
isDM: roomProxy.isDirectOneToOneRoom,
|
||||
@@ -202,6 +207,16 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
||||
state: roomProxy.infoPublisher.value.isPrivate ?? true ? .private : .public)
|
||||
}
|
||||
|
||||
private func processLeaveSpace() async {
|
||||
switch await userSession.clientProxy.spaceService.leaveSpace(spaceID: roomProxy.id) {
|
||||
case .success:
|
||||
// TODO: Handle leave space
|
||||
break
|
||||
case .failure(let failure):
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
}
|
||||
}
|
||||
|
||||
private func setupRoomSubscription() {
|
||||
roomProxy.infoPublisher
|
||||
.receive(on: DispatchQueue.main)
|
||||
|
||||
@@ -46,7 +46,7 @@ struct RoomDetailsScreen: View {
|
||||
message: blockUserAlertMessage)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
if context.viewState.canEdit {
|
||||
if context.viewState.canEditBaseInfo {
|
||||
Button(L10n.actionEdit) {
|
||||
context.send(viewAction: .processTapEdit)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user