Add a RoomScreenHook.

This commit is contained in:
Doug
2025-06-06 14:53:29 +01:00
committed by Stefan Ceriu
parent 3f61eb8c5e
commit e3884f903c
13 changed files with 86 additions and 10 deletions
@@ -25,6 +25,7 @@ struct RoomScreenCoordinatorParameters {
let ongoingCallRoomIDPublisher: CurrentValuePublisher<String?, Never>
let appMediator: AppMediatorProtocol
let appSettings: AppSettings
let appHooks: AppHooks
let composerDraftService: ComposerDraftServiceProtocol
let timelineControllerFactory: TimelineControllerFactoryProtocol
}
@@ -73,6 +74,7 @@ final class RoomScreenCoordinator: CoordinatorProtocol {
ongoingCallRoomIDPublisher: parameters.ongoingCallRoomIDPublisher,
appMediator: parameters.appMediator,
appSettings: parameters.appSettings,
appHooks: parameters.appHooks,
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController)
@@ -43,9 +43,18 @@ struct RoomScreenViewState: BindableState {
}
var canSendMessage = true
/// Whether or not starting a call is supported.
var isCallingEnabled = true
/// Whether or not the user is allowed to join calls in this room.
var canJoinCall = false
/// Whether or not this room currently has a call in progress.
var hasOngoingCall: Bool
var shouldShowCallButton = true
/// Whether or not the user is already part of a call in another room.
var isParticipatingInOngoingCall = false
var shouldShowCallButton: Bool {
isCallingEnabled && !isParticipatingInOngoingCall // Hide the join call button when already in the call
}
var isKnockingEnabled = false
var isKnockableRoom = false
@@ -70,7 +79,7 @@ struct RoomScreenViewState: BindableState {
var footerDetails: RoomScreenFooterViewDetails?
var bindings: RoomScreenViewStateBindings
var bindings = RoomScreenViewStateBindings()
}
struct RoomScreenViewStateBindings {
@@ -57,6 +57,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
ongoingCallRoomIDPublisher: CurrentValuePublisher<String?, Never>,
appMediator: AppMediatorProtocol,
appSettings: AppSettings,
appHooks: AppHooks,
analyticsService: AnalyticsService,
userIndicatorController: UserIndicatorControllerProtocol) {
self.clientProxy = clientProxy
@@ -69,16 +70,15 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
self.initialSelectedPinnedEventID = initialSelectedPinnedEventID
pinnedEventStringBuilder = .pinnedEventStringBuilder(userID: roomProxy.ownUserID)
super.init(initialViewState: .init(roomTitle: roomProxy.infoPublisher.value.displayName ?? roomProxy.id,
roomAvatar: roomProxy.infoPublisher.value.avatar,
hasOngoingCall: roomProxy.infoPublisher.value.hasRoomCall,
hasSuccessor: roomProxy.infoPublisher.value.successor != nil,
bindings: .init()),
let viewState = RoomScreenViewState(roomTitle: roomProxy.infoPublisher.value.displayName ?? roomProxy.id,
roomAvatar: roomProxy.infoPublisher.value.avatar,
hasOngoingCall: roomProxy.infoPublisher.value.hasRoomCall,
hasSuccessor: roomProxy.infoPublisher.value.successor != nil)
super.init(initialViewState: appHooks.roomScreenHook.update(viewState),
mediaProvider: mediaProvider)
Task {
await handleRoomInfoUpdate(roomProxy.infoPublisher.value)
await updateVerificationBadge()
}
@@ -205,7 +205,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
.receive(on: DispatchQueue.main)
.sink { [weak self] ongoingCallRoomID in
guard let self else { return }
state.shouldShowCallButton = ongoingCallRoomID != roomProxy.id
state.isParticipatingInOngoingCall = ongoingCallRoomID == roomProxy.id
}
.store(in: &cancellables)
@@ -430,6 +430,7 @@ extension RoomScreenViewModel {
ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
appHooks: AppHooks(),
analyticsService: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController)
}