mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-06 04:18:31 +00:00
Hook up the actions in the media details sheet. (#3607)
This commit is contained in:
@@ -9,6 +9,7 @@ import Combine
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
enum MediaEventsTimelineFlowCoordinatorAction {
|
enum MediaEventsTimelineFlowCoordinatorAction {
|
||||||
|
case viewInRoomTimeline(TimelineItemIdentifier)
|
||||||
case finished
|
case finished
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,6 +92,15 @@ class MediaEventsTimelineFlowCoordinator: FlowCoordinatorProtocol {
|
|||||||
|
|
||||||
let coordinator = MediaEventsTimelineScreenCoordinator(parameters: parameters)
|
let coordinator = MediaEventsTimelineScreenCoordinator(parameters: parameters)
|
||||||
|
|
||||||
|
coordinator.actions
|
||||||
|
.sink { [weak self] action in
|
||||||
|
switch action {
|
||||||
|
case .viewInRoomTimeline(let itemID):
|
||||||
|
self?.actionsSubject.send(.viewInRoomTimeline(itemID))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.store(in: &cancellables)
|
||||||
|
|
||||||
navigationStackCoordinator.push(coordinator) { [weak self] in
|
navigationStackCoordinator.push(coordinator) { [weak self] in
|
||||||
self?.actionsSubject.send(.finished)
|
self?.actionsSubject.send(.finished)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1546,6 +1546,13 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
|
|||||||
guard let self else { return }
|
guard let self else { return }
|
||||||
|
|
||||||
switch action {
|
switch action {
|
||||||
|
case .viewInRoomTimeline(let itemID):
|
||||||
|
guard let eventID = itemID.eventID else {
|
||||||
|
MXLog.error("Unable to present room timeline for event \(itemID)")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
stateMachine.tryEvent(.dismissMediaEventsTimeline)
|
||||||
|
stateMachine.tryEvent(.presentRoom(presentationAction: .eventFocus(.init(eventID: eventID, shouldSetPin: false))))
|
||||||
case .finished:
|
case .finished:
|
||||||
stateMachine.tryEvent(.dismissMediaEventsTimeline)
|
stateMachine.tryEvent(.dismissMediaEventsTimeline)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,9 +55,9 @@ class TimelineMediaPreviewController: QLPreviewController, QLPreviewControllerDa
|
|||||||
switch action {
|
switch action {
|
||||||
case .loadedMediaFile:
|
case .loadedMediaFile:
|
||||||
self?.refreshCurrentPreviewItem()
|
self?.refreshCurrentPreviewItem()
|
||||||
case .viewInTimeline:
|
case .viewInRoomTimeline, .dismiss:
|
||||||
self?.dismiss(animated: true) // Dismiss the details sheet.
|
self?.dismiss(animated: true) // Dismiss the details sheet.
|
||||||
// Errrr, hmmmmm, do something else here.
|
// And let the view model handle the rest.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
|
|||||||
@@ -7,9 +7,10 @@
|
|||||||
|
|
||||||
import QuickLook
|
import QuickLook
|
||||||
|
|
||||||
enum TimelineMediaPreviewViewModelAction {
|
enum TimelineMediaPreviewViewModelAction: Equatable {
|
||||||
case loadedMediaFile
|
case loadedMediaFile
|
||||||
case viewInTimeline
|
case viewInRoomTimeline(TimelineItemIdentifier)
|
||||||
|
case dismiss
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TimelineMediaPreviewViewState: BindableState {
|
struct TimelineMediaPreviewViewState: BindableState {
|
||||||
|
|||||||
@@ -51,14 +51,16 @@ class TimelineMediaPreviewViewModel: TimelineMediaPreviewViewModelType {
|
|||||||
case .menuAction(let action):
|
case .menuAction(let action):
|
||||||
switch action {
|
switch action {
|
||||||
case .viewInRoomTimeline:
|
case .viewInRoomTimeline:
|
||||||
actionsSubject.send(.viewInTimeline)
|
actionsSubject.send(.viewInRoomTimeline(state.currentItem.id))
|
||||||
case .redact:
|
case .redact:
|
||||||
state.bindings.isPresentingRedactConfirmation = true
|
state.bindings.isPresentingRedactConfirmation = true
|
||||||
default:
|
default:
|
||||||
MXLog.error("Received unexpected action: \(action)")
|
MXLog.error("Received unexpected action: \(action)")
|
||||||
}
|
}
|
||||||
case .redactConfirmation:
|
case .redactConfirmation:
|
||||||
break // Do it here??
|
timelineViewModel.context.send(viewAction: .handleTimelineItemMenuAction(itemID: state.currentItem.id, action: .redact))
|
||||||
|
state.bindings.isPresentingRedactConfirmation = false
|
||||||
|
actionsSubject.send(.dismiss) // Will dismiss the details sheet and the QuickLook view.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-1
@@ -20,7 +20,9 @@ struct MediaEventsTimelineScreenCoordinatorParameters {
|
|||||||
let userIndicatorController: UserIndicatorControllerProtocol
|
let userIndicatorController: UserIndicatorControllerProtocol
|
||||||
}
|
}
|
||||||
|
|
||||||
enum MediaEventsTimelineScreenCoordinatorAction { }
|
enum MediaEventsTimelineScreenCoordinatorAction {
|
||||||
|
case viewInRoomTimeline(TimelineItemIdentifier)
|
||||||
|
}
|
||||||
|
|
||||||
final class MediaEventsTimelineScreenCoordinator: CoordinatorProtocol {
|
final class MediaEventsTimelineScreenCoordinator: CoordinatorProtocol {
|
||||||
private let parameters: MediaEventsTimelineScreenCoordinatorParameters
|
private let parameters: MediaEventsTimelineScreenCoordinatorParameters
|
||||||
@@ -62,6 +64,15 @@ final class MediaEventsTimelineScreenCoordinator: CoordinatorProtocol {
|
|||||||
filesTimelineViewModel: filesTimelineViewModel,
|
filesTimelineViewModel: filesTimelineViewModel,
|
||||||
mediaProvider: parameters.mediaProvider,
|
mediaProvider: parameters.mediaProvider,
|
||||||
userIndicatorController: parameters.userIndicatorController)
|
userIndicatorController: parameters.userIndicatorController)
|
||||||
|
|
||||||
|
viewModel.actionsPublisher
|
||||||
|
.sink { [weak self] action in
|
||||||
|
switch action {
|
||||||
|
case .viewInRoomTimeline(let itemID):
|
||||||
|
self?.actionsSubject.send(.viewInRoomTimeline(itemID))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.store(in: &cancellables)
|
||||||
}
|
}
|
||||||
|
|
||||||
func toPresentable() -> AnyView {
|
func toPresentable() -> AnyView {
|
||||||
|
|||||||
+3
-1
@@ -7,7 +7,9 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
enum MediaEventsTimelineScreenViewModelAction { }
|
enum MediaEventsTimelineScreenViewModelAction {
|
||||||
|
case viewInRoomTimeline(TimelineItemIdentifier)
|
||||||
|
}
|
||||||
|
|
||||||
enum MediaEventsTimelineScreenMode {
|
enum MediaEventsTimelineScreenMode {
|
||||||
case media
|
case media
|
||||||
|
|||||||
+17
@@ -26,6 +26,8 @@ class MediaEventsTimelineScreenViewModel: MediaEventsTimelineScreenViewModelType
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var mediaPreviewCancellable: AnyCancellable?
|
||||||
|
|
||||||
private let actionsSubject: PassthroughSubject<MediaEventsTimelineScreenViewModelAction, Never> = .init()
|
private let actionsSubject: PassthroughSubject<MediaEventsTimelineScreenViewModelAction, Never> = .init()
|
||||||
var actionsPublisher: AnyPublisher<MediaEventsTimelineScreenViewModelAction, Never> {
|
var actionsPublisher: AnyPublisher<MediaEventsTimelineScreenViewModelAction, Never> {
|
||||||
actionsSubject.eraseToAnyPublisher()
|
actionsSubject.eraseToAnyPublisher()
|
||||||
@@ -154,6 +156,21 @@ class MediaEventsTimelineScreenViewModel: MediaEventsTimelineScreenViewModelType
|
|||||||
timelineViewModel: activeTimelineViewModel,
|
timelineViewModel: activeTimelineViewModel,
|
||||||
mediaProvider: mediaProvider,
|
mediaProvider: mediaProvider,
|
||||||
userIndicatorController: userIndicatorController)
|
userIndicatorController: userIndicatorController)
|
||||||
|
|
||||||
|
mediaPreviewCancellable = viewModel.actions
|
||||||
|
.sink { [weak self] action in
|
||||||
|
guard let self else { return }
|
||||||
|
switch action {
|
||||||
|
case .viewInRoomTimeline(let itemID):
|
||||||
|
state.bindings.mediaPreviewViewModel = nil
|
||||||
|
actionsSubject.send(.viewInRoomTimeline(itemID))
|
||||||
|
case .dismiss:
|
||||||
|
state.bindings.mediaPreviewViewModel = nil
|
||||||
|
case .loadedMediaFile:
|
||||||
|
break // Handled by the preview controller
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
state.bindings.mediaPreviewViewModel = viewModel
|
state.bindings.mediaPreviewViewModel = viewModel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
@@ -121,6 +121,7 @@ struct MediaEventsTimelineScreen: View {
|
|||||||
ProgressView()
|
ProgressView()
|
||||||
.padding()
|
.padding()
|
||||||
.opacity(context.viewState.isBackPaginating ? 1 : 0)
|
.opacity(context.viewState.isBackPaginating ? 1 : 0)
|
||||||
|
.scaleEffect(.init(width: 1, height: -1)) // Make sure it spins the right way around 🙃
|
||||||
|
|
||||||
Rectangle()
|
Rectangle()
|
||||||
.frame(height: 1)
|
.frame(height: 1)
|
||||||
|
|||||||
@@ -870,10 +870,10 @@ private extension RoomInfoProxy {
|
|||||||
extension TimelineViewModel {
|
extension TimelineViewModel {
|
||||||
static let mock = mock(timelineKind: .live)
|
static let mock = mock(timelineKind: .live)
|
||||||
|
|
||||||
static func mock(timelineKind: TimelineKind = .live) -> TimelineViewModel {
|
static func mock(timelineKind: TimelineKind = .live, timelineController: MockRoomTimelineController? = nil) -> TimelineViewModel {
|
||||||
TimelineViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Preview room")),
|
TimelineViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Preview room")),
|
||||||
focussedEventID: nil,
|
focussedEventID: nil,
|
||||||
timelineController: MockRoomTimelineController(timelineKind: timelineKind),
|
timelineController: timelineController ?? MockRoomTimelineController(timelineKind: timelineKind),
|
||||||
mediaProvider: MediaProviderMock(configuration: .init()),
|
mediaProvider: MediaProviderMock(configuration: .init()),
|
||||||
mediaPlayerProvider: MediaPlayerProviderMock(),
|
mediaPlayerProvider: MediaPlayerProviderMock(),
|
||||||
voiceMessageMediaManager: VoiceMessageMediaManagerMock(),
|
voiceMessageMediaManager: VoiceMessageMediaManagerMock(),
|
||||||
|
|||||||
+4
-1
@@ -113,7 +113,10 @@ class MockRoomTimelineController: RoomTimelineControllerProtocol {
|
|||||||
|
|
||||||
func removeCaption(_ eventOrTransactionID: EventOrTransactionId) async { }
|
func removeCaption(_ eventOrTransactionID: EventOrTransactionId) async { }
|
||||||
|
|
||||||
func redact(_ eventOrTransactionID: EventOrTransactionId) async { }
|
private(set) var redactCalled = false
|
||||||
|
func redact(_ eventOrTransactionID: EventOrTransactionId) async {
|
||||||
|
redactCalled = true
|
||||||
|
}
|
||||||
|
|
||||||
func pin(eventID: String) async { }
|
func pin(eventID: String) async { }
|
||||||
|
|
||||||
|
|||||||
@@ -16,12 +16,14 @@ class TimelineMediaPreviewViewModelTests: XCTestCase {
|
|||||||
var viewModel: TimelineMediaPreviewViewModel!
|
var viewModel: TimelineMediaPreviewViewModel!
|
||||||
var context: TimelineMediaPreviewViewModel.Context { viewModel.context }
|
var context: TimelineMediaPreviewViewModel.Context { viewModel.context }
|
||||||
var mediaProvider: MediaProviderMock!
|
var mediaProvider: MediaProviderMock!
|
||||||
|
var timelineController: MockRoomTimelineController!
|
||||||
|
|
||||||
func testLoadingItem() async throws {
|
func testLoadingItem() async {
|
||||||
// Given a fresh view model.
|
// Given a fresh view model.
|
||||||
setupViewModel()
|
setupViewModel()
|
||||||
XCTAssertFalse(mediaProvider.loadFileFromSourceFilenameCalled)
|
XCTAssertFalse(mediaProvider.loadFileFromSourceFilenameCalled)
|
||||||
XCTAssertEqual(context.viewState.currentItem, context.viewState.previewItems[0])
|
XCTAssertEqual(context.viewState.currentItem, context.viewState.previewItems[0])
|
||||||
|
XCTAssertNotNil(context.viewState.currentItemActions)
|
||||||
|
|
||||||
// When the preview controller sets the current item.
|
// When the preview controller sets the current item.
|
||||||
await viewModel.updateCurrentItem(context.viewState.previewItems[0])
|
await viewModel.updateCurrentItem(context.viewState.previewItems[0])
|
||||||
@@ -29,6 +31,42 @@ class TimelineMediaPreviewViewModelTests: XCTestCase {
|
|||||||
// Then the view model should load the item and update its view state.
|
// Then the view model should load the item and update its view state.
|
||||||
XCTAssertTrue(mediaProvider.loadFileFromSourceFilenameCalled)
|
XCTAssertTrue(mediaProvider.loadFileFromSourceFilenameCalled)
|
||||||
XCTAssertEqual(context.viewState.currentItem, context.viewState.previewItems[0])
|
XCTAssertEqual(context.viewState.currentItem, context.viewState.previewItems[0])
|
||||||
|
XCTAssertNotNil(context.viewState.currentItemActions)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testViewInRoomTimeline() async throws {
|
||||||
|
// Given a view model with a loaded item.
|
||||||
|
await testLoadingItem()
|
||||||
|
|
||||||
|
// When choosing to view the current item in the timeline.
|
||||||
|
let currentItemID = context.viewState.currentItem.id
|
||||||
|
let deferred = deferFulfillment(viewModel.actions) { $0 == .viewInRoomTimeline(currentItemID) }
|
||||||
|
context.send(viewAction: .menuAction(.viewInRoomTimeline))
|
||||||
|
|
||||||
|
// Then the action should be sent upwards to make this happen.
|
||||||
|
try await deferred.fulfill()
|
||||||
|
}
|
||||||
|
|
||||||
|
func testRedactConfirmation() async throws {
|
||||||
|
// Given a view model with a loaded item.
|
||||||
|
await testLoadingItem()
|
||||||
|
XCTAssertFalse(context.isPresentingRedactConfirmation)
|
||||||
|
XCTAssertFalse(timelineController.redactCalled)
|
||||||
|
|
||||||
|
// When choosing to redact the current item.
|
||||||
|
context.send(viewAction: .menuAction(.redact))
|
||||||
|
|
||||||
|
// Then the confirmation sheet should be presented.
|
||||||
|
XCTAssertTrue(context.isPresentingRedactConfirmation)
|
||||||
|
XCTAssertFalse(timelineController.redactCalled)
|
||||||
|
|
||||||
|
// When confirming the redaction.
|
||||||
|
let deferred = deferFulfillment(viewModel.actions) { $0 == .dismiss }
|
||||||
|
context.send(viewAction: .redactConfirmation)
|
||||||
|
|
||||||
|
// Then the item should be redacted and the view should be dismissed.
|
||||||
|
try await deferred.fulfill()
|
||||||
|
XCTAssertTrue(timelineController.redactCalled)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Helpers
|
// MARK: - Helpers
|
||||||
@@ -46,9 +84,13 @@ class TimelineMediaPreviewViewModelTests: XCTestCase {
|
|||||||
imageInfo: .mockImage,
|
imageInfo: .mockImage,
|
||||||
thumbnailInfo: .mockThumbnail))
|
thumbnailInfo: .mockThumbnail))
|
||||||
|
|
||||||
|
timelineController = MockRoomTimelineController(timelineKind: .media(.mediaFilesScreen))
|
||||||
|
timelineController.timelineItems = [item]
|
||||||
|
|
||||||
mediaProvider = MediaProviderMock(configuration: .init())
|
mediaProvider = MediaProviderMock(configuration: .init())
|
||||||
viewModel = TimelineMediaPreviewViewModel(initialItem: item,
|
viewModel = TimelineMediaPreviewViewModel(initialItem: item,
|
||||||
timelineViewModel: TimelineViewModel.mock,
|
timelineViewModel: TimelineViewModel.mock(timelineKind: .media(.mediaFilesScreen),
|
||||||
|
timelineController: timelineController),
|
||||||
mediaProvider: mediaProvider,
|
mediaProvider: mediaProvider,
|
||||||
userIndicatorController: UserIndicatorControllerMock())
|
userIndicatorController: UserIndicatorControllerMock())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user