mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
f8920d4d11
* Update Compound and use super button for room directory.
73 lines
2.4 KiB
Swift
73 lines
2.4 KiB
Swift
//
|
|
// 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 JoinRoomScreenCoordinatorParameters {
|
|
let roomID: String
|
|
let roomName: String
|
|
let avatarURL: URL?
|
|
let interaction: JoinRoomScreenInteraction
|
|
let clientProxy: ClientProxyProtocol
|
|
}
|
|
|
|
enum JoinRoomScreenCoordinatorAction {
|
|
case joined
|
|
case cancelled
|
|
}
|
|
|
|
final class JoinRoomScreenCoordinator: CoordinatorProtocol {
|
|
private let parameters: JoinRoomScreenCoordinatorParameters
|
|
private let viewModel: JoinRoomScreenViewModelProtocol
|
|
|
|
private var cancellables = Set<AnyCancellable>()
|
|
|
|
private let actionsSubject: PassthroughSubject<JoinRoomScreenCoordinatorAction, Never> = .init()
|
|
var actionsPublisher: AnyPublisher<JoinRoomScreenCoordinatorAction, Never> {
|
|
actionsSubject.eraseToAnyPublisher()
|
|
}
|
|
|
|
init(parameters: JoinRoomScreenCoordinatorParameters) {
|
|
self.parameters = parameters
|
|
|
|
viewModel = JoinRoomScreenViewModel(roomID: parameters.roomID,
|
|
roomName: parameters.roomName,
|
|
avatarURL: parameters.avatarURL,
|
|
interaction: parameters.interaction,
|
|
clientProxy: parameters.clientProxy)
|
|
}
|
|
|
|
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 .joined:
|
|
actionsSubject.send(.joined)
|
|
case .cancelled:
|
|
actionsSubject.send(.cancelled)
|
|
}
|
|
}
|
|
.store(in: &cancellables)
|
|
}
|
|
|
|
func toPresentable() -> AnyView {
|
|
AnyView(JoinRoomScreen(context: viewModel.context))
|
|
}
|
|
}
|