Disable the threaded timeline composer when the room is read only.

This commit is contained in:
Stefan Ceriu
2025-06-03 17:52:55 +03:00
committed by Stefan Ceriu
parent 9804be70eb
commit c3a9e5deaa
4 changed files with 39 additions and 13 deletions
@@ -11,13 +11,32 @@ import SwiftUI
typealias ThreadTimelineScreenViewModelType = StateStoreViewModel<ThreadTimelineScreenViewState, ThreadTimelineScreenViewAction>
class ThreadTimelineScreenViewModel: ThreadTimelineScreenViewModelType, ThreadTimelineScreenViewModelProtocol {
private let roomProxy: JoinedRoomProxyProtocol
private let actionsSubject: PassthroughSubject<ThreadTimelineScreenViewModelAction, Never> = .init()
var actionsPublisher: AnyPublisher<ThreadTimelineScreenViewModelAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
init() {
init(roomProxy: JoinedRoomProxyProtocol) {
self.roomProxy = roomProxy
super.init(initialViewState: ThreadTimelineScreenViewState())
Task { [weak self] in
for await roomInfo in roomProxy.infoPublisher.receive(on: DispatchQueue.main).values {
guard !Task.isCancelled else {
return
}
await self?.handleRoomInfoUpdate(roomInfo)
}
}
.store(in: &cancellables)
Task {
await handleRoomInfoUpdate(roomProxy.infoPublisher.value)
}
}
// MARK: - Public
@@ -42,4 +61,10 @@ class ThreadTimelineScreenViewModel: ThreadTimelineScreenViewModelType, ThreadTi
state.bindings.mediaPreviewViewModel = mediaPreviewViewModel
}
// MARK: - Private
private func handleRoomInfoUpdate(_ roomInfo: RoomInfoProxy) async {
state.canSendMessage = await (try? roomProxy.canUser(userID: roomProxy.ownUserID, sendMessage: .roomMessage).get()) == true
}
}