mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Pass attachment bodies when loading media
This commit is contained in:
committed by
Stefan Ceriu
parent
95492d7e10
commit
86aebfb9ef
@@ -595,7 +595,7 @@ extension ClientProxy: MediaLoaderProtocol {
|
||||
try await mediaLoader.loadMediaThumbnailForSource(source, width: width, height: height)
|
||||
}
|
||||
|
||||
func loadMediaFileForSource(_ source: MediaSourceProxy) async throws -> MediaFileHandleProxy {
|
||||
try await mediaLoader.loadMediaFileForSource(source)
|
||||
func loadMediaFileForSource(_ source: MediaSourceProxy, body: String?) async throws -> MediaFileHandleProxy {
|
||||
try await mediaLoader.loadMediaFileForSource(source, body: body)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ class MockClientProxy: ClientProxyProtocol {
|
||||
throw ClientProxyError.failedLoadingMedia
|
||||
}
|
||||
|
||||
func loadMediaFileForSource(_ source: MediaSourceProxy) async throws -> MediaFileHandleProxy {
|
||||
func loadMediaFileForSource(_ source: MediaSourceProxy, body: String?) async throws -> MediaFileHandleProxy {
|
||||
throw ClientProxyError.failedLoadingMedia
|
||||
}
|
||||
|
||||
|
||||
@@ -46,9 +46,9 @@ actor MediaLoader: MediaLoaderProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func loadMediaFileForSource(_ source: MediaSourceProxy) async throws -> MediaFileHandleProxy {
|
||||
func loadMediaFileForSource(_ source: MediaSourceProxy, body: String?) async throws -> MediaFileHandleProxy {
|
||||
let result = try await Task.dispatch(on: clientQueue) {
|
||||
try self.client.getMediaFile(mediaSource: source.underlyingSource, mimeType: source.mimeType ?? "application/octet-stream")
|
||||
try self.client.getMediaFile(mediaSource: source.underlyingSource, body: body, mimeType: source.mimeType ?? "application/octet-stream")
|
||||
}
|
||||
|
||||
return MediaFileHandleProxy(handle: result)
|
||||
|
||||
@@ -21,5 +21,11 @@ protocol MediaLoaderProtocol {
|
||||
|
||||
func loadMediaThumbnailForSource(_ source: MediaSourceProxy, width: UInt, height: UInt) async throws -> Data
|
||||
|
||||
func loadMediaFileForSource(_ source: MediaSourceProxy) async throws -> MediaFileHandleProxy
|
||||
func loadMediaFileForSource(_ source: MediaSourceProxy, body: String?) async throws -> MediaFileHandleProxy
|
||||
}
|
||||
|
||||
extension MediaLoaderProtocol {
|
||||
func loadMediaFileForSource(_ source: MediaSourceProxy) async throws -> MediaFileHandleProxy {
|
||||
try await loadMediaFileForSource(source, body: nil)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,12 +91,12 @@ struct MediaProvider: MediaProviderProtocol {
|
||||
|
||||
// MARK: Files
|
||||
|
||||
func loadFileFromSource(_ source: MediaSourceProxy) async -> Result<MediaFileHandleProxy, MediaProviderError> {
|
||||
func loadFileFromSource(_ source: MediaSourceProxy, body: String?) async -> Result<MediaFileHandleProxy, MediaProviderError> {
|
||||
let loadFileBgTask = await backgroundTaskService?.startBackgroundTask(withName: "LoadFile: \(source.url.hashValue)")
|
||||
defer { loadFileBgTask?.stop() }
|
||||
|
||||
do {
|
||||
let file = try await mediaLoader.loadMediaFileForSource(source)
|
||||
let file = try await mediaLoader.loadMediaFileForSource(source, body: body)
|
||||
return .success(file)
|
||||
} catch {
|
||||
MXLog.error("Failed retrieving file with error: \(error)")
|
||||
|
||||
@@ -24,5 +24,11 @@ enum MediaProviderError: Error {
|
||||
}
|
||||
|
||||
protocol MediaProviderProtocol: ImageProviderProtocol {
|
||||
func loadFileFromSource(_ source: MediaSourceProxy) async -> Result<MediaFileHandleProxy, MediaProviderError>
|
||||
func loadFileFromSource(_ source: MediaSourceProxy, body: String?) async -> Result<MediaFileHandleProxy, MediaProviderError>
|
||||
}
|
||||
|
||||
extension MediaProviderProtocol {
|
||||
func loadFileFromSource(_ source: MediaSourceProxy) async -> Result<MediaFileHandleProxy, MediaProviderError> {
|
||||
await loadFileFromSource(source, body: nil)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ struct MockMediaProvider: MediaProviderProtocol {
|
||||
return .success(data)
|
||||
}
|
||||
|
||||
func loadFileFromSource(_ source: MediaSourceProxy) async -> Result<MediaFileHandleProxy, MediaProviderError> {
|
||||
func loadFileFromSource(_ source: MediaSourceProxy, body: String?) async -> Result<MediaFileHandleProxy, MediaProviderError> {
|
||||
.failure(.failedRetrievingFile)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,29 +106,29 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
||||
}
|
||||
|
||||
var source: MediaSourceProxy?
|
||||
var title: String
|
||||
var body: String
|
||||
switch timelineItem {
|
||||
case let item as ImageRoomTimelineItem:
|
||||
source = item.source
|
||||
title = item.body
|
||||
body = item.body
|
||||
case let item as VideoRoomTimelineItem:
|
||||
source = item.source
|
||||
title = item.body
|
||||
body = item.body
|
||||
case let item as FileRoomTimelineItem:
|
||||
source = item.source
|
||||
title = item.body
|
||||
body = item.body
|
||||
case let item as AudioRoomTimelineItem:
|
||||
// For now we are just displaying audio messages with the File preview until we create a timeline player for them.
|
||||
source = item.source
|
||||
title = item.body
|
||||
body = item.body
|
||||
default:
|
||||
return .none
|
||||
}
|
||||
|
||||
guard let source else { return .none }
|
||||
switch await mediaProvider.loadFileFromSource(source) {
|
||||
switch await mediaProvider.loadFileFromSource(source, body: body) {
|
||||
case .success(let file):
|
||||
return .displayMediaFile(file: file, title: title)
|
||||
return .displayMediaFile(file: file, title: body)
|
||||
case .failure:
|
||||
return .none
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user