mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
feat: decline and block screen
fix improvement fix conflict fix tests tests
This commit is contained in:
@@ -57,6 +57,7 @@ final class AppSettings {
|
||||
case enableOnlySignedDeviceIsolationMode
|
||||
case knockingEnabled
|
||||
case reportRoomEnabled
|
||||
case reportInviteEnabled
|
||||
}
|
||||
|
||||
private static var suiteName: String = InfoPlistReader.main.appGroupIdentifier
|
||||
@@ -333,6 +334,9 @@ final class AppSettings {
|
||||
|
||||
@UserPreference(key: UserDefaultsKeys.reportRoomEnabled, defaultValue: false, storageType: .userDefaults(store)) var reportRoomEnabled
|
||||
|
||||
@UserPreference(key: UserDefaultsKeys.reportInviteEnabled, defaultValue: false, storageType: .userDefaults(store))
|
||||
var reportInviteEnabled
|
||||
|
||||
#endif
|
||||
|
||||
// MARK: - Shared
|
||||
|
||||
@@ -419,6 +419,11 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
|
||||
return .reportRoom(previousState: fromState)
|
||||
case (.reportRoom(let previousState), .dismissReportRoomScreen):
|
||||
return previousState
|
||||
|
||||
case (.joinRoomScreen, .presentDeclineAndBlockScreen):
|
||||
return .declineAndBlockScreen
|
||||
case (.declineAndBlockScreen, .dismissDeclineAndBlockScreen):
|
||||
return .joinRoomScreen
|
||||
|
||||
default:
|
||||
return nil
|
||||
@@ -595,6 +600,11 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
|
||||
presentReportRoom()
|
||||
case (.reportRoom, .dismissReportRoomScreen, .roomDetails):
|
||||
break
|
||||
|
||||
case (.joinRoomScreen, .presentDeclineAndBlockScreen(let userID), .declineAndBlockScreen):
|
||||
presentDeclineAndBlockScreen(userID: userID)
|
||||
case (.declineAndBlockScreen, .dismissDeclineAndBlockScreen, .joinRoomScreen):
|
||||
break
|
||||
|
||||
// Child flow
|
||||
case (_, .startChildFlow(let roomID, let via, let entryPoint), .presentingChild):
|
||||
@@ -799,6 +809,8 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
|
||||
}
|
||||
case .cancelled:
|
||||
stateMachine.tryEvent(.dismissJoinRoomScreen)
|
||||
case .presentDeclineAndBlock(let userID):
|
||||
stateMachine.tryEvent(.presentDeclineAndBlockScreen(userID: userID))
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
@@ -1551,6 +1563,30 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
private func presentDeclineAndBlockScreen(userID: String) {
|
||||
let stackCoordinator = NavigationStackCoordinator()
|
||||
let coordinator = DeclineAndBlockScreenCoordinator(parameters: .init(userID: userID,
|
||||
roomID: roomID,
|
||||
clientProxy: userSession.clientProxy,
|
||||
userIndicatorController: userIndicatorController))
|
||||
coordinator.actionsPublisher.sink { [weak self] action in
|
||||
guard let self else { return }
|
||||
switch action {
|
||||
case .dismiss(let hasDeclined):
|
||||
if hasDeclined {
|
||||
stateMachine.tryEvent(.dismissFlow)
|
||||
}
|
||||
navigationStackCoordinator.setSheetCoordinator(nil)
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
stackCoordinator.setRootCoordinator(coordinator)
|
||||
navigationStackCoordinator.setSheetCoordinator(stackCoordinator) { [weak self] in
|
||||
self?.stateMachine.tryEvent(.dismissDeclineAndBlockScreen)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Other flows
|
||||
|
||||
private func startChildFlow(for roomID: String, via: [String], entryPoint: RoomFlowCoordinatorEntryPoint) async {
|
||||
@@ -1722,6 +1758,7 @@ private extension RoomFlowCoordinator {
|
||||
case mediaEventsTimeline(previousState: State)
|
||||
case securityAndPrivacy(previousState: State)
|
||||
case reportRoom(previousState: State)
|
||||
case declineAndBlockScreen
|
||||
|
||||
/// A child flow is in progress.
|
||||
case presentingChild(childRoomID: String, previousState: State)
|
||||
@@ -1811,5 +1848,8 @@ private extension RoomFlowCoordinator {
|
||||
|
||||
case presentReportRoomScreen
|
||||
case dismissReportRoomScreen
|
||||
|
||||
case presentDeclineAndBlockScreen(userID: String)
|
||||
case dismissDeclineAndBlockScreen
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,6 +312,11 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
|
||||
case (.reportRoomScreen, .dismissedReportRoomScreen, .roomList):
|
||||
break
|
||||
|
||||
case (.roomList, .presentDeclineAndBlockScreen(let userID, let roomID), .declineAndBlockUserScreen):
|
||||
presentDeclineAndBlockScreen(userID: userID, roomID: roomID)
|
||||
case (.declineAndBlockUserScreen, .dismissedDeclineAndBlockScreen, .roomList):
|
||||
break
|
||||
|
||||
case (.roomList(let roomListSelectedRoomID), .showShareExtensionRoomList, .shareExtensionRoomList(let sharePayload)):
|
||||
Task {
|
||||
if roomListSelectedRoomID != nil {
|
||||
@@ -526,6 +531,8 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
|
||||
self.actionsSubject.send(.logout)
|
||||
case .logout:
|
||||
Task { await self.runLogoutFlow() }
|
||||
case .presentDeclineAndBlock(let userID, let roomID):
|
||||
stateMachine.processEvent(.presentDeclineAndBlockScreen(userID: userID, roomID: roomID))
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
@@ -564,6 +571,28 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
private func presentDeclineAndBlockScreen(userID: String, roomID: String) {
|
||||
let stackCoordinator = NavigationStackCoordinator()
|
||||
let coordinator = DeclineAndBlockScreenCoordinator(parameters: .init(userID: userID,
|
||||
roomID: roomID,
|
||||
clientProxy: userSession.clientProxy,
|
||||
userIndicatorController: ServiceLocator.shared.userIndicatorController))
|
||||
coordinator.actionsPublisher.sink { [weak self] action in
|
||||
guard let self else { return }
|
||||
|
||||
switch action {
|
||||
case .dismiss:
|
||||
navigationSplitCoordinator.setSheetCoordinator(nil)
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
stackCoordinator.setRootCoordinator(coordinator)
|
||||
navigationSplitCoordinator.setSheetCoordinator(stackCoordinator) { [weak self] in
|
||||
self?.stateMachine.processEvent(.dismissedDeclineAndBlockScreen)
|
||||
}
|
||||
}
|
||||
|
||||
private func runLogoutFlow() async {
|
||||
let secureBackupController = userSession.clientProxy.secureBackupController
|
||||
|
||||
|
||||
@@ -47,6 +47,8 @@ class UserSessionFlowCoordinatorStateMachine {
|
||||
|
||||
case shareExtensionRoomList(sharePayload: ShareExtensionPayload)
|
||||
|
||||
case declineAndBlockUserScreen(roomListSelectedRoomID: String?)
|
||||
|
||||
/// The selected room ID from the state if available.
|
||||
var roomListSelectedRoomID: String? {
|
||||
switch self {
|
||||
@@ -60,7 +62,8 @@ class UserSessionFlowCoordinatorStateMachine {
|
||||
.startChatScreen(let roomListSelectedRoomID),
|
||||
.logoutConfirmationScreen(let roomListSelectedRoomID),
|
||||
.roomDirectorySearchScreen(let roomListSelectedRoomID),
|
||||
.reportRoomScreen(let roomListSelectedRoomID):
|
||||
.reportRoomScreen(let roomListSelectedRoomID),
|
||||
.declineAndBlockUserScreen(let roomListSelectedRoomID):
|
||||
roomListSelectedRoomID
|
||||
}
|
||||
}
|
||||
@@ -128,6 +131,9 @@ class UserSessionFlowCoordinatorStateMachine {
|
||||
|
||||
case presentReportRoomScreen(roomID: String)
|
||||
case dismissedReportRoomScreen
|
||||
|
||||
case presentDeclineAndBlockScreen(userID: String, roomID: String)
|
||||
case dismissedDeclineAndBlockScreen
|
||||
}
|
||||
|
||||
private let stateMachine: StateMachine<State, Event>
|
||||
@@ -206,6 +212,11 @@ class UserSessionFlowCoordinatorStateMachine {
|
||||
case (.reportRoomScreen(let roomListSelectedRoomID), .dismissedReportRoomScreen):
|
||||
return .roomList(roomListSelectedRoomID: roomListSelectedRoomID)
|
||||
|
||||
case(.roomList(let roomListSelectedRoomID), .presentDeclineAndBlockScreen):
|
||||
return .declineAndBlockUserScreen(roomListSelectedRoomID: roomListSelectedRoomID)
|
||||
case (.declineAndBlockUserScreen(let roomListSelectedRoomID), .dismissedDeclineAndBlockScreen):
|
||||
return .roomList(roomListSelectedRoomID: roomListSelectedRoomID)
|
||||
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -3383,6 +3383,76 @@ class ClientProxyMock: ClientProxyProtocol, @unchecked Sendable {
|
||||
return roomSummaryForAliasReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - reportRoomForIdentifier
|
||||
|
||||
var reportRoomForIdentifierReasonUnderlyingCallsCount = 0
|
||||
var reportRoomForIdentifierReasonCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return reportRoomForIdentifierReasonUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = reportRoomForIdentifierReasonUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
reportRoomForIdentifierReasonUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
reportRoomForIdentifierReasonUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var reportRoomForIdentifierReasonCalled: Bool {
|
||||
return reportRoomForIdentifierReasonCallsCount > 0
|
||||
}
|
||||
var reportRoomForIdentifierReasonReceivedArguments: (identifier: String, reason: String?)?
|
||||
var reportRoomForIdentifierReasonReceivedInvocations: [(identifier: String, reason: String?)] = []
|
||||
|
||||
var reportRoomForIdentifierReasonUnderlyingReturnValue: Result<Void, ClientProxyError>!
|
||||
var reportRoomForIdentifierReasonReturnValue: Result<Void, ClientProxyError>! {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return reportRoomForIdentifierReasonUnderlyingReturnValue
|
||||
} else {
|
||||
var returnValue: Result<Void, ClientProxyError>? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = reportRoomForIdentifierReasonUnderlyingReturnValue
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
reportRoomForIdentifierReasonUnderlyingReturnValue = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
reportRoomForIdentifierReasonUnderlyingReturnValue = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var reportRoomForIdentifierReasonClosure: ((String, String?) async -> Result<Void, ClientProxyError>)?
|
||||
|
||||
func reportRoomForIdentifier(_ identifier: String, reason: String?) async -> Result<Void, ClientProxyError> {
|
||||
reportRoomForIdentifierReasonCallsCount += 1
|
||||
reportRoomForIdentifierReasonReceivedArguments = (identifier: identifier, reason: reason)
|
||||
DispatchQueue.main.async {
|
||||
self.reportRoomForIdentifierReasonReceivedInvocations.append((identifier: identifier, reason: reason))
|
||||
}
|
||||
if let reportRoomForIdentifierReasonClosure = reportRoomForIdentifierReasonClosure {
|
||||
return await reportRoomForIdentifierReasonClosure(identifier, reason)
|
||||
} else {
|
||||
return reportRoomForIdentifierReasonReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - loadUserDisplayName
|
||||
|
||||
var loadUserDisplayNameUnderlyingCallsCount = 0
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
//
|
||||
// Copyright 2022-2024 New Vector Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
// periphery:ignore:all - this is just a reportInvite remove this comment once generating the final file
|
||||
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
struct DeclineAndBlockScreenCoordinatorParameters {
|
||||
let userID: String
|
||||
let roomID: String
|
||||
let clientProxy: ClientProxyProtocol
|
||||
let userIndicatorController: UserIndicatorControllerProtocol
|
||||
}
|
||||
|
||||
enum DeclineAndBlockScreenCoordinatorAction {
|
||||
case dismiss(hasDeclined: Bool)
|
||||
}
|
||||
|
||||
final class DeclineAndBlockScreenCoordinator: CoordinatorProtocol {
|
||||
private let parameters: DeclineAndBlockScreenCoordinatorParameters
|
||||
private let viewModel: DeclineAndBlockScreenViewModelProtocol
|
||||
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
private let actionsSubject: PassthroughSubject<DeclineAndBlockScreenCoordinatorAction, Never> = .init()
|
||||
var actionsPublisher: AnyPublisher<DeclineAndBlockScreenCoordinatorAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init(parameters: DeclineAndBlockScreenCoordinatorParameters) {
|
||||
self.parameters = parameters
|
||||
|
||||
viewModel = DeclineAndBlockScreenViewModel(userID: parameters.userID,
|
||||
roomID: parameters.roomID,
|
||||
clientProxy: parameters.clientProxy,
|
||||
userIndicatorController: parameters.userIndicatorController)
|
||||
}
|
||||
|
||||
func start() {
|
||||
viewModel.actionsPublisher.sink { [weak self] action in
|
||||
MXLog.info("Coordinator: received view model action: \(action)")
|
||||
|
||||
guard let self else { return }
|
||||
switch action {
|
||||
case .dismiss(let hasDeclined):
|
||||
actionsSubject.send(.dismiss(hasDeclined: hasDeclined))
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
func toPresentable() -> AnyView {
|
||||
AnyView(DeclineAndBlockScreen(context: viewModel.context))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// Copyright 2022-2024 New Vector Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
enum DeclineAndBlockScreenViewModelAction {
|
||||
case dismiss(hasDeclined: Bool)
|
||||
}
|
||||
|
||||
struct DeclineAndBlockScreenViewState: BindableState {
|
||||
var bindings = DeclineAndBlockScreenViewStateBindings()
|
||||
|
||||
var isDeclineDisabled: Bool {
|
||||
!bindings.shouldBlockUser && !bindings.shouldReport
|
||||
}
|
||||
}
|
||||
|
||||
struct DeclineAndBlockScreenViewStateBindings {
|
||||
var shouldBlockUser = true
|
||||
var shouldReport = false
|
||||
var reportReason = ""
|
||||
}
|
||||
|
||||
enum DeclineAndBlockScreenViewAction {
|
||||
case decline
|
||||
case dismiss
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
//
|
||||
// Copyright 2022-2024 New Vector 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 DeclineAndBlockScreenViewModelType = StateStoreViewModel<DeclineAndBlockScreenViewState, DeclineAndBlockScreenViewAction>
|
||||
|
||||
class DeclineAndBlockScreenViewModel: DeclineAndBlockScreenViewModelType, DeclineAndBlockScreenViewModelProtocol {
|
||||
let userID: String
|
||||
let roomID: String
|
||||
let clientProxy: ClientProxyProtocol
|
||||
let userIndicatorController: UserIndicatorControllerProtocol
|
||||
|
||||
private let actionsSubject: PassthroughSubject<DeclineAndBlockScreenViewModelAction, Never> = .init()
|
||||
var actionsPublisher: AnyPublisher<DeclineAndBlockScreenViewModelAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init(userID: String,
|
||||
roomID: String,
|
||||
clientProxy: ClientProxyProtocol,
|
||||
userIndicatorController: UserIndicatorControllerProtocol) {
|
||||
self.userID = userID
|
||||
self.roomID = roomID
|
||||
self.clientProxy = clientProxy
|
||||
self.userIndicatorController = userIndicatorController
|
||||
super.init(initialViewState: DeclineAndBlockScreenViewState())
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
override func process(viewAction: DeclineAndBlockScreenViewAction) {
|
||||
MXLog.info("View model: received view action: \(viewAction)")
|
||||
|
||||
switch viewAction {
|
||||
case .dismiss:
|
||||
actionsSubject.send(.dismiss(hasDeclined: false))
|
||||
case .decline:
|
||||
Task { await decline() }
|
||||
}
|
||||
}
|
||||
|
||||
private func decline() async {
|
||||
showLoadingIndicator()
|
||||
guard case let .invited(roomProxy) = await clientProxy.roomForIdentifier(roomID) else {
|
||||
MXLog.error("DeclineAndBlockScreenViewModel: Unable to find an invited room for identifier \(roomID)")
|
||||
hideLoadingIndicator()
|
||||
showError()
|
||||
return
|
||||
}
|
||||
|
||||
let result = await roomProxy.rejectInvitation()
|
||||
hideLoadingIndicator()
|
||||
|
||||
// TODO: Check with design how to handle the error cases and what message to present for success and error
|
||||
switch result {
|
||||
case .success:
|
||||
if state.bindings.shouldReport {
|
||||
Task {
|
||||
await clientProxy.reportRoomForIdentifier(roomID, reason: state.bindings.reportReason.isBlank ? nil : state.bindings.reportReason)
|
||||
}
|
||||
}
|
||||
|
||||
if state.bindings.shouldBlockUser {
|
||||
Task {
|
||||
await clientProxy.ignoreUser(userID)
|
||||
}
|
||||
}
|
||||
|
||||
actionsSubject.send(.dismiss(hasDeclined: true))
|
||||
case .failure:
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
}
|
||||
}
|
||||
|
||||
private static let loadingIndicator = "\(DeclineAndBlockScreenViewModel.self).loadingIndicator"
|
||||
|
||||
private func showLoadingIndicator() {
|
||||
userIndicatorController.submitIndicator(.init(id: Self.loadingIndicator,
|
||||
type: .modal(progress: .indeterminate,
|
||||
interactiveDismissDisabled: true,
|
||||
allowsInteraction: false),
|
||||
title: L10n.commonLoading,
|
||||
persistent: true))
|
||||
}
|
||||
|
||||
private func hideLoadingIndicator() {
|
||||
userIndicatorController.retractIndicatorWithId(Self.loadingIndicator)
|
||||
}
|
||||
|
||||
private func showError() {
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// Copyright 2022-2024 New Vector 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
|
||||
|
||||
@MainActor
|
||||
protocol DeclineAndBlockScreenViewModelProtocol {
|
||||
var actionsPublisher: AnyPublisher<DeclineAndBlockScreenViewModelAction, Never> { get }
|
||||
var context: DeclineAndBlockScreenViewModelType.Context { get }
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
//
|
||||
// Copyright 2022-2024 New Vector Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import Compound
|
||||
import SwiftUI
|
||||
|
||||
struct DeclineAndBlockScreen: View {
|
||||
@ObservedObject var context: DeclineAndBlockScreenViewModel.Context
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
blockUserSection
|
||||
reportSection
|
||||
if context.shouldReport {
|
||||
reportReasonSection
|
||||
}
|
||||
}
|
||||
.compoundList()
|
||||
.navigationTitle(L10n.screenDeclineAndBlockTitle)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar { toolbar }
|
||||
.animation(.elementDefault, value: context.shouldReport)
|
||||
}
|
||||
|
||||
private var blockUserSection: some View {
|
||||
Section {
|
||||
ListRow(label: .plain(title: L10n.screenDeclineAndBlockBlockUserOptionTitle),
|
||||
kind: .toggle($context.shouldBlockUser))
|
||||
}
|
||||
}
|
||||
|
||||
private var reportSection: some View {
|
||||
Section {
|
||||
ListRow(label: .plain(title: L10n.actionReportRoom),
|
||||
kind: .toggle($context.shouldReport))
|
||||
}
|
||||
}
|
||||
|
||||
private var reportReasonSection: some View {
|
||||
Section {
|
||||
ListRow(label: .plain(title: ""),
|
||||
kind: .textField(text: $context.reportReason, axis: .vertical))
|
||||
.lineLimit(4, reservesSpace: true)
|
||||
}
|
||||
}
|
||||
|
||||
@ToolbarContentBuilder
|
||||
private var toolbar: some ToolbarContent {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button(L10n.actionCancel) {
|
||||
context.send(viewAction: .dismiss)
|
||||
}
|
||||
}
|
||||
|
||||
ToolbarItem(placement: .confirmationAction) {
|
||||
Button(L10n.actionDecline) {
|
||||
context.send(viewAction: .decline)
|
||||
}
|
||||
.disabled(context.viewState.isDeclineDisabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct DeclineAndBlockScreen_Previews: PreviewProvider, TestablePreview {
|
||||
static let viewModel = DeclineAndBlockScreenViewModel(userID: "@alice:matrix.org",
|
||||
roomID: "!room:matrix.org",
|
||||
clientProxy: ClientProxyMock(.init()),
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
|
||||
static var previews: some View {
|
||||
NavigationStack {
|
||||
DeclineAndBlockScreen(context: viewModel.context)
|
||||
}
|
||||
.previewDisplayName("Default")
|
||||
NavigationStack {
|
||||
DeclineAndBlockScreen(context: viewModel.context)
|
||||
.onAppear {
|
||||
viewModel.context.shouldReport = true
|
||||
}
|
||||
}
|
||||
.previewDisplayName("Report room selected")
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ enum HomeScreenCoordinatorAction {
|
||||
case presentRoom(roomIdentifier: String)
|
||||
case presentRoomDetails(roomIdentifier: String)
|
||||
case presentReportRoom(roomIdentifier: String)
|
||||
case presentDeclineAndBlock(userID: String, roomID: String)
|
||||
case roomLeft(roomIdentifier: String)
|
||||
case presentSettingsScreen
|
||||
case presentFeedbackScreen
|
||||
@@ -81,6 +82,8 @@ final class HomeScreenCoordinator: CoordinatorProtocol {
|
||||
actionsSubject.send(.logoutWithoutConfirmation)
|
||||
case .logout:
|
||||
actionsSubject.send(.logout)
|
||||
case .presentDeclineAndBlock(let userID, let roomID):
|
||||
actionsSubject.send(.presentDeclineAndBlock(userID: userID, roomID: roomID))
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
@@ -13,6 +13,7 @@ enum HomeScreenViewModelAction: Equatable {
|
||||
case presentRoom(roomIdentifier: String)
|
||||
case presentRoomDetails(roomIdentifier: String)
|
||||
case presentReportRoom(roomIdentifier: String)
|
||||
case presentDeclineAndBlock(userID: String, roomID: String)
|
||||
case roomLeft(roomIdentifier: String)
|
||||
case presentSecureBackupSettings
|
||||
case presentRecoveryKeyScreen
|
||||
|
||||
@@ -426,11 +426,24 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
let title = room.isDirect ? L10n.screenInvitesDeclineDirectChatTitle : L10n.screenInvitesDeclineChatTitle
|
||||
let message = room.isDirect ? L10n.screenInvitesDeclineDirectChatMessage(roomPlaceholder) : L10n.screenInvitesDeclineChatMessage(roomPlaceholder)
|
||||
|
||||
state.bindings.alertInfo = .init(id: UUID(),
|
||||
title: title,
|
||||
message: message,
|
||||
primaryButton: .init(title: L10n.actionDecline, role: .destructive) { Task { await self.declineInvite(roomID: room.id) } },
|
||||
secondaryButton: .init(title: L10n.actionCancel, role: .cancel, action: nil))
|
||||
if appSettings.reportInviteEnabled, let userID = room.inviter?.id {
|
||||
state.bindings.alertInfo = .init(id: UUID(),
|
||||
title: title,
|
||||
message: message,
|
||||
primaryButton: .init(title: L10n.actionCancel, role: .cancel, action: nil),
|
||||
secondaryButton: .init(title: L10n.actionDeclineAndBlock, role: .destructive) { [weak self] in self?.declineAndBlockInvite(userID: userID, roomID: roomID) },
|
||||
verticalButtons: [.init(title: L10n.actionDecline) { [weak self] in Task { await self?.declineInvite(roomID: room.id) } }])
|
||||
} else {
|
||||
state.bindings.alertInfo = .init(id: UUID(),
|
||||
title: title,
|
||||
message: message,
|
||||
primaryButton: .init(title: L10n.actionCancel, role: .cancel, action: nil),
|
||||
secondaryButton: .init(title: L10n.actionDecline, role: .destructive) { [weak self] in Task { await self?.declineInvite(roomID: room.id) } })
|
||||
}
|
||||
}
|
||||
|
||||
private func declineAndBlockInvite(userID: String, roomID: String) {
|
||||
actionsSubject.send(.presentDeclineAndBlock(userID: userID, roomID: roomID))
|
||||
}
|
||||
|
||||
private func declineInvite(roomID: String) async {
|
||||
|
||||
@@ -20,6 +20,7 @@ struct JoinRoomScreenCoordinatorParameters {
|
||||
enum JoinRoomScreenCoordinatorAction {
|
||||
case joined
|
||||
case cancelled
|
||||
case presentDeclineAndBlock(userID: String)
|
||||
}
|
||||
|
||||
final class JoinRoomScreenCoordinator: CoordinatorProtocol {
|
||||
@@ -51,6 +52,8 @@ final class JoinRoomScreenCoordinator: CoordinatorProtocol {
|
||||
actionsSubject.send(.joined)
|
||||
case .dismiss:
|
||||
actionsSubject.send(.cancelled)
|
||||
case .presentDeclineAndBlock(let userID):
|
||||
actionsSubject.send(.presentDeclineAndBlock(userID: userID))
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
@@ -7,9 +7,10 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
enum JoinRoomScreenViewModelAction {
|
||||
enum JoinRoomScreenViewModelAction: Equatable {
|
||||
case joined
|
||||
case dismiss
|
||||
case presentDeclineAndBlock(userID: String)
|
||||
}
|
||||
|
||||
enum JoinRoomScreenMode: Equatable {
|
||||
|
||||
@@ -323,11 +323,15 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
|
||||
}
|
||||
|
||||
private func showDeclineAndBlockConfirmationAlert(userID: String) {
|
||||
state.bindings.alertInfo = .init(id: .declineInviteAndBlock,
|
||||
title: L10n.screenJoinRoomDeclineAndBlockAlertTitle,
|
||||
message: L10n.screenJoinRoomDeclineAndBlockAlertMessage(userID),
|
||||
primaryButton: .init(title: L10n.actionCancel, role: .cancel, action: nil),
|
||||
secondaryButton: .init(title: L10n.screenJoinRoomDeclineAndBlockAlertConfirmation, role: .destructive) { Task { await self.declineAndBlock(userID: userID) } })
|
||||
if appSettings.reportInviteEnabled {
|
||||
actionsSubject.send(.presentDeclineAndBlock(userID: userID))
|
||||
} else {
|
||||
state.bindings.alertInfo = .init(id: .declineInviteAndBlock,
|
||||
title: L10n.screenJoinRoomDeclineAndBlockAlertTitle,
|
||||
message: L10n.screenJoinRoomDeclineAndBlockAlertMessage(userID),
|
||||
primaryButton: .init(title: L10n.actionCancel, role: .cancel, action: nil),
|
||||
secondaryButton: .init(title: L10n.screenJoinRoomDeclineAndBlockAlertConfirmation, role: .destructive) { Task { await self.declineAndBlock(userID: userID) } })
|
||||
}
|
||||
}
|
||||
|
||||
private func declineAndBlock(userID: String) async {
|
||||
|
||||
+1
@@ -45,6 +45,7 @@ protocol DeveloperOptionsProtocol: AnyObject {
|
||||
var elementCallBaseURLOverride: URL? { get set }
|
||||
var knockingEnabled: Bool { get set }
|
||||
var reportRoomEnabled: Bool { get set }
|
||||
var reportInviteEnabled: Bool { get set }
|
||||
}
|
||||
|
||||
extension AppSettings: DeveloperOptionsProtocol { }
|
||||
|
||||
+4
@@ -68,6 +68,10 @@ struct DeveloperOptionsScreen: View {
|
||||
Text("Report rooms")
|
||||
Text("Report API might not work properly")
|
||||
}
|
||||
Toggle(isOn: $context.reportInviteEnabled) {
|
||||
Text("Report invites")
|
||||
Text("Report API might not work properly")
|
||||
}
|
||||
}
|
||||
|
||||
Section {
|
||||
|
||||
@@ -529,6 +529,20 @@ class ClientProxy: ClientProxyProtocol {
|
||||
func roomSummaryForAlias(_ alias: String) -> RoomSummary? {
|
||||
staticRoomSummaryProvider.roomListPublisher.value.first { $0.canonicalAlias == alias || $0.alternativeAliases.contains(alias) }
|
||||
}
|
||||
|
||||
func reportRoomForIdentifier(_ identifier: String, reason: String?) async -> Result<Void, ClientProxyError> {
|
||||
do {
|
||||
guard let room = try client.getRoom(roomId: identifier) else {
|
||||
MXLog.error("Failed reporting room with identifier: \(identifier), room not in local store")
|
||||
return .failure(.roomNotInLocalStore)
|
||||
}
|
||||
try await room.reportRoom(reason: reason)
|
||||
return .success(())
|
||||
} catch {
|
||||
MXLog.error("Failed reporting room with identifier: \(identifier), with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
func loadUserDisplayName() async -> Result<Void, ClientProxyError> {
|
||||
do {
|
||||
|
||||
@@ -38,6 +38,7 @@ enum ClientProxyError: Error {
|
||||
case roomPreviewIsPrivate
|
||||
case failedRetrievingUserIdentity
|
||||
case failedResolvingRoomAlias
|
||||
case roomNotInLocalStore
|
||||
}
|
||||
|
||||
enum SlidingSyncConstants {
|
||||
@@ -152,6 +153,9 @@ protocol ClientProxyProtocol: AnyObject, MediaLoaderProtocol {
|
||||
|
||||
func roomSummaryForAlias(_ alias: String) -> RoomSummary?
|
||||
|
||||
/// Will only work for rooms that are in our room list/local store
|
||||
func reportRoomForIdentifier(_ identifier: String, reason: String?) async -> Result<Void, ClientProxyError>
|
||||
|
||||
@discardableResult func loadUserDisplayName() async -> Result<Void, ClientProxyError>
|
||||
|
||||
func setUserDisplayName(_ name: String) async -> Result<Void, ClientProxyError>
|
||||
|
||||
Reference in New Issue
Block a user