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