Skip to content

Commit

Permalink
Refactor into a dedicated screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Aug 31, 2024
1 parent c0ecdb6 commit b6d0d1a
Show file tree
Hide file tree
Showing 17 changed files with 455 additions and 275 deletions.
52 changes: 40 additions & 12 deletions ElementX.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,11 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
case (.roomDetails, .presentRoomMemberDetails(let userID)):
return .roomMemberDetails(userID: userID, previousState: fromState)

case (.room, .presentResolveSendFailure):
return .resolveSendFailure
case (.resolveSendFailure, .dismissResolveSendFailure):
return .room

// Child flow

case (_, .startChildFlow(let roomID, _, _)):
Expand Down Expand Up @@ -508,6 +513,11 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
case (.roomMemberDetails, .dismissUserProfile, .roomDetails):
break

case (.room, .presentResolveSendFailure(let failure, let itemID), .resolveSendFailure):
presentResolveSendFailure(failure: failure, itemID: itemID)
case (.resolveSendFailure, .dismissResolveSendFailure, .room):
break

// Child flow
case (_, .startChildFlow(let roomID, let via, let entryPoint), .presentingChild):
Task { await self.startChildFlow(for: roomID, via: via, entryPoint: entryPoint) }
Expand Down Expand Up @@ -632,6 +642,8 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
actionsSubject.send(.presentCallScreen(roomProxy: roomProxy))
case .presentPinnedEventsTimeline:
stateMachine.tryEvent(.presentPinnedEventsTimeline)
case .presentResolveSendFailure(failure: let failure, itemID: let itemID):
stateMachine.tryEvent(.presentResolveSendFailure(failure: failure, itemID: itemID))
}
}
.store(in: &cancellables)
Expand Down Expand Up @@ -1360,6 +1372,25 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
coordinator.start()
}

private func presentResolveSendFailure(failure: TimelineItemSendFailure.VerifiedUser, itemID: TimelineItemIdentifier) {
let coordinator = ResolveVerifiedUserSendFailureScreenCoordinator(parameters: .init(failure: failure,
itemID: itemID,
roomProxy: roomProxy))
coordinator.actionsPublisher.sink { [weak self] action in
guard let self else { return }

switch action {
case .dismiss:
navigationStackCoordinator.setSheetCoordinator(nil)
}
}
.store(in: &cancellables)

navigationStackCoordinator.setSheetCoordinator(coordinator) { [weak self] in
self?.stateMachine.tryEvent(.dismissResolveSendFailure)
}
}

// MARK: - Child Flow

private func startChildFlow(for roomID: String, via: [String], entryPoint: RoomFlowCoordinatorEntryPoint) async {
Expand Down Expand Up @@ -1434,6 +1465,7 @@ private extension RoomFlowCoordinator {
case pollsHistoryForm
case rolesAndPermissions
case pinnedEventsTimeline(previousState: PinnedEventsTimelineSource)
case resolveSendFailure

/// A child flow is in progress.
case presentingChild(childRoomID: String, previousState: State)
Expand Down Expand Up @@ -1506,6 +1538,9 @@ private extension RoomFlowCoordinator {
case presentPinnedEventsTimeline
case dismissPinnedEventsTimeline

case presentResolveSendFailure(failure: TimelineItemSendFailure.VerifiedUser, itemID: TimelineItemIdentifier)
case dismissResolveSendFailure

// Child room flow events
case startChildFlow(roomID: String, via: [String], entryPoint: RoomFlowCoordinatorEntryPoint)
case dismissChildFlow
Expand Down
92 changes: 46 additions & 46 deletions ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11664,6 +11664,52 @@ open class RoomSDKMock: MatrixRustSDK.Room {
}
}

//MARK: - ignoreDeviceTrustAndResend

open var ignoreDeviceTrustAndResendDevicesTransactionIdThrowableError: Error?
var ignoreDeviceTrustAndResendDevicesTransactionIdUnderlyingCallsCount = 0
open var ignoreDeviceTrustAndResendDevicesTransactionIdCallsCount: Int {
get {
if Thread.isMainThread {
return ignoreDeviceTrustAndResendDevicesTransactionIdUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = ignoreDeviceTrustAndResendDevicesTransactionIdUnderlyingCallsCount
}

return returnValue!
}
}
set {
if Thread.isMainThread {
ignoreDeviceTrustAndResendDevicesTransactionIdUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
ignoreDeviceTrustAndResendDevicesTransactionIdUnderlyingCallsCount = newValue
}
}
}
}
open var ignoreDeviceTrustAndResendDevicesTransactionIdCalled: Bool {
return ignoreDeviceTrustAndResendDevicesTransactionIdCallsCount > 0
}
open var ignoreDeviceTrustAndResendDevicesTransactionIdReceivedArguments: (devices: [String: [String]], transactionId: String)?
open var ignoreDeviceTrustAndResendDevicesTransactionIdReceivedInvocations: [(devices: [String: [String]], transactionId: String)] = []
open var ignoreDeviceTrustAndResendDevicesTransactionIdClosure: (([String: [String]], String) async throws -> Void)?

