generated from element-hq/.github
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
812 additions
and
99 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
.../Sources/Screens/RoomChangePermissionsScreen/RoomChangePermissionsScreenCoordinator.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// | ||
// Copyright 2022 New Vector Ltd | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
// periphery:ignore:all - this is just a roomChangePermissions remove this comment once generating the final file | ||
|
||
import Combine | ||
import SwiftUI | ||
|
||
struct RoomChangePermissionsScreenCoordinatorParameters { | ||
let permissions: RoomPermissions | ||
let permissionsGroup: RoomRolesAndPermissionsScreenPermissionsGroup | ||
let roomProxy: RoomProxyProtocol | ||
let userIndicatorController: UserIndicatorControllerProtocol | ||
} | ||
|
||
enum RoomChangePermissionsScreenCoordinatorAction { | ||
case cancel | ||
} | ||
|
||
final class RoomChangePermissionsScreenCoordinator: CoordinatorProtocol { | ||
private let parameters: RoomChangePermissionsScreenCoordinatorParameters | ||
private var viewModel: RoomChangePermissionsScreenViewModelProtocol | ||
private let actionsSubject: PassthroughSubject<RoomChangePermissionsScreenCoordinatorAction, Never> = .init() | ||
private var cancellables = Set<AnyCancellable>() | ||
|
||
var actions: AnyPublisher<RoomChangePermissionsScreenCoordinatorAction, Never> { | ||
actionsSubject.eraseToAnyPublisher() | ||
} | ||
|
||
init(parameters: RoomChangePermissionsScreenCoordinatorParameters) { | ||
self.parameters = parameters | ||
|
||
viewModel = RoomChangePermissionsScreenViewModel(currentPermissions: parameters.permissions, | ||
group: parameters.permissionsGroup, | ||
roomProxy: parameters.roomProxy, | ||
userIndicatorController: parameters.userIndicatorController) | ||
} | ||
|
||
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 .cancel: | ||
actionsSubject.send(.cancel) | ||
} | ||
} | ||
.store(in: &cancellables) | ||
} | ||
|
||
func toPresentable() -> AnyView { | ||
AnyView(RoomChangePermissionsScreen(context: viewModel.context)) | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
ElementX/Sources/Screens/RoomChangePermissionsScreen/RoomChangePermissionsScreenModels.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// | ||
// Copyright 2022 New Vector Ltd | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Foundation | ||
import MatrixRustSDK | ||
|
||
enum RoomChangePermissionsScreenViewModelAction { | ||
case cancel | ||
} | ||
|
||
struct RoomChangePermissionsScreenViewState: BindableState { | ||
/// The screen's title. | ||
let title: String | ||
/// The current permissions that are set on the room. | ||
var currentPermissions: RoomPermissions | ||
|
||
var bindings: RoomChangePermissionsScreenViewStateBindings | ||
|
||
/// Whether or not there are and changes to be saved. | ||
var hasChanges: Bool { | ||
bindings.settings.contains { currentPermissions[keyPath: $0.keyPath] ?? RoomPermissions.default[keyPath: $0.keyPath] != $0.value } | ||
} | ||
} | ||
|
||
struct RoomChangePermissionsScreenViewStateBindings: BindableState { | ||
/// All of the settings shown for this screen. | ||
var settings: [RoomPermissionsSetting] | ||
/// Information about the currently displayed alert. | ||
var alertInfo: AlertInfo<RoomChangePermissionsScreenAlertType>? | ||
} | ||
|
||
enum RoomChangePermissionsScreenAlertType { | ||
/// The generic error message. | ||
case generic | ||
} | ||
|
||
enum RoomChangePermissionsScreenViewAction { | ||
/// Save the permissions. | ||
case save | ||
} | ||
|
||
extension RoomChangePermissionsScreenViewState { | ||
/// Creates a view state for a particular group of permissions. | ||
/// - Parameters: | ||
/// - currentPermissions: The current permissions for the room. | ||
/// - group: The group of permissions that should be shown in the screen. | ||
init(currentPermissions: RoomPermissions, group: RoomRolesAndPermissionsScreenPermissionsGroup) { | ||
switch group { | ||
case .roomDetails: | ||
// swiftlint:disable force_unwrapping | ||
let settings = [ | ||
RoomPermissionsSetting(keyPath: \.roomName, | ||
value: currentPermissions.roomName ?? RoomPermissions.default.roomName!, | ||
title: L10n.screenRoomChangePermissionsRoomName), | ||
RoomPermissionsSetting(keyPath: \.roomAvatar, | ||
value: currentPermissions.roomAvatar ?? RoomPermissions.default.roomAvatar!, | ||
title: L10n.screenRoomChangePermissionsRoomAvatar), | ||
RoomPermissionsSetting(keyPath: \.roomTopic, | ||
value: currentPermissions.roomTopic ?? RoomPermissions.default.roomTopic!, | ||
title: L10n.screenRoomChangePermissionsRoomTopic) | ||
] | ||
// swiftlint:enable force_unwrapping | ||
|
||
self.init(title: L10n.screenRoomChangePermissionsRoomDetails, currentPermissions: currentPermissions, bindings: .init(settings: settings)) | ||
|
||
case .messagesAndContent: | ||
// swiftlint:disable force_unwrapping | ||
let settings = [ | ||
RoomPermissionsSetting(keyPath: \.eventsDefault, | ||
value: currentPermissions.eventsDefault ?? RoomPermissions.default.eventsDefault!, | ||
title: L10n.screenRoomChangePermissionsSendMessages), | ||
RoomPermissionsSetting(keyPath: \.redact, | ||
value: currentPermissions.redact ?? RoomPermissions.default.redact!, | ||
title: L10n.screenRoomChangePermissionsDeleteMessages) | ||
] | ||
// swiftlint:enable force_unwrapping | ||
|
||
self.init(title: L10n.screenRoomChangePermissionsMessagesAndContent, currentPermissions: currentPermissions, bindings: .init(settings: settings)) | ||
|
||
case .memberModeration: | ||
// swiftlint:disable force_unwrapping | ||
let settings = [ | ||
RoomPermissionsSetting(keyPath: \.invite, | ||
value: currentPermissions.invite ?? RoomPermissions.default.invite!, | ||
title: L10n.screenRoomChangePermissionsInvitePeople), | ||
RoomPermissionsSetting(keyPath: \.kick, | ||
value: currentPermissions.kick ?? RoomPermissions.default.kick!, | ||
title: L10n.screenRoomChangePermissionsRemovePeople), | ||
RoomPermissionsSetting(keyPath: \.ban, | ||
value: currentPermissions.ban ?? RoomPermissions.default.ban!, | ||
title: L10n.screenRoomChangePermissionsBanPeople) | ||
] | ||
// swiftlint:enable force_unwrapping | ||
|
||
self.init(title: L10n.screenRoomChangePermissionsMemberModeration, currentPermissions: currentPermissions, bindings: .init(settings: settings)) | ||
} | ||
} | ||
} |
Oops, something went wrong.