mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Pass attachment bodies when loading media
This commit is contained in:
committed by
Stefan Ceriu
parent
95492d7e10
commit
86aebfb9ef
@@ -20,7 +20,7 @@
|
|||||||
{
|
{
|
||||||
"identity" : "compound-ios",
|
"identity" : "compound-ios",
|
||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
"location" : "https://github.com/vector-im/compound-ios.git",
|
"location" : "https://github.com/vector-im/compound-ios",
|
||||||
"state" : {
|
"state" : {
|
||||||
"revision" : "b4f34edce9003ba1fde31500312f317b728f4ee3"
|
"revision" : "b4f34edce9003ba1fde31500312f317b728f4ee3"
|
||||||
}
|
}
|
||||||
@@ -111,8 +111,8 @@
|
|||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
"location" : "https://github.com/matrix-org/matrix-rust-components-swift",
|
"location" : "https://github.com/matrix-org/matrix-rust-components-swift",
|
||||||
"state" : {
|
"state" : {
|
||||||
"revision" : "3a1355ab4c6933e9f55d8a7addcefb13c6a5c26d",
|
"revision" : "15c314fcb20e3b009b573a50edc4736a73e63c96",
|
||||||
"version" : "1.0.58-alpha"
|
"version" : "1.0.59-alpha"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -595,7 +595,7 @@ extension ClientProxy: MediaLoaderProtocol {
|
|||||||
try await mediaLoader.loadMediaThumbnailForSource(source, width: width, height: height)
|
try await mediaLoader.loadMediaThumbnailForSource(source, width: width, height: height)
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadMediaFileForSource(_ source: MediaSourceProxy) async throws -> MediaFileHandleProxy {
|
func loadMediaFileForSource(_ source: MediaSourceProxy, body: String?) async throws -> MediaFileHandleProxy {
|
||||||
try await mediaLoader.loadMediaFileForSource(source)
|
try await mediaLoader.loadMediaFileForSource(source, body: body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ class MockClientProxy: ClientProxyProtocol {
|
|||||||
throw ClientProxyError.failedLoadingMedia
|
throw ClientProxyError.failedLoadingMedia
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadMediaFileForSource(_ source: MediaSourceProxy) async throws -> MediaFileHandleProxy {
|
func loadMediaFileForSource(_ source: MediaSourceProxy, body: String?) async throws -> MediaFileHandleProxy {
|
||||||
throw ClientProxyError.failedLoadingMedia
|
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) {
|
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)
|
return MediaFileHandleProxy(handle: result)
|
||||||
|
|||||||
@@ -21,5 +21,11 @@ protocol MediaLoaderProtocol {
|
|||||||
|
|
||||||
func loadMediaThumbnailForSource(_ source: MediaSourceProxy, width: UInt, height: UInt) async throws -> Data
|
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
|
// 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)")
|
let loadFileBgTask = await backgroundTaskService?.startBackgroundTask(withName: "LoadFile: \(source.url.hashValue)")
|
||||||
defer { loadFileBgTask?.stop() }
|
defer { loadFileBgTask?.stop() }
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let file = try await mediaLoader.loadMediaFileForSource(source)
|
let file = try await mediaLoader.loadMediaFileForSource(source, body: body)
|
||||||
return .success(file)
|
return .success(file)
|
||||||
} catch {
|
} catch {
|
||||||
MXLog.error("Failed retrieving file with error: \(error)")
|
MXLog.error("Failed retrieving file with error: \(error)")
|
||||||
|
|||||||
@@ -24,5 +24,11 @@ enum MediaProviderError: Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protocol MediaProviderProtocol: ImageProviderProtocol {
|
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)
|
return .success(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadFileFromSource(_ source: MediaSourceProxy) async -> Result<MediaFileHandleProxy, MediaProviderError> {
|
func loadFileFromSource(_ source: MediaSourceProxy, body: String?) async -> Result<MediaFileHandleProxy, MediaProviderError> {
|
||||||
.failure(.failedRetrievingFile)
|
.failure(.failedRetrievingFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,29 +106,29 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var source: MediaSourceProxy?
|
var source: MediaSourceProxy?
|
||||||
var title: String
|
var body: String
|
||||||
switch timelineItem {
|
switch timelineItem {
|
||||||
case let item as ImageRoomTimelineItem:
|
case let item as ImageRoomTimelineItem:
|
||||||
source = item.source
|
source = item.source
|
||||||
title = item.body
|
body = item.body
|
||||||
case let item as VideoRoomTimelineItem:
|
case let item as VideoRoomTimelineItem:
|
||||||
source = item.source
|
source = item.source
|
||||||
title = item.body
|
body = item.body
|
||||||
case let item as FileRoomTimelineItem:
|
case let item as FileRoomTimelineItem:
|
||||||
source = item.source
|
source = item.source
|
||||||
title = item.body
|
body = item.body
|
||||||
case let item as AudioRoomTimelineItem:
|
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.
|
// For now we are just displaying audio messages with the File preview until we create a timeline player for them.
|
||||||
source = item.source
|
source = item.source
|
||||||
title = item.body
|
body = item.body
|
||||||
default:
|
default:
|
||||||
return .none
|
return .none
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let source else { return .none }
|
guard let source else { return .none }
|
||||||
switch await mediaProvider.loadFileFromSource(source) {
|
switch await mediaProvider.loadFileFromSource(source, body: body) {
|
||||||
case .success(let file):
|
case .success(let file):
|
||||||
return .displayMediaFile(file: file, title: title)
|
return .displayMediaFile(file: file, title: body)
|
||||||
case .failure:
|
case .failure:
|
||||||
return .none
|
return .none
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ private class MockMediaLoadingClient: ClientProtocol {
|
|||||||
|
|
||||||
func uploadMedia(mimeType: String, data content: [UInt8]) throws -> String { fatalError() }
|
func uploadMedia(mimeType: String, data content: [UInt8]) throws -> String { fatalError() }
|
||||||
|
|
||||||
func getMediaFile(mediaSource: MatrixRustSDK.MediaSource, mimeType: String) throws -> MatrixRustSDK.MediaFileHandle { fatalError() }
|
func getMediaFile(mediaSource: MatrixRustSDK.MediaSource, body: String?, mimeType: String) throws -> MatrixRustSDK.MediaFileHandle { fatalError() }
|
||||||
|
|
||||||
func getProfile(userId: String) throws -> MatrixRustSDK.UserProfile { fatalError() }
|
func getProfile(userId: String) throws -> MatrixRustSDK.UserProfile { fatalError() }
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class MockMediaLoader: MediaLoaderProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadMediaFileForSource(_ source: MediaSourceProxy) async throws -> MediaFileHandleProxy {
|
func loadMediaFileForSource(_ source: MediaSourceProxy, body: String?) async throws -> MediaFileHandleProxy {
|
||||||
if let mediaFileURL {
|
if let mediaFileURL {
|
||||||
return .unmanaged(url: mediaFileURL)
|
return .unmanaged(url: mediaFileURL)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+1
-1
@@ -42,7 +42,7 @@ include:
|
|||||||
packages:
|
packages:
|
||||||
MatrixRustSDK:
|
MatrixRustSDK:
|
||||||
url: https://github.com/matrix-org/matrix-rust-components-swift
|
url: https://github.com/matrix-org/matrix-rust-components-swift
|
||||||
exactVersion: 1.0.58-alpha
|
exactVersion: 1.0.59-alpha
|
||||||
# path: ../matrix-rust-sdk
|
# path: ../matrix-rust-sdk
|
||||||
DesignKit:
|
DesignKit:
|
||||||
path: DesignKit
|
path: DesignKit
|
||||||
|
|||||||
Reference in New Issue
Block a user