mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 10:33:45 +00:00
Disable the threaded timeline composer when the room is read only.
This commit is contained in:
committed by
Stefan Ceriu
parent
9804be70eb
commit
c3a9e5deaa
@@ -55,7 +55,7 @@ final class ThreadTimelineScreenCoordinator: CoordinatorProtocol {
|
|||||||
init(parameters: ThreadTimelineScreenCoordinatorParameters) {
|
init(parameters: ThreadTimelineScreenCoordinatorParameters) {
|
||||||
self.parameters = parameters
|
self.parameters = parameters
|
||||||
|
|
||||||
viewModel = ThreadTimelineScreenViewModel()
|
viewModel = ThreadTimelineScreenViewModel(roomProxy: parameters.roomProxy)
|
||||||
|
|
||||||
timelineViewModel = TimelineViewModel(roomProxy: parameters.roomProxy,
|
timelineViewModel = TimelineViewModel(roomProxy: parameters.roomProxy,
|
||||||
timelineController: parameters.timelineController,
|
timelineController: parameters.timelineController,
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import Foundation
|
|||||||
enum ThreadTimelineScreenViewModelAction { }
|
enum ThreadTimelineScreenViewModelAction { }
|
||||||
|
|
||||||
struct ThreadTimelineScreenViewState: BindableState {
|
struct ThreadTimelineScreenViewState: BindableState {
|
||||||
|
var canSendMessage = true
|
||||||
|
|
||||||
var bindings = ThreadTimelineScreenViewStateBindings()
|
var bindings = ThreadTimelineScreenViewStateBindings()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,13 +11,32 @@ import SwiftUI
|
|||||||
typealias ThreadTimelineScreenViewModelType = StateStoreViewModel<ThreadTimelineScreenViewState, ThreadTimelineScreenViewAction>
|
typealias ThreadTimelineScreenViewModelType = StateStoreViewModel<ThreadTimelineScreenViewState, ThreadTimelineScreenViewAction>
|
||||||
|
|
||||||
class ThreadTimelineScreenViewModel: ThreadTimelineScreenViewModelType, ThreadTimelineScreenViewModelProtocol {
|
class ThreadTimelineScreenViewModel: ThreadTimelineScreenViewModelType, ThreadTimelineScreenViewModelProtocol {
|
||||||
|
private let roomProxy: JoinedRoomProxyProtocol
|
||||||
|
|
||||||
private let actionsSubject: PassthroughSubject<ThreadTimelineScreenViewModelAction, Never> = .init()
|
private let actionsSubject: PassthroughSubject<ThreadTimelineScreenViewModelAction, Never> = .init()
|
||||||
var actionsPublisher: AnyPublisher<ThreadTimelineScreenViewModelAction, Never> {
|
var actionsPublisher: AnyPublisher<ThreadTimelineScreenViewModelAction, Never> {
|
||||||
actionsSubject.eraseToAnyPublisher()
|
actionsSubject.eraseToAnyPublisher()
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init(roomProxy: JoinedRoomProxyProtocol) {
|
||||||
|
self.roomProxy = roomProxy
|
||||||
|
|
||||||
super.init(initialViewState: ThreadTimelineScreenViewState())
|
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
|
// MARK: - Public
|
||||||
@@ -42,4 +61,10 @@ class ThreadTimelineScreenViewModel: ThreadTimelineScreenViewModelType, ThreadTi
|
|||||||
|
|
||||||
state.bindings.mediaPreviewViewModel = mediaPreviewViewModel
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,16 +64,15 @@ struct ThreadTimelineScreen: View {
|
|||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
private var composer: some View {
|
private var composer: some View {
|
||||||
#warning("Check permissions here too")
|
if context.viewState.canSendMessage {
|
||||||
// if roomContext.viewState.canSendMessage {
|
|
||||||
composerToolbar
|
composerToolbar
|
||||||
// } else {
|
} else {
|
||||||
// Text(L10n.screenRoomTimelineNoPermissionToPost)
|
Text(L10n.screenRoomTimelineNoPermissionToPost)
|
||||||
// .font(.compound.bodyLG)
|
.font(.compound.bodyLG)
|
||||||
// .foregroundStyle(.compound.textDisabled)
|
.foregroundStyle(.compound.textDisabled)
|
||||||
// .multilineTextAlignment(.center)
|
.multilineTextAlignment(.center)
|
||||||
// .padding(.vertical, 10) // Matches the MessageComposerStyleModifier
|
.padding(.vertical, 10) // Matches the MessageComposerStyleModifier
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var scrollToBottomButton: some View {
|
private var scrollToBottomButton: some View {
|
||||||
|
|||||||
Reference in New Issue
Block a user