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
808fe4cf62
commit
75ea2f55c4
@@ -155,14 +155,96 @@ class MockTimelineController: TimelineControllerProtocol {
|
||||
inReplyToEventID: String?,
|
||||
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 {
|
||||
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(())
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
/// 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,
|
||||
audioInfo: audioInfo,
|
||||
waveform: waveform) { _ in }
|
||||
waveform: waveform, requestHandle: requestHandle).mapError(TimelineControllerError.timelineProxyError)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
@@ -31,6 +31,7 @@ enum TimelineControllerAction {
|
||||
enum TimelineControllerError: Error {
|
||||
case generic
|
||||
case eventNotFound
|
||||
case timelineProxyError(TimelineProxyError)
|
||||
}
|
||||
|
||||
/// This protocol is a high level abstraction on top of the ``TimelineProxyProtocol``
|
||||
@@ -98,5 +99,36 @@ protocol TimelineControllerProtocol {
|
||||
inReplyToEventID: String?,
|
||||
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,
|
||||
audioInfo: audioInfo,
|
||||
waveform: waveform)
|
||||
waveform: waveform) { _ in }
|
||||
|
||||
if case .failure(let error) = result {
|
||||
MXLog.error("Failed to send the voice message. \(error)")
|
||||
|
||||
Reference in New Issue
Block a user