open override func ignoreDeviceTrustAndResend(devices: [String: [String]], transactionId: String) async throws {

Check failure on line 11701 in ElementX/Sources/Mocks/Generated/SDKGeneratedMocks.swift

View workflow job for this annotation

GitHub Actions / Tests

method does not override any method from its superclass
if let error = ignoreDeviceTrustAndResendDevicesTransactionIdThrowableError {
throw error
}
ignoreDeviceTrustAndResendDevicesTransactionIdCallsCount += 1
ignoreDeviceTrustAndResendDevicesTransactionIdReceivedArguments = (devices: devices, transactionId: transactionId)
DispatchQueue.main.async {
self.ignoreDeviceTrustAndResendDevicesTransactionIdReceivedInvocations.append((devices: devices, transactionId: transactionId))
}
try await ignoreDeviceTrustAndResendDevicesTransactionIdClosure?(devices, transactionId)
}

//MARK: - ignoreUser

open var ignoreUserUserIdThrowableError: Error?
Expand Down Expand Up @@ -14421,52 +14467,6 @@ open class RoomSDKMock: MatrixRustSDK.Room {
}
}

//MARK: - trustDevicesAndResend

open var trustDevicesAndResendDevicesTransactionIdThrowableError: Error?
var trustDevicesAndResendDevicesTransactionIdUnderlyingCallsCount = 0
open var trustDevicesAndResendDevicesTransactionIdCallsCount: Int {
get {
if Thread.isMainThread {
return trustDevicesAndResendDevicesTransactionIdUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = trustDevicesAndResendDevicesTransactionIdUnderlyingCallsCount
}

return returnValue!
}
}
set {
if Thread.isMainThread {
trustDevicesAndResendDevicesTransactionIdUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
trustDevicesAndResendDevicesTransactionIdUnderlyingCallsCount = newValue
}
}
}
}
open var trustDevicesAndResendDevicesTransactionIdCalled: Bool {
return trustDevicesAndResendDevicesTransactionIdCallsCount > 0
}
open var trustDevicesAndResendDevicesTransactionIdReceivedArguments: (devices: [String: [String]], transactionId: String)?
open var trustDevicesAndResendDevicesTransactionIdReceivedInvocations: [(devices: [String: [String]], transactionId: String)] = []
open var trustDevicesAndResendDevicesTransactionIdClosure: (([String: [String]], String) async throws -> Void)?

open override func trustDevicesAndResend(devices: [String: [String]], transactionId: String) async throws {
if let error = trustDevicesAndResendDevicesTransactionIdThrowableError {
throw error
}
trustDevicesAndResendDevicesTransactionIdCallsCount += 1
trustDevicesAndResendDevicesTransactionIdReceivedArguments = (devices: devices, transactionId: transactionId)
DispatchQueue.main.async {
self.trustDevicesAndResendDevicesTransactionIdReceivedInvocations.append((devices: devices, transactionId: transactionId))
}
try await trustDevicesAndResendDevicesTransactionIdClosure?(devices, transactionId)
}

//MARK: - typingNotice

open var typingNoticeIsTypingThrowableError: Error?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ final class PinnedEventsTimelineScreenCoordinator: CoordinatorProtocol {
case .viewInRoomTimeline(let eventID):
actionsSubject.send(.displayRoomScreenWithFocussedPin(eventID: eventID))
// These other actions will not be handled in this view
case .displayEmojiPicker, .displayReportContent, .displayCameraPicker, .displayMediaPicker, .displayDocumentPicker, .displayLocationPicker, .displayPollForm, .displayMediaUploadPreviewScreen, .composer, .hasScrolled:
case .displayEmojiPicker, .displayReportContent, .displayCameraPicker, .displayMediaPicker,
.displayDocumentPicker, .displayLocationPicker, .displayPollForm, .displayMediaUploadPreviewScreen,
.displayResolveSendFailure, .composer, .hasScrolled:
// These actions are not handled in this coordinator
break
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// 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 Combine
import SwiftUI

struct ResolveVerifiedUserSendFailureScreenCoordinatorParameters {
let failure: TimelineItemSendFailure.VerifiedUser
let itemID: TimelineItemIdentifier
let roomProxy: JoinedRoomProxyProtocol
}

enum ResolveVerifiedUserSendFailureScreenCoordinatorAction {
case dismiss
}

final class ResolveVerifiedUserSendFailureScreenCoordinator: CoordinatorProtocol {
private let parameters: ResolveVerifiedUserSendFailureScreenCoordinatorParameters
private let viewModel: ResolveVerifiedUserSendFailureScreenViewModelProtocol

private var cancellables = Set<AnyCancellable>()

private let actionsSubject: PassthroughSubject<ResolveVerifiedUserSendFailureScreenCoordinatorAction, Never> = .init()
var actionsPublisher: AnyPublisher<ResolveVerifiedUserSendFailureScreenCoordinatorAction, Never> {
actionsSubject.eraseToAnyPublisher()
}

init(parameters: ResolveVerifiedUserSendFailureScreenCoordinatorParameters) {
self.parameters = parameters

viewModel = ResolveVerifiedUserSendFailureScreenViewModel(failure: parameters.failure,
itemID: parameters.itemID,
roomProxy: parameters.roomProxy)
}

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:
actionsSubject.send(.dismiss)
}
}
.store(in: &cancellables)
}

func toPresentable() -> AnyView {
AnyView(ResolveVerifiedUserSendFailureScreen(context: viewModel.context))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// 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

enum ResolveVerifiedUserSendFailureScreenViewModelAction {
case dismiss
}

struct ResolveVerifiedUserSendFailureScreenViewState: BindableState {
var currentFailure: TimelineItemSendFailure.VerifiedUser
var currentMemberDisplayName: String

var title: String {
switch currentFailure {
case .hasUnsignedDevice: UntranslatedL10n.screenRoomSendFailureUnsignedDeviceResolveTitle(currentMemberDisplayName)
case .changedIdentity: UntranslatedL10n.screenRoomSendFailureIdentityChangedResolveTitle(currentMemberDisplayName)
}
}

var subtitle: String {
switch currentFailure {
case .hasUnsignedDevice: UntranslatedL10n.screenRoomSendFailureUnsignedDeviceResolveSubtitle(currentMemberDisplayName,
currentMemberDisplayName)
case .changedIdentity: UntranslatedL10n.screenRoomSendFailureIdentityChangedResolveSubtitle(currentMemberDisplayName)
}
}

var primaryButtonTitle: String {
switch currentFailure {
case .hasUnsignedDevice: UntranslatedL10n.screenRoomSendFailureUnsignedDeviceResolvePrimaryButtonTitle
case .changedIdentity: UntranslatedL10n.screenRoomSendFailureIdentityChangedResolvePrimaryButtonTitle
}
}
}

enum ResolveVerifiedUserSendFailureScreenViewAction {
case resolveAndResend
case resend
case cancel
}
Loading

0 comments on commit b6d0d1a

Please sign in to comment.