mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Basic implementation of the UI, navigation wil be implemented in the next PR
This commit is contained in:
@@ -45,5 +45,6 @@ enum SpaceScreenViewAction {
|
||||
case toggleLeaveSpaceRoomDetails(id: String)
|
||||
case confirmLeaveSpace
|
||||
case spaceSettings
|
||||
case rolesAndPermissions
|
||||
case displayMembers(roomProxy: JoinedRoomProxyProtocol)
|
||||
}
|
||||
|
||||
@@ -76,19 +76,7 @@ class SpaceScreenViewModel: SpaceScreenViewModelType, SpaceScreenViewModelProtoc
|
||||
}
|
||||
|
||||
appSettings.$spaceSettingsEnabled
|
||||
.combineLatest(roomProxy.infoPublisher)
|
||||
.sink { [weak self] isEnabled, info in
|
||||
guard let self else { return }
|
||||
guard isEnabled, let powerLevels = info.powerLevels else {
|
||||
state.isSpaceManagementEnabled = false
|
||||
return
|
||||
}
|
||||
|
||||
state.isSpaceManagementEnabled = powerLevels.canOwnUserEditRolesAndPermissions() ||
|
||||
powerLevels.canOwnUser(sendStateEvent: .roomName) ||
|
||||
powerLevels.canOwnUser(sendStateEvent: .roomTopic) ||
|
||||
powerLevels.canOwnUser(sendStateEvent: .roomAvatar)
|
||||
}
|
||||
.weakAssign(to: \.state.isSpaceManagementEnabled, on: self)
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
}
|
||||
@@ -141,6 +129,8 @@ class SpaceScreenViewModel: SpaceScreenViewModelType, SpaceScreenViewModelProtoc
|
||||
fatalError("Always available when the space settings button is tapped.")
|
||||
}
|
||||
actionsSubject.send(.displaySpaceSettings(roomProxy: roomProxy))
|
||||
case .rolesAndPermissions:
|
||||
break // Not implemented yet
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -99,9 +99,9 @@ struct LeaveSpaceView: View {
|
||||
.buttonStyle(.compound(.primary))
|
||||
} else if context.viewState.isSpaceManagementEnabled {
|
||||
Button {
|
||||
context.send(viewAction: .spaceSettings)
|
||||
context.send(viewAction: .rolesAndPermissions)
|
||||
} label: {
|
||||
Label(L10n.actionGoToSettings, icon: \.settings)
|
||||
Label(L10n.actionGoToRolesAndPermissions, icon: \.settings)
|
||||
}
|
||||
.buttonStyle(.compound(.primary))
|
||||
}
|
||||
|
||||
+6
-2
@@ -8,7 +8,10 @@
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
struct SpaceSettingsScreenCoordinatorParameters { }
|
||||
struct SpaceSettingsScreenCoordinatorParameters {
|
||||
let roomProxy: JoinedRoomProxyProtocol
|
||||
let userSession: UserSessionProtocol
|
||||
}
|
||||
|
||||
enum SpaceSettingsScreenCoordinatorAction { }
|
||||
|
||||
@@ -26,7 +29,8 @@ final class SpaceSettingsScreenCoordinator: CoordinatorProtocol {
|
||||
init(parameters: SpaceSettingsScreenCoordinatorParameters) {
|
||||
self.parameters = parameters
|
||||
|
||||
viewModel = SpaceSettingsScreenViewModel()
|
||||
viewModel = SpaceSettingsScreenViewModel(roomProxy: parameters.roomProxy,
|
||||
userSession: parameters.userSession)
|
||||
}
|
||||
|
||||
func start() {
|
||||
|
||||
+10
-15
@@ -10,23 +10,18 @@ import Foundation
|
||||
enum SpaceSettingsScreenViewModelAction { }
|
||||
|
||||
struct SpaceSettingsScreenViewState: BindableState {
|
||||
var title: String
|
||||
var placeholder: String
|
||||
var counter = 0
|
||||
var details: RoomDetails
|
||||
|
||||
var bindings: SpaceSettingsScreenViewStateBindings
|
||||
}
|
||||
|
||||
struct SpaceSettingsScreenViewStateBindings {
|
||||
var composerText: String
|
||||
var joinedMembersCount: Int
|
||||
var hasMemberIdentityVerificationStateViolations = false
|
||||
|
||||
var canEditRolesOrPermissions = false
|
||||
}
|
||||
|
||||
enum SpaceSettingsScreenViewAction {
|
||||
case done
|
||||
case textChanged
|
||||
|
||||
case incrementCounter
|
||||
case decrementCounter
|
||||
|
||||
// Consider adding CustomStringConvertible conformance if the actions contain PII
|
||||
case processTapEdit
|
||||
case processTapSecurity
|
||||
case processTapPeople
|
||||
case processTapRolesAndPermissions
|
||||
case processTapLeave
|
||||
}
|
||||
|
||||
+65
-17
@@ -11,15 +11,25 @@ import SwiftUI
|
||||
typealias SpaceSettingsScreenViewModelType = StateStoreViewModelV2<SpaceSettingsScreenViewState, SpaceSettingsScreenViewAction>
|
||||
|
||||
class SpaceSettingsScreenViewModel: SpaceSettingsScreenViewModelType, SpaceSettingsScreenViewModelProtocol {
|
||||
private let roomProxy: JoinedRoomProxyProtocol
|
||||
private let userSession: UserSessionProtocol
|
||||
|
||||
private let actionsSubject: PassthroughSubject<SpaceSettingsScreenViewModelAction, Never> = .init()
|
||||
var actionsPublisher: AnyPublisher<SpaceSettingsScreenViewModelAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init() {
|
||||
super.init(initialViewState: SpaceSettingsScreenViewState(title: "SpaceSettings title",
|
||||
placeholder: "Enter something here",
|
||||
bindings: .init(composerText: "Initial composer text")))
|
||||
init(roomProxy: JoinedRoomProxyProtocol, userSession: UserSessionProtocol) {
|
||||
self.roomProxy = roomProxy
|
||||
self.userSession = userSession
|
||||
|
||||
super.init(initialViewState: .init(details: roomProxy.details,
|
||||
joinedMembersCount: roomProxy.infoPublisher.value.joinedMembersCount),
|
||||
mediaProvider: userSession.mediaProvider)
|
||||
|
||||
updateRoomInfo(roomProxy.infoPublisher.value)
|
||||
setupRoomSubscription()
|
||||
Task { await roomProxy.updateMembers() }
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
@@ -28,20 +38,58 @@ class SpaceSettingsScreenViewModel: SpaceSettingsScreenViewModelType, SpaceSetti
|
||||
MXLog.info("View model: received view action: \(viewAction)")
|
||||
|
||||
switch viewAction {
|
||||
case .done:
|
||||
case .processTapEdit:
|
||||
break
|
||||
case .processTapSecurity:
|
||||
break
|
||||
case .processTapPeople:
|
||||
break
|
||||
case .processTapRolesAndPermissions:
|
||||
break
|
||||
case .processTapLeave:
|
||||
break
|
||||
case .textChanged:
|
||||
MXLog.info("View model: composer text changed to: \(state.bindings.composerText)")
|
||||
case .incrementCounter:
|
||||
Task {
|
||||
try await Task.sleep(for: .seconds(.random(in: 1.0...2.0)))
|
||||
state.counter += 1
|
||||
}
|
||||
case .decrementCounter:
|
||||
Task {
|
||||
try await Task.sleep(for: .seconds(.random(in: 1.0...2.0)))
|
||||
state.counter -= 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func updateRoomInfo(_ roomInfo: RoomInfoProxyProtocol) {
|
||||
state.joinedMembersCount = roomInfo.joinedMembersCount
|
||||
state.details = roomProxy.details
|
||||
|
||||
if let powerLevels = roomInfo.powerLevels {
|
||||
state.canEditRolesOrPermissions = powerLevels.canOwnUserEditRolesAndPermissions()
|
||||
}
|
||||
}
|
||||
|
||||
private func setupRoomSubscription() {
|
||||
roomProxy.infoPublisher
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] roomInfo in
|
||||
self?.updateRoomInfo(roomInfo)
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
roomProxy.membersPublisher.combineLatest(roomProxy.identityStatusChangesPublisher)
|
||||
.sink { [weak self] _ in
|
||||
Task { await self?.updateMemberIdentityVerificationStates() }
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
private func updateMemberIdentityVerificationStates() async {
|
||||
guard roomProxy.infoPublisher.value.isEncrypted else {
|
||||
// We don't care about identity statuses on non-encrypted rooms
|
||||
return
|
||||
}
|
||||
|
||||
for member in roomProxy.membersPublisher.value {
|
||||
if case let .success(userIdentity) = await userSession.clientProxy.userIdentity(for: member.userID) {
|
||||
if userIdentity?.verificationState == .verificationViolation {
|
||||
state.hasMemberIdentityVerificationStateViolations = true
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
state.hasMemberIdentityVerificationStateViolations = false
|
||||
}
|
||||
}
|
||||
|
||||
+92
-39
@@ -13,59 +13,112 @@ struct SpaceSettingsScreen: View {
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
Section {
|
||||
ListRow(label: .plain(title: context.viewState.placeholder),
|
||||
kind: .textField(text: $context.composerText))
|
||||
|
||||
ListRow(label: .centeredAction(title: L10n.actionDone,
|
||||
icon: \.leave),
|
||||
kind: .button { context.send(viewAction: .done) })
|
||||
}
|
||||
|
||||
Section {
|
||||
ListRow(label: .default(title: "Counter", icon: \.chart),
|
||||
details: .counter(context.viewState.counter),
|
||||
kind: .label)
|
||||
ListRow(label: .default(title: "Increment", icon: \.plus),
|
||||
kind: .button { context.send(viewAction: .incrementCounter) })
|
||||
ListRow(label: .default(title: "Decrement", icon: \.minus),
|
||||
kind: .button { context.send(viewAction: .decrementCounter) })
|
||||
editSection
|
||||
if context.viewState.canEditRolesOrPermissions {
|
||||
securitySection
|
||||
}
|
||||
peopleSection
|
||||
leaveSpaceSection
|
||||
}
|
||||
.compoundList()
|
||||
.navigationTitle(context.viewState.title)
|
||||
.onChange(of: context.composerText) {
|
||||
context.send(viewAction: .textChanged)
|
||||
.navigationTitle(L10n.commonSettings)
|
||||
}
|
||||
|
||||
private var editSection: some View {
|
||||
Section {
|
||||
ListRow(kind: .custom {
|
||||
Button {
|
||||
context.send(viewAction: .processTapEdit)
|
||||
} label: {
|
||||
editSectionContent
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private var editSectionContent: some View {
|
||||
HStack(spacing: 12) {
|
||||
RoomAvatarImage(avatar: context.viewState.details.avatar,
|
||||
avatarSize: .room(on: .spaceSettings),
|
||||
mediaProvider: context.mediaProvider)
|
||||
.accessibilityHidden(true)
|
||||
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(context.viewState.details.name ?? context.viewState.details.id)
|
||||
.lineLimit(1)
|
||||
.font(.compound.headingMD)
|
||||
.foregroundStyle(.compound.textPrimary)
|
||||
if let alias = context.viewState.details.canonicalAlias {
|
||||
Text(alias)
|
||||
.lineLimit(1)
|
||||
.font(.compound.bodySM)
|
||||
.foregroundStyle(.compound.textSecondary)
|
||||
}
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
ListRowAccessory.navigationLink
|
||||
}
|
||||
.padding(.horizontal, ListRowPadding.horizontal)
|
||||
.padding(.vertical, 16)
|
||||
}
|
||||
|
||||
private var securitySection: some View {
|
||||
Section {
|
||||
ListRow(label: .default(title: L10n.screenSpaceSettingsSecurityAndPrivacy, icon: \.lock),
|
||||
kind: .navigationLink {
|
||||
context.send(viewAction: .processTapSecurity)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private var peopleSection: some View {
|
||||
Section {
|
||||
if context.viewState.hasMemberIdentityVerificationStateViolations {
|
||||
ListRow(label: .default(title: L10n.commonPeople, icon: \.user),
|
||||
details: .icon(CompoundIcon(\.infoSolid).foregroundStyle(.compound.iconCriticalPrimary)),
|
||||
kind: .navigationLink {
|
||||
context.send(viewAction: .processTapPeople)
|
||||
})
|
||||
} else {
|
||||
ListRow(label: .default(title: L10n.commonPeople, icon: \.user),
|
||||
details: .title(String(context.viewState.joinedMembersCount)),
|
||||
kind: .navigationLink {
|
||||
context.send(viewAction: .processTapPeople)
|
||||
})
|
||||
}
|
||||
|
||||
if context.viewState.canEditRolesOrPermissions {
|
||||
ListRow(label: .default(title: L10n.screenSpaceSettingsRolesAndPermissions, icon: \.admin),
|
||||
kind: .navigationLink {
|
||||
context.send(viewAction: .processTapRolesAndPermissions)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var leaveSpaceSection: some View {
|
||||
ListRow(label: .action(title: L10n.screenSpaceSettingsLeaveSpace,
|
||||
icon: \.leave,
|
||||
role: .destructive),
|
||||
kind: .button { context.send(viewAction: .processTapLeave) })
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct SpaceSettingsScreen_Previews: PreviewProvider, TestablePreview {
|
||||
static let viewModel = makeViewModel()
|
||||
static let incrementedViewModel = makeViewModel(counterValue: 1)
|
||||
static let viewModel = SpaceSettingsScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Space",
|
||||
avatarURL: .mockMXCAvatar,
|
||||
isSpace: true,
|
||||
canonicalAlias: "#space:matrix.org",
|
||||
members: .allMembersAsCreator)),
|
||||
userSession: UserSessionMock(.init()))
|
||||
|
||||
static var previews: some View {
|
||||
NavigationStack {
|
||||
SpaceSettingsScreen(context: viewModel.context)
|
||||
}
|
||||
.previewDisplayName("Initial")
|
||||
|
||||
NavigationStack {
|
||||
SpaceSettingsScreen(context: incrementedViewModel.context)
|
||||
}
|
||||
.previewDisplayName("Incremented")
|
||||
.snapshotPreferences(expect: incrementedViewModel.context.observe(\.viewState.counter).map { $0 == 1 }.eraseToStream())
|
||||
}
|
||||
|
||||
static func makeViewModel(counterValue: Int = 0) -> SpaceSettingsScreenViewModel {
|
||||
let viewModel = SpaceSettingsScreenViewModel()
|
||||
|
||||
for _ in 0..<counterValue {
|
||||
viewModel.context.send(viewAction: .incrementCounter)
|
||||
}
|
||||
|
||||
return viewModel
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user