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 ce277bfd7e
commit 3923d65b41
4 changed files with 39 additions and 13 deletions

View File

@@ -55,7 +55,7 @@ final class ThreadTimelineScreenCoordinator: CoordinatorProtocol {
init(parameters: ThreadTimelineScreenCoordinatorParameters) {
self.parameters = parameters
viewModel = ThreadTimelineScreenViewModel()
viewModel = ThreadTimelineScreenViewModel(roomProxy: parameters.roomProxy)
timelineViewModel = TimelineViewModel(roomProxy: parameters.roomProxy,
timelineController: parameters.timelineController,

View File

@@ -10,6 +10,8 @@ import Foundation
enum ThreadTimelineScreenViewModelAction { }
struct ThreadTimelineScreenViewState: BindableState {
var canSendMessage = true
var bindings = ThreadTimelineScreenViewStateBindings()
}

View File

@@ -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
}
}

View File

@@ -64,16 +64,15 @@ struct ThreadTimelineScreen: View {
@ViewBuilder
private var composer: some View {
#warning("Check permissions here too")
// if roomContext.viewState.canSendMessage {
composerToolbar
// } else {
// Text(L10n.screenRoomTimelineNoPermissionToPost)
// .font(.compound.bodyLG)
// .foregroundStyle(.compound.textDisabled)
// .multilineTextAlignment(.center)
// .padding(.vertical, 10) // Matches the MessageComposerStyleModifier
// }
if context.viewState.canSendMessage {
composerToolbar
} else {
Text(L10n.screenRoomTimelineNoPermissionToPost)
.font(.compound.bodyLG)
.foregroundStyle(.compound.textDisabled)
.multilineTextAlignment(.center)
.padding(.vertical, 10) // Matches the MessageComposerStyleModifier
}
}
private var scrollToBottomButton: some View {