Transition voice messages to the new in thread sending mechanism

This commit is contained in:
Stefan Ceriu
2025-07-22 10:41:30 +03:00
committed by Stefan Ceriu
parent ed98f64a35
commit 3fcbc8c60a
8 changed files with 76 additions and 69 deletions
@@ -18,6 +18,8 @@ class MockTimelineController: TimelineControllerProtocol {
var incomingItems: [RoomTimelineItemProtocol] = []
var roomProxy: JoinedRoomProxyProtocol?
var timelineProxy: TimelineProxyProtocol?
var roomID: String { roomProxy?.id ?? "MockRoomIdentifier" }
var timelineKind: TimelineKind
@@ -46,9 +48,13 @@ class MockTimelineController: TimelineControllerProtocol {
return mock
}
init(timelineKind: TimelineKind = .live, listenForSignals: Bool = false, timelineItems: [RoomTimelineItemProtocol] = RoomTimelineItemFixtures.default) {
init(timelineKind: TimelineKind = .live,
listenForSignals: Bool = false,
timelineItems: [RoomTimelineItemProtocol] = RoomTimelineItemFixtures.default,
timelineProxy: TimelineProxyProtocol? = nil) {
self.timelineKind = timelineKind
self.timelineItems = timelineItems
self.timelineProxy = timelineProxy
callbacks.send(.paginationState(paginationState))
callbacks.send(.isLive(true))
@@ -107,6 +113,10 @@ class MockTimelineController: TimelineControllerProtocol {
html: String?,
inReplyToEventID: String?,
intentionalMentions: IntentionalMentions) async { }
func sendVoiceMessage(url: URL, audioInfo: AudioInfo, waveform: [UInt16]) async -> Result<Void, TimelineProxyError> {
await timelineProxy?.sendVoiceMessage(url: url, audioInfo: audioInfo, waveform: waveform, requestHandle: { _ in }) ?? .success(())
}
func toggleReaction(_ reaction: String, to eventID: TimelineItemIdentifier.EventOrTransactionID) async { }
@@ -145,6 +145,8 @@ class TimelineController: TimelineControllerProtocol {
func processItemDisappearance(_ itemID: TimelineItemIdentifier) { }
// MARK: - Sending
func sendMessage(_ message: String,
html: String?,
inReplyToEventID: String?,
@@ -153,7 +155,6 @@ class TimelineController: TimelineControllerProtocol {
switch await activeTimeline.sendMessage(message,
html: html,
threadRootEventID: timelineKind.threadRootEventID,
inReplyToEventID: inReplyToEventID,
intentionalMentions: intentionalMentions) {
case .success:
@@ -164,6 +165,12 @@ class TimelineController: TimelineControllerProtocol {
}
}
func sendVoiceMessage(url: URL, audioInfo: AudioInfo, waveform: [UInt16]) async -> Result<Void, TimelineProxyError> {
await activeTimeline.sendVoiceMessage(url: url,
audioInfo: audioInfo,
waveform: waveform) { _ in }
}
private func donateSendMessageIntent() async {
guard let displayName = roomProxy.details.name ?? roomProxy.details.canonicalAlias, !displayName.isEmpty else {
MXLog.error("Failed donating send message intent, room missing name or alias.")
@@ -68,6 +68,8 @@ protocol TimelineControllerProtocol {
inReplyToEventID: String?,
intentionalMentions: IntentionalMentions) async
func sendVoiceMessage(url: URL, audioInfo: AudioInfo, waveform: [UInt16]) async -> Result<Void, TimelineProxyError>
func edit(_ eventOrTransactionID: TimelineItemIdentifier.EventOrTransactionID,
message: String,
html: String?,
@@ -144,9 +144,8 @@ class VoiceMessageRecorder: VoiceMessageRecorderProtocol {
return .success(waveformData)
}
func sendVoiceMessage(inRoom roomProxy: JoinedRoomProxyProtocol,
audioConverter: AudioConverterProtocol,
threadRootEventID: String?) async -> Result<Void, VoiceMessageRecorderError> {
func sendVoiceMessage(timelineController: TimelineControllerProtocol,
audioConverter: AudioConverterProtocol) async -> Result<Void, VoiceMessageRecorderError> {
guard let url = audioRecorder.audioFileURL else {
return .failure(VoiceMessageRecorderError.missingRecordingFile)
}
@@ -178,9 +177,9 @@ class VoiceMessageRecorder: VoiceMessageRecorderProtocol {
return .failure(.failedSendingVoiceMessage)
}
let result = await roomProxy.timeline.sendVoiceMessage(url: oggFile,
let result = await timelineController.sendVoiceMessage(url: oggFile,
audioInfo: audioInfo,
waveform: waveform) { _ in }
waveform: waveform)
if case .failure(let error) = result {
MXLog.error("Failed to send the voice message. \(error)")
@@ -38,9 +38,8 @@ protocol VoiceMessageRecorderProtocol {
func seekPlayback(to progress: Double) async
func deleteRecording() async
func sendVoiceMessage(inRoom roomProxy: JoinedRoomProxyProtocol,
audioConverter: AudioConverterProtocol,
threadRootEventID: String?) async -> Result<Void, VoiceMessageRecorderError>
func sendVoiceMessage(timelineController: TimelineControllerProtocol,
audioConverter: AudioConverterProtocol) async -> Result<Void, VoiceMessageRecorderError>
}
// sourcery: AutoMockable