mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Add RoomRolesAndPermissionsFlowCoordinator. (#2539)
This commit is contained in:
@@ -25,6 +25,7 @@ struct RoomDetailsScreenCoordinatorParameters {
|
||||
let userIndicatorController: UserIndicatorControllerProtocol
|
||||
let notificationSettings: NotificationSettingsProxyProtocol
|
||||
let attributedStringBuilder: AttributedStringBuilderProtocol
|
||||
let appSettings: AppSettings
|
||||
}
|
||||
|
||||
enum RoomDetailsScreenCoordinatorAction {
|
||||
@@ -34,6 +35,7 @@ enum RoomDetailsScreenCoordinatorAction {
|
||||
case presentNotificationSettingsScreen
|
||||
case presentInviteUsersScreen
|
||||
case presentPollsHistory
|
||||
case presentRolesAndPermissionsScreen
|
||||
}
|
||||
|
||||
final class RoomDetailsScreenCoordinator: CoordinatorProtocol {
|
||||
@@ -53,7 +55,8 @@ final class RoomDetailsScreenCoordinator: CoordinatorProtocol {
|
||||
analyticsService: parameters.analyticsService,
|
||||
userIndicatorController: parameters.userIndicatorController,
|
||||
notificationSettingsProxy: parameters.notificationSettings,
|
||||
attributedStringBuilder: parameters.attributedStringBuilder)
|
||||
attributedStringBuilder: parameters.attributedStringBuilder,
|
||||
appSettings: parameters.appSettings)
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
@@ -76,6 +79,8 @@ final class RoomDetailsScreenCoordinator: CoordinatorProtocol {
|
||||
actionsSubject.send(.presentNotificationSettingsScreen)
|
||||
case .requestPollsHistoryPresentation:
|
||||
actionsSubject.send(.presentPollsHistory)
|
||||
case .requestRolesAndPermissionsPresentation:
|
||||
actionsSubject.send(.presentRolesAndPermissionsScreen)
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
@@ -28,6 +28,7 @@ enum RoomDetailsScreenViewModelAction {
|
||||
case leftRoom
|
||||
case requestEditDetailsPresentation
|
||||
case requestPollsHistoryPresentation
|
||||
case requestRolesAndPermissionsPresentation
|
||||
}
|
||||
|
||||
// MARK: View
|
||||
@@ -47,6 +48,7 @@ struct RoomDetailsScreenViewState: BindableState {
|
||||
var canEditRoomName = false
|
||||
var canEditRoomTopic = false
|
||||
var canEditRoomAvatar = false
|
||||
var canEditRolesOrPermissions = false
|
||||
var notificationSettingsState: RoomDetailsNotificationSettingsState = .loading
|
||||
|
||||
var canEdit: Bool {
|
||||
@@ -177,10 +179,11 @@ enum RoomDetailsScreenViewAction {
|
||||
case ignoreConfirmed
|
||||
case unignoreConfirmed
|
||||
case processTapNotifications
|
||||
case processToogleMuteNotifications
|
||||
case processToggleMuteNotifications
|
||||
case displayAvatar
|
||||
case processTapPolls
|
||||
case toggleFavourite(isFavourite: Bool)
|
||||
case processTapRolesAndPermissions
|
||||
}
|
||||
|
||||
enum RoomDetailsScreenViewShortcut {
|
||||
|
||||
@@ -27,6 +27,7 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
||||
private let userIndicatorController: UserIndicatorControllerProtocol
|
||||
private let notificationSettingsProxy: NotificationSettingsProxyProtocol
|
||||
private let attributedStringBuilder: AttributedStringBuilderProtocol
|
||||
private let appSettings: AppSettings
|
||||
|
||||
private var dmRecipient: RoomMemberProxyProtocol?
|
||||
|
||||
@@ -42,7 +43,8 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
||||
analyticsService: AnalyticsService,
|
||||
userIndicatorController: UserIndicatorControllerProtocol,
|
||||
notificationSettingsProxy: NotificationSettingsProxyProtocol,
|
||||
attributedStringBuilder: AttributedStringBuilderProtocol) {
|
||||
attributedStringBuilder: AttributedStringBuilderProtocol,
|
||||
appSettings: AppSettings) {
|
||||
self.roomProxy = roomProxy
|
||||
self.clientProxy = clientProxy
|
||||
self.mediaProvider = mediaProvider
|
||||
@@ -50,6 +52,7 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
||||
self.userIndicatorController = userIndicatorController
|
||||
self.notificationSettingsProxy = notificationSettingsProxy
|
||||
self.attributedStringBuilder = attributedStringBuilder
|
||||
self.appSettings = appSettings
|
||||
|
||||
let topic = attributedStringBuilder.fromPlain(roomProxy.topic)
|
||||
|
||||
@@ -111,7 +114,7 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
||||
} else {
|
||||
actionsSubject.send(.requestNotificationSettingsPresentation)
|
||||
}
|
||||
case .processToogleMuteNotifications:
|
||||
case .processToggleMuteNotifications:
|
||||
Task { await toggleMuteNotifications() }
|
||||
case .displayAvatar:
|
||||
displayFullScreenAvatar()
|
||||
@@ -119,6 +122,8 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
||||
actionsSubject.send(.requestPollsHistoryPresentation)
|
||||
case .toggleFavourite(let isFavourite):
|
||||
Task { await toggleFavourite(isFavourite) }
|
||||
case .processTapRolesAndPermissions:
|
||||
actionsSubject.send(.requestRolesAndPermissionsPresentation)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,6 +177,9 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
||||
state.canEditRoomName = await roomProxy.canUser(userID: roomProxy.ownUserID, sendStateEvent: .roomName) == .success(true)
|
||||
state.canEditRoomTopic = await roomProxy.canUser(userID: roomProxy.ownUserID, sendStateEvent: .roomTopic) == .success(true)
|
||||
state.canEditRoomAvatar = await roomProxy.canUser(userID: roomProxy.ownUserID, sendStateEvent: .roomAvatar) == .success(true)
|
||||
if appSettings.roomModerationEnabled {
|
||||
state.canEditRolesOrPermissions = await roomProxy.canUser(userID: roomProxy.ownUserID, sendStateEvent: .roomPowerLevels) == .success(true)
|
||||
}
|
||||
state.canInviteUsers = await canInviteUsers
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ struct RoomDetailsScreen: View {
|
||||
|
||||
topicSection
|
||||
|
||||
notificationSection
|
||||
configurationSection
|
||||
|
||||
aboutSection
|
||||
|
||||
@@ -169,7 +169,7 @@ struct RoomDetailsScreen: View {
|
||||
}
|
||||
}
|
||||
|
||||
private var notificationSection: some View {
|
||||
private var configurationSection: some View {
|
||||
Section {
|
||||
ListRow(label: .default(title: L10n.screenRoomDetailsNotificationTitle,
|
||||
icon: \.notifications),
|
||||
@@ -188,13 +188,21 @@ struct RoomDetailsScreen: View {
|
||||
.onChange(of: context.isFavourite) { newValue in
|
||||
context.send(viewAction: .toggleFavourite(isFavourite: newValue))
|
||||
}
|
||||
|
||||
if context.viewState.canEditRolesOrPermissions, context.viewState.dmRecipient == nil {
|
||||
ListRow(label: .default(title: L10n.screenRoomDetailsRolesAndPermissions,
|
||||
icon: \.admin),
|
||||
kind: .navigationLink {
|
||||
context.send(viewAction: .processTapRolesAndPermissions)
|
||||
})
|
||||
}
|
||||
}
|
||||
.disabled(context.viewState.notificationSettingsState.isLoading)
|
||||
}
|
||||
|
||||
private var toggleMuteButton: some View {
|
||||
Button {
|
||||
context.send(viewAction: .processToogleMuteNotifications)
|
||||
context.send(viewAction: .processToggleMuteNotifications)
|
||||
} label: {
|
||||
if context.viewState.isProcessingMuteToggleAction {
|
||||
ProgressView()
|
||||
@@ -311,7 +319,8 @@ struct RoomDetailsScreen_Previews: PreviewProvider, TestablePreview {
|
||||
userIndicatorController: ServiceLocator.shared.userIndicatorController,
|
||||
notificationSettingsProxy: notificationSettingsProxy,
|
||||
attributedStringBuilder: AttributedStringBuilder(permalinkBaseURL: .userDirectory,
|
||||
mentionBuilder: MentionBuilder()))
|
||||
mentionBuilder: MentionBuilder()),
|
||||
appSettings: ServiceLocator.shared.settings)
|
||||
}()
|
||||
|
||||
static let dmRoomViewModel = {
|
||||
@@ -337,7 +346,8 @@ struct RoomDetailsScreen_Previews: PreviewProvider, TestablePreview {
|
||||
userIndicatorController: ServiceLocator.shared.userIndicatorController,
|
||||
notificationSettingsProxy: notificationSettingsProxy,
|
||||
attributedStringBuilder: AttributedStringBuilder(permalinkBaseURL: .userDirectory,
|
||||
mentionBuilder: MentionBuilder()))
|
||||
mentionBuilder: MentionBuilder()),
|
||||
appSettings: ServiceLocator.shared.settings)
|
||||
}()
|
||||
|
||||
static let simpleRoomViewModel = {
|
||||
@@ -362,7 +372,8 @@ struct RoomDetailsScreen_Previews: PreviewProvider, TestablePreview {
|
||||
userIndicatorController: ServiceLocator.shared.userIndicatorController,
|
||||
notificationSettingsProxy: notificationSettingsProxy,
|
||||
attributedStringBuilder: AttributedStringBuilder(permalinkBaseURL: .userDirectory,
|
||||
mentionBuilder: MentionBuilder()))
|
||||
mentionBuilder: MentionBuilder()),
|
||||
appSettings: ServiceLocator.shared.settings)
|
||||
}()
|
||||
|
||||
static var previews: some View {
|
||||
|
||||
Reference in New Issue
Block a user