mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 19:44:05 +00:00
Add message sending methods to the TimelineController that will automatically use the correct timeline proxy instance internally.
This commit is contained in:
committed by
Stefan Ceriu
parent
a4c0b7f91c
commit
35195abc35
@@ -155,14 +155,96 @@ class MockTimelineController: TimelineControllerProtocol {
|
|||||||
inReplyToEventID: String?,
|
inReplyToEventID: String?,
|
||||||
intentionalMentions: IntentionalMentions) async { }
|
intentionalMentions: IntentionalMentions) async { }
|
||||||
|
|
||||||
func sendVoiceMessage(url: URL, audioInfo: AudioInfo, waveform: [UInt16]) async -> Result<Void, TimelineProxyError> {
|
func sendAudio(url: URL,
|
||||||
|
audioInfo: MatrixRustSDK.AudioInfo,
|
||||||
|
caption: String?,
|
||||||
|
requestHandle: @MainActor (any MatrixRustSDK.SendAttachmentJoinHandleProtocol) -> Void) async -> Result<Void, TimelineControllerError> {
|
||||||
if let timelineProxy {
|
if let timelineProxy {
|
||||||
return await timelineProxy.sendVoiceMessage(url: url, audioInfo: audioInfo, waveform: waveform) { _ in }
|
return await timelineProxy.sendAudio(url: url,
|
||||||
|
audioInfo: audioInfo,
|
||||||
|
caption: caption,
|
||||||
|
requestHandle: requestHandle).mapError(TimelineControllerError.timelineProxyError)
|
||||||
}
|
}
|
||||||
|
|
||||||
return .success(())
|
return .success(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sendFile(url: URL,
|
||||||
|
fileInfo: MatrixRustSDK.FileInfo,
|
||||||
|
caption: String?,
|
||||||
|
requestHandle: @MainActor (any MatrixRustSDK.SendAttachmentJoinHandleProtocol) -> Void) async -> Result<Void, TimelineControllerError> {
|
||||||
|
if let timelineProxy {
|
||||||
|
return await timelineProxy.sendFile(url: url,
|
||||||
|
fileInfo: fileInfo,
|
||||||
|
caption: caption,
|
||||||
|
requestHandle: requestHandle).mapError(TimelineControllerError.timelineProxyError)
|
||||||
|
}
|
||||||
|
|
||||||
|
return .success(())
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendImage(url: URL,
|
||||||
|
thumbnailURL: URL,
|
||||||
|
imageInfo: MatrixRustSDK.ImageInfo,
|
||||||
|
caption: String?,
|
||||||
|
requestHandle: @MainActor (any MatrixRustSDK.SendAttachmentJoinHandleProtocol) -> Void) async -> Result<Void, TimelineControllerError> {
|
||||||
|
if let timelineProxy {
|
||||||
|
return await timelineProxy.sendImage(url: url,
|
||||||
|
thumbnailURL: thumbnailURL,
|
||||||
|
imageInfo: imageInfo,
|
||||||
|
caption: caption,
|
||||||
|
requestHandle: requestHandle).mapError(TimelineControllerError.timelineProxyError)
|
||||||
|
}
|
||||||
|
|
||||||
|
return .success(())
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendLocation(body: String,
|
||||||
|
geoURI: GeoURI,
|
||||||
|
description: String?,
|
||||||
|
zoomLevel: UInt8?,
|
||||||
|
assetType: MatrixRustSDK.AssetType?) async -> Result<Void, TimelineControllerError> {
|
||||||
|
if let timelineProxy {
|
||||||
|
return await timelineProxy.sendLocation(body: body,
|
||||||
|
geoURI: geoURI,
|
||||||
|
description: description,
|
||||||
|
zoomLevel: zoomLevel,
|
||||||
|
assetType: assetType).mapError(TimelineControllerError.timelineProxyError)
|
||||||
|
}
|
||||||
|
|
||||||
|
return .success(())
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendVideo(url: URL,
|
||||||
|
thumbnailURL: URL,
|
||||||
|
videoInfo: MatrixRustSDK.VideoInfo,
|
||||||
|
caption: String?,
|
||||||
|
requestHandle: @MainActor (any MatrixRustSDK.SendAttachmentJoinHandleProtocol) -> Void) async -> Result<Void, TimelineControllerError> {
|
||||||
|
if let timelineProxy {
|
||||||
|
return await timelineProxy.sendVideo(url: url,
|
||||||
|
thumbnailURL: thumbnailURL,
|
||||||
|
videoInfo: videoInfo,
|
||||||
|
caption: caption,
|
||||||
|
requestHandle: requestHandle).mapError(TimelineControllerError.timelineProxyError)
|
||||||
|
}
|
||||||
|
|
||||||
|
return .success(())
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendVoiceMessage(url: URL,
|
||||||
|
audioInfo: MatrixRustSDK.AudioInfo,
|
||||||
|
waveform: [UInt16],
|
||||||
|
requestHandle: @MainActor (any MatrixRustSDK.SendAttachmentJoinHandleProtocol) -> Void) async -> Result<Void, TimelineControllerError> {
|
||||||
|
if let timelineProxy {
|
||||||
|
return await timelineProxy.sendVoiceMessage(url: url,
|
||||||
|
audioInfo: audioInfo,
|
||||||
|
waveform: waveform,
|
||||||
|
requestHandle: requestHandle).mapError(TimelineControllerError.timelineProxyError)
|
||||||
|
}
|
||||||
|
|
||||||
|
return .success(())
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - UI Test signalling
|
// MARK: - UI Test signalling
|
||||||
|
|
||||||
/// The cancellable used for UI Tests signalling.
|
/// The cancellable used for UI Tests signalling.
|
||||||
|
|||||||
@@ -301,10 +301,65 @@ class TimelineController: TimelineControllerProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendVoiceMessage(url: URL, audioInfo: AudioInfo, waveform: [UInt16]) async -> Result<Void, TimelineProxyError> {
|
func sendAudio(url: URL,
|
||||||
|
audioInfo: MatrixRustSDK.AudioInfo,
|
||||||
|
caption: String?,
|
||||||
|
requestHandle: @MainActor (any MatrixRustSDK.SendAttachmentJoinHandleProtocol) -> Void) async -> Result<Void, TimelineControllerError> {
|
||||||
|
await activeTimeline.sendAudio(url: url,
|
||||||
|
audioInfo: audioInfo,
|
||||||
|
caption: caption,
|
||||||
|
requestHandle: requestHandle).mapError(TimelineControllerError.timelineProxyError)
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendFile(url: URL,
|
||||||
|
fileInfo: MatrixRustSDK.FileInfo,
|
||||||
|
caption: String?,
|
||||||
|
requestHandle: @MainActor (any MatrixRustSDK.SendAttachmentJoinHandleProtocol) -> Void) async -> Result<Void, TimelineControllerError> {
|
||||||
|
await activeTimeline.sendFile(url: url,
|
||||||
|
fileInfo: fileInfo,
|
||||||
|
caption: caption,
|
||||||
|
requestHandle: requestHandle).mapError(TimelineControllerError.timelineProxyError)
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendImage(url: URL,
|
||||||
|
thumbnailURL: URL,
|
||||||
|
imageInfo: MatrixRustSDK.ImageInfo,
|
||||||
|
caption: String?,
|
||||||
|
requestHandle: @MainActor (any MatrixRustSDK.SendAttachmentJoinHandleProtocol) -> Void) async -> Result<Void, TimelineControllerError> {
|
||||||
|
await activeTimeline.sendImage(url: url,
|
||||||
|
thumbnailURL: thumbnailURL,
|
||||||
|
imageInfo: imageInfo,
|
||||||
|
caption: caption,
|
||||||
|
requestHandle: requestHandle).mapError(TimelineControllerError.timelineProxyError)
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendVideo(url: URL,
|
||||||
|
thumbnailURL: URL,
|
||||||
|
videoInfo: MatrixRustSDK.VideoInfo,
|
||||||
|
caption: String?,
|
||||||
|
requestHandle: @MainActor (any MatrixRustSDK.SendAttachmentJoinHandleProtocol) -> Void) async -> Result<Void, TimelineControllerError> {
|
||||||
|
await activeTimeline.sendVideo(url: url,
|
||||||
|
thumbnailURL: thumbnailURL,
|
||||||
|
videoInfo: videoInfo,
|
||||||
|
caption: caption,
|
||||||
|
requestHandle: requestHandle).mapError(TimelineControllerError.timelineProxyError)
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendLocation(body: String,
|
||||||
|
geoURI: GeoURI,
|
||||||
|
description: String?,
|
||||||
|
zoomLevel: UInt8?,
|
||||||
|
assetType: AssetType?) async -> Result<Void, TimelineControllerError> {
|
||||||
|
await activeTimeline.sendLocation(body: body, geoURI: geoURI, description: description, zoomLevel: zoomLevel, assetType: assetType).mapError(TimelineControllerError.timelineProxyError)
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendVoiceMessage(url: URL,
|
||||||
|
audioInfo: MatrixRustSDK.AudioInfo,
|
||||||
|
waveform: [UInt16],
|
||||||
|
requestHandle: @MainActor (any MatrixRustSDK.SendAttachmentJoinHandleProtocol) -> Void) async -> Result<Void, TimelineControllerError> {
|
||||||
await activeTimeline.sendVoiceMessage(url: url,
|
await activeTimeline.sendVoiceMessage(url: url,
|
||||||
audioInfo: audioInfo,
|
audioInfo: audioInfo,
|
||||||
waveform: waveform) { _ in }
|
waveform: waveform, requestHandle: requestHandle).mapError(TimelineControllerError.timelineProxyError)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Private
|
// MARK: - Private
|
||||||
|
|||||||
+33
-1
@@ -31,6 +31,7 @@ enum TimelineControllerAction {
|
|||||||
enum TimelineControllerError: Error {
|
enum TimelineControllerError: Error {
|
||||||
case generic
|
case generic
|
||||||
case eventNotFound
|
case eventNotFound
|
||||||
|
case timelineProxyError(TimelineProxyError)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This protocol is a high level abstraction on top of the ``TimelineProxyProtocol``
|
/// This protocol is a high level abstraction on top of the ``TimelineProxyProtocol``
|
||||||
@@ -98,5 +99,36 @@ protocol TimelineControllerProtocol {
|
|||||||
inReplyToEventID: String?,
|
inReplyToEventID: String?,
|
||||||
intentionalMentions: IntentionalMentions) async
|
intentionalMentions: IntentionalMentions) async
|
||||||
|
|
||||||
func sendVoiceMessage(url: URL, audioInfo: AudioInfo, waveform: [UInt16]) async -> Result<Void, TimelineProxyError>
|
func sendAudio(url: URL,
|
||||||
|
audioInfo: AudioInfo,
|
||||||
|
caption: String?,
|
||||||
|
requestHandle: @MainActor (SendAttachmentJoinHandleProtocol) -> Void) async -> Result<Void, TimelineControllerError>
|
||||||
|
|
||||||
|
func sendFile(url: URL,
|
||||||
|
fileInfo: FileInfo,
|
||||||
|
caption: String?,
|
||||||
|
requestHandle: @MainActor (SendAttachmentJoinHandleProtocol) -> Void) async -> Result<Void, TimelineControllerError>
|
||||||
|
|
||||||
|
func sendImage(url: URL,
|
||||||
|
thumbnailURL: URL,
|
||||||
|
imageInfo: ImageInfo,
|
||||||
|
caption: String?,
|
||||||
|
requestHandle: @MainActor (SendAttachmentJoinHandleProtocol) -> Void) async -> Result<Void, TimelineControllerError>
|
||||||
|
|
||||||
|
func sendLocation(body: String,
|
||||||
|
geoURI: GeoURI,
|
||||||
|
description: String?,
|
||||||
|
zoomLevel: UInt8?,
|
||||||
|
assetType: AssetType?) async -> Result<Void, TimelineControllerError>
|
||||||
|
|
||||||
|
func sendVideo(url: URL,
|
||||||
|
thumbnailURL: URL,
|
||||||
|
videoInfo: VideoInfo,
|
||||||
|
caption: String?,
|
||||||
|
requestHandle: @MainActor (SendAttachmentJoinHandleProtocol) -> Void) async -> Result<Void, TimelineControllerError>
|
||||||
|
|
||||||
|
func sendVoiceMessage(url: URL,
|
||||||
|
audioInfo: AudioInfo,
|
||||||
|
waveform: [UInt16],
|
||||||
|
requestHandle: @MainActor (SendAttachmentJoinHandleProtocol) -> Void) async -> Result<Void, TimelineControllerError>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ class VoiceMessageRecorder: VoiceMessageRecorderProtocol {
|
|||||||
|
|
||||||
let result = await timelineController.sendVoiceMessage(url: oggFile,
|
let result = await timelineController.sendVoiceMessage(url: oggFile,
|
||||||
audioInfo: audioInfo,
|
audioInfo: audioInfo,
|
||||||
waveform: waveform)
|
waveform: waveform) { _ in }
|
||||||
|
|
||||||
if case .failure(let error) = result {
|
if case .failure(let error) = result {
|
||||||
MXLog.error("Failed to send the voice message. \(error)")
|
MXLog.error("Failed to send the voice message. \(error)")
|
||||||
|
|||||||
Reference in New Issue
Block a user