Use the new TimelineController message sending methods for media uploads.
This commit is contained in:
committed by
Stefan Ceriu
parent
75ea2f55c4
commit
78cbcc5c26
@@ -9,13 +9,13 @@ import Combine
|
||||
import SwiftUI
|
||||
|
||||
struct MediaUploadPreviewScreenCoordinatorParameters {
|
||||
let roomProxy: JoinedRoomProxyProtocol
|
||||
let timelineController: TimelineControllerProtocol
|
||||
let userIndicatorController: UserIndicatorControllerProtocol
|
||||
let mediaUploadingPreprocessor: MediaUploadingPreprocessor
|
||||
let title: String?
|
||||
let url: URL
|
||||
let shouldShowCaptionWarning: Bool
|
||||
let isRoomEncrypted: Bool
|
||||
}
|
||||
|
||||
enum MediaUploadPreviewScreenCoordinatorAction {
|
||||
@@ -32,13 +32,13 @@ final class MediaUploadPreviewScreenCoordinator: CoordinatorProtocol {
|
||||
}
|
||||
|
||||
init(parameters: MediaUploadPreviewScreenCoordinatorParameters) {
|
||||
viewModel = MediaUploadPreviewScreenViewModel(roomProxy: parameters.roomProxy,
|
||||
timelineController: parameters.timelineController,
|
||||
viewModel = MediaUploadPreviewScreenViewModel(timelineController: parameters.timelineController,
|
||||
userIndicatorController: parameters.userIndicatorController,
|
||||
mediaUploadingPreprocessor: parameters.mediaUploadingPreprocessor,
|
||||
title: parameters.title,
|
||||
url: parameters.url,
|
||||
shouldShowCaptionWarning: parameters.shouldShowCaptionWarning)
|
||||
shouldShowCaptionWarning: parameters.shouldShowCaptionWarning,
|
||||
isRoomEncrypted: parameters.isRoomEncrypted)
|
||||
}
|
||||
|
||||
func start() {
|
||||
|
||||
@@ -12,7 +12,6 @@ import SwiftUI
|
||||
typealias MediaUploadPreviewScreenViewModelType = StateStoreViewModelV2<MediaUploadPreviewScreenViewState, MediaUploadPreviewScreenViewAction>
|
||||
|
||||
class MediaUploadPreviewScreenViewModel: MediaUploadPreviewScreenViewModelType, MediaUploadPreviewScreenViewModelProtocol {
|
||||
private let roomProxy: JoinedRoomProxyProtocol
|
||||
private let timelineController: TimelineControllerProtocol
|
||||
private let userIndicatorController: UserIndicatorControllerProtocol
|
||||
|
||||
@@ -28,14 +27,13 @@ class MediaUploadPreviewScreenViewModel: MediaUploadPreviewScreenViewModelType,
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init(roomProxy: JoinedRoomProxyProtocol,
|
||||
timelineController: TimelineControllerProtocol,
|
||||
init(timelineController: TimelineControllerProtocol,
|
||||
userIndicatorController: UserIndicatorControllerProtocol,
|
||||
mediaUploadingPreprocessor: MediaUploadingPreprocessor,
|
||||
title: String?,
|
||||
url: URL,
|
||||
shouldShowCaptionWarning: Bool) {
|
||||
self.roomProxy = roomProxy
|
||||
shouldShowCaptionWarning: Bool,
|
||||
isRoomEncrypted: Bool) {
|
||||
self.timelineController = timelineController
|
||||
self.userIndicatorController = userIndicatorController
|
||||
self.mediaUploadingPreprocessor = mediaUploadingPreprocessor
|
||||
@@ -47,7 +45,7 @@ class MediaUploadPreviewScreenViewModel: MediaUploadPreviewScreenViewModelType,
|
||||
super.init(initialViewState: MediaUploadPreviewScreenViewState(url: url,
|
||||
title: title,
|
||||
shouldShowCaptionWarning: shouldShowCaptionWarning,
|
||||
isRoomEncrypted: roomProxy.infoPublisher.value.isEncrypted))
|
||||
isRoomEncrypted: isRoomEncrypted))
|
||||
}
|
||||
|
||||
override func process(viewAction: MediaUploadPreviewScreenViewAction) {
|
||||
@@ -90,31 +88,31 @@ class MediaUploadPreviewScreenViewModel: MediaUploadPreviewScreenViewModelType,
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func sendAttachment(mediaInfo: MediaInfo, caption: String?) async -> Result<Void, TimelineProxyError> {
|
||||
private func sendAttachment(mediaInfo: MediaInfo, caption: String?) async -> Result<Void, TimelineControllerError> {
|
||||
let requestHandle: ((SendAttachmentJoinHandleProtocol) -> Void) = { [weak self] handle in
|
||||
self?.requestHandle = handle
|
||||
}
|
||||
|
||||
switch mediaInfo {
|
||||
case let .image(imageURL, thumbnailURL, imageInfo):
|
||||
return await roomProxy.timeline.sendImage(url: imageURL,
|
||||
return await timelineController.sendImage(url: imageURL,
|
||||
thumbnailURL: thumbnailURL,
|
||||
imageInfo: imageInfo,
|
||||
caption: caption,
|
||||
requestHandle: requestHandle)
|
||||
case let .video(videoURL, thumbnailURL, videoInfo):
|
||||
return await roomProxy.timeline.sendVideo(url: videoURL,
|
||||
return await timelineController.sendVideo(url: videoURL,
|
||||
thumbnailURL: thumbnailURL,
|
||||
videoInfo: videoInfo,
|
||||
caption: caption,
|
||||
requestHandle: requestHandle)
|
||||
case let .audio(audioURL, audioInfo):
|
||||
return await roomProxy.timeline.sendAudio(url: audioURL,
|
||||
return await timelineController.sendAudio(url: audioURL,
|
||||
audioInfo: audioInfo,
|
||||
caption: caption,
|
||||
requestHandle: requestHandle)
|
||||
case let .file(fileURL, fileInfo):
|
||||
return await roomProxy.timeline.sendFile(url: fileURL,
|
||||
return await timelineController.sendFile(url: fileURL,
|
||||
fileInfo: fileInfo,
|
||||
caption: caption,
|
||||
requestHandle: requestHandle)
|
||||
|
||||
@@ -227,13 +227,13 @@ struct MediaUploadPreviewScreen_Previews: PreviewProvider, TestablePreview {
|
||||
static let snapshotURL = URL.picturesDirectory
|
||||
static let testURL = Bundle.main.url(forResource: "AppIcon60x60@2x", withExtension: "png")
|
||||
|
||||
static let viewModel = MediaUploadPreviewScreenViewModel(roomProxy: JoinedRoomProxyMock(.init()),
|
||||
timelineController: MockTimelineController(),
|
||||
static let viewModel = MediaUploadPreviewScreenViewModel(timelineController: MockTimelineController(),
|
||||
userIndicatorController: UserIndicatorControllerMock.default,
|
||||
mediaUploadingPreprocessor: MediaUploadingPreprocessor(appSettings: ServiceLocator.shared.settings),
|
||||
title: "App Icon.png",
|
||||
url: snapshotURL,
|
||||
shouldShowCaptionWarning: true)
|
||||
shouldShowCaptionWarning: true,
|
||||
isRoomEncrypted: true)
|
||||
static var previews: some View {
|
||||
NavigationStack {
|
||||
MediaUploadPreviewScreen(context: viewModel.context)
|
||||
|
||||
@@ -119,15 +119,13 @@ class MediaUploadPreviewScreenViewModelTests: XCTestCase {
|
||||
self?.verifyCaption(caption, expectedCaption: expectedCaption) ?? .failure(.sdkError(TestError.unknown))
|
||||
}
|
||||
|
||||
let roomProxy = JoinedRoomProxyMock(.init())
|
||||
roomProxy.timeline = timelineProxy
|
||||
viewModel = MediaUploadPreviewScreenViewModel(roomProxy: roomProxy,
|
||||
timelineController: MockTimelineController(timelineProxy: timelineProxy),
|
||||
viewModel = MediaUploadPreviewScreenViewModel(timelineController: MockTimelineController(timelineProxy: timelineProxy),
|
||||
userIndicatorController: UserIndicatorControllerMock(),
|
||||
mediaUploadingPreprocessor: MediaUploadingPreprocessor(appSettings: ServiceLocator.shared.settings),
|
||||
title: "Some File",
|
||||
url: url,
|
||||
shouldShowCaptionWarning: true)
|
||||
shouldShowCaptionWarning: true,
|
||||
isRoomEncrypted: true)
|
||||
}
|
||||
|
||||
private func verifyCaption(_ caption: String?, expectedCaption: String?) -> Result<Void, TimelineProxyError> {
|
||||
|
||||
Reference in New Issue
Block a user