mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 00:49:44 +00:00
Switch callbacks to combine (#1710)
* #750 - Convert the SoftLogoutScreen to combine * #750 - Convert the UserSessionFlowCoordinator to Combine * #750 - Convert the AnalyticsPromptScreen to Combine * #750 - Convert the LoginScreen to Combine * #750 - Convert the ServerSelectionScreen to Combine * #750 - Convert the EmojiPickerScreen to Combine * #750 - Convert the HomeScreen to Combine * #750 - Convert the MediaUploadPreviewScreen to Combine * #750 - Convert the OnboardingScreen to Combine * Rename `Onboarding` to `OnboardingScreen` * #750 - Convert the ReportContentScreen to Combine * #750 - Convert the RoomDetailsSscreen to Combine * #750 - Convert the RoomMemberDetailsScreen to Combine * #750 - Convert the RoomMembersListScreen to Combine * #750 - Convert the SessionVerificationScreen to Combine * #750 - Convert the SettingsScreen to Combine * #750 - Convert the AdvancedSettingsScreen to Combine * #750 - Convert the DeveloperOptionsScreen to Combine * Fix the unit tests * Use .sink action and the same cancellables constructor everywhere * Cleanup cancellables when setting up tests
This commit is contained in:
@@ -41,7 +41,7 @@ final class RoomDetailsScreenCoordinator: CoordinatorProtocol {
|
||||
}
|
||||
|
||||
private let actionsSubject: PassthroughSubject<RoomDetailsScreenCoordinatorAction, Never> = .init()
|
||||
private var cancellables: Set<AnyCancellable> = .init()
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
var actions: AnyPublisher<RoomDetailsScreenCoordinatorAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
@@ -60,22 +60,24 @@ final class RoomDetailsScreenCoordinator: CoordinatorProtocol {
|
||||
// MARK: - Public
|
||||
|
||||
func start() {
|
||||
viewModel.callback = { [weak self] action in
|
||||
guard let self else { return }
|
||||
|
||||
switch action {
|
||||
case .requestMemberDetailsPresentation:
|
||||
self.presentRoomMembersList()
|
||||
case .requestInvitePeoplePresentation:
|
||||
self.presentInviteUsersScreen()
|
||||
case .leftRoom:
|
||||
self.actionsSubject.send(.leftRoom)
|
||||
case .requestEditDetailsPresentation(let accountOwner):
|
||||
self.presentRoomDetailsEditScreen(accountOwner: accountOwner)
|
||||
case .requestNotificationSettingsPresentation:
|
||||
self.presentNotificationSettings()
|
||||
viewModel.actions
|
||||
.sink { [weak self] action in
|
||||
guard let self else { return }
|
||||
|
||||
switch action {
|
||||
case .requestMemberDetailsPresentation:
|
||||
presentRoomMembersList()
|
||||
case .requestInvitePeoplePresentation:
|
||||
presentInviteUsersScreen()
|
||||
case .leftRoom:
|
||||
actionsSubject.send(.leftRoom)
|
||||
case .requestEditDetailsPresentation(let accountOwner):
|
||||
presentRoomDetailsEditScreen(accountOwner: accountOwner)
|
||||
case .requestNotificationSettingsPresentation:
|
||||
presentNotificationSettings()
|
||||
}
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
func stop() {
|
||||
@@ -94,12 +96,16 @@ final class RoomDetailsScreenCoordinator: CoordinatorProtocol {
|
||||
roomProxy: parameters.roomProxy)
|
||||
let coordinator = RoomMembersListScreenCoordinator(parameters: params)
|
||||
|
||||
coordinator.callback = { [weak self] action in
|
||||
switch action {
|
||||
case .invite:
|
||||
self?.presentInviteUsersScreen()
|
||||
coordinator.actions
|
||||
.sink { [weak self] action in
|
||||
guard let self else { return }
|
||||
|
||||
switch action {
|
||||
case .invite:
|
||||
presentInviteUsersScreen()
|
||||
}
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
navigationStackCoordinator?.push(coordinator)
|
||||
}
|
||||
@@ -115,10 +121,10 @@ final class RoomDetailsScreenCoordinator: CoordinatorProtocol {
|
||||
let coordinator = InviteUsersScreenCoordinator(parameters: inviteParameters)
|
||||
inviteUsersStackCoordinator.setRootCoordinator(coordinator)
|
||||
|
||||
coordinator.actions.sink { [weak self] result in
|
||||
coordinator.actions.sink { [weak self] action in
|
||||
guard let self else { return }
|
||||
|
||||
switch result {
|
||||
switch action {
|
||||
case .cancel:
|
||||
navigationStackCoordinator?.setSheetCoordinator(nil)
|
||||
case .proceed:
|
||||
|
||||
@@ -32,7 +32,11 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
||||
|
||||
private var dmRecipient: RoomMemberProxyProtocol?
|
||||
|
||||
var callback: ((RoomDetailsScreenViewModelAction) -> Void)?
|
||||
private var actionsSubject: PassthroughSubject<RoomDetailsScreenViewModelAction, Never> = .init()
|
||||
|
||||
var actions: AnyPublisher<RoomDetailsScreenViewModelAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init(accountUserID: String,
|
||||
roomProxy: RoomProxyProtocol,
|
||||
@@ -75,9 +79,9 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
||||
override func process(viewAction: RoomDetailsScreenViewAction) {
|
||||
switch viewAction {
|
||||
case .processTapPeople:
|
||||
callback?(.requestMemberDetailsPresentation)
|
||||
actionsSubject.send(.requestMemberDetailsPresentation)
|
||||
case .processTapInvite:
|
||||
callback?(.requestInvitePeoplePresentation)
|
||||
actionsSubject.send(.requestInvitePeoplePresentation)
|
||||
case .processTapLeave:
|
||||
guard state.joinedMembersCount > 1 else {
|
||||
state.bindings.leaveRoomAlertItem = LeaveRoomAlertItem(roomId: roomProxy.id, state: .empty)
|
||||
@@ -95,7 +99,7 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
||||
MXLog.error("Missing account owner when presenting the room's edit details screen")
|
||||
return
|
||||
}
|
||||
callback?(.requestEditDetailsPresentation(accountOwner))
|
||||
actionsSubject.send(.requestEditDetailsPresentation(accountOwner))
|
||||
case .ignoreConfirmed:
|
||||
Task { await ignore() }
|
||||
case .unignoreConfirmed:
|
||||
@@ -104,7 +108,7 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
||||
if state.notificationSettingsState.isError {
|
||||
fetchNotificationSettings()
|
||||
} else {
|
||||
callback?(.requestNotificationSettingsPresentation)
|
||||
actionsSubject.send(.requestNotificationSettingsPresentation)
|
||||
}
|
||||
case .processToogleMuteNotifications:
|
||||
Task { await toggleMuteNotifications() }
|
||||
@@ -239,7 +243,7 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
||||
case .failure:
|
||||
state.bindings.alertInfo = AlertInfo(id: .unknown)
|
||||
case .success:
|
||||
callback?(.leftRoom)
|
||||
actionsSubject.send(.leftRoom)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
|
||||
@MainActor
|
||||
protocol RoomDetailsScreenViewModelProtocol {
|
||||
var callback: ((RoomDetailsScreenViewModelAction) -> Void)? { get set }
|
||||
var actions: AnyPublisher<RoomDetailsScreenViewModelAction, Never> { get }
|
||||
var context: RoomDetailsScreenViewModelType.Context { get }
|
||||
func stop()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user