Remove threadRootEventID parameters from TimelineProxy send methods. This is now handled internally to the SDK as long as the right timeline instance is used.

This commit is contained in:
Stefan Ceriu
2025-07-22 10:05:42 +03:00
committed by Stefan Ceriu
parent d6f7607538
commit ed98f64a35
13 changed files with 361 additions and 365 deletions
@@ -97,7 +97,8 @@ class AuthenticationService: AuthenticationServiceProtocol {
let oidcData = try await client.urlForOidc(oidcConfiguration: appSettings.oidcConfiguration.rustValue,
prompt: .consent,
loginHint: loginHint,
deviceId: nil)
deviceId: nil,
additionalScopes: nil)
return .success(OIDCAuthorizationDataProxy(underlyingData: oidcData))
} catch {
MXLog.error("Failed to get URL for OIDC login: \(error)")
@@ -229,22 +229,15 @@ final class TimelineProxy: TimelineProxyProtocol {
func sendAudio(url: URL,
audioInfo: AudioInfo,
caption: String?,
threadRootEventID: String?,
requestHandle: @MainActor (SendAttachmentJoinHandleProtocol) -> Void) async -> Result<Void, TimelineProxyError> {
MXLog.info("Sending audio")
let replyParameters: ReplyParameters? = if let threadRootEventID {
ReplyParameters(eventId: threadRootEventID, enforceThread: true, replyWithinThread: false)
} else {
nil
}
do {
let handle = try timeline.sendAudio(params: .init(source: .file(filename: url.path(percentEncoded: false)),
caption: caption,
formattedCaption: nil, // Rust will build this from the caption's markdown.
mentions: nil,
replyParams: replyParameters,
inReplyTo: nil,
useSendQueue: true),
audioInfo: audioInfo,
progressWatcher: nil)
@@ -264,22 +257,15 @@ final class TimelineProxy: TimelineProxyProtocol {
func sendFile(url: URL,
fileInfo: FileInfo,
caption: String?,
threadRootEventID: String?,
requestHandle: @MainActor (SendAttachmentJoinHandleProtocol) -> Void) async -> Result<Void, TimelineProxyError> {
MXLog.info("Sending file")
let replyParameters: ReplyParameters? = if let threadRootEventID {
ReplyParameters(eventId: threadRootEventID, enforceThread: true, replyWithinThread: false)
} else {
nil
}
do {
let handle = try timeline.sendFile(params: .init(source: .file(filename: url.path(percentEncoded: false)),
caption: caption,
formattedCaption: nil, // Rust will build this from the caption's markdown.
mentions: nil,
replyParams: replyParameters,
inReplyTo: nil,
useSendQueue: true),
fileInfo: fileInfo,
progressWatcher: nil)
@@ -300,22 +286,15 @@ final class TimelineProxy: TimelineProxyProtocol {
thumbnailURL: URL,
imageInfo: ImageInfo,
caption: String?,
threadRootEventID: String?,
requestHandle: @MainActor (SendAttachmentJoinHandleProtocol) -> Void) async -> Result<Void, TimelineProxyError> {
MXLog.info("Sending image")
let replyParameters: ReplyParameters? = if let threadRootEventID {
ReplyParameters(eventId: threadRootEventID, enforceThread: true, replyWithinThread: false)
} else {
nil
}
do {
let handle = try timeline.sendImage(params: .init(source: .file(filename: url.path(percentEncoded: false)),
caption: caption,
formattedCaption: nil, // Rust will build this from the caption's markdown.
mentions: nil,
replyParams: replyParameters,
inReplyTo: nil,
useSendQueue: true),
thumbnailPath: thumbnailURL.path(percentEncoded: false),
imageInfo: imageInfo,
@@ -337,23 +316,16 @@ final class TimelineProxy: TimelineProxyProtocol {
geoURI: GeoURI,
description: String?,
zoomLevel: UInt8?,
assetType: AssetType?,
threadRootEventID: String?) async -> Result<Void, TimelineProxyError> {
assetType: AssetType?) async -> Result<Void, TimelineProxyError> {
MXLog.info("Sending location")
let replyParameters: ReplyParameters? = if let threadRootEventID {
ReplyParameters(eventId: threadRootEventID, enforceThread: true, replyWithinThread: false)
} else {
nil
}
do {
try await timeline.sendLocation(body: body,
geoUri: geoURI.string,
description: description,
zoomLevel: zoomLevel,
assetType: assetType,
replyParams: replyParameters)
repliedToEventId: nil)
MXLog.info("Finished sending location")
} catch {
@@ -368,22 +340,15 @@ final class TimelineProxy: TimelineProxyProtocol {
thumbnailURL: URL,
videoInfo: VideoInfo,
caption: String?,
threadRootEventID: String?,
requestHandle: @MainActor (SendAttachmentJoinHandleProtocol) -> Void) async -> Result<Void, TimelineProxyError> {
MXLog.info("Sending video")
let replyParameters: ReplyParameters? = if let threadRootEventID {
ReplyParameters(eventId: threadRootEventID, enforceThread: true, replyWithinThread: false)
} else {
nil
}
do {
let handle = try timeline.sendVideo(params: .init(source: .file(filename: url.path(percentEncoded: false)),
caption: caption,
formattedCaption: nil,
mentions: nil,
replyParams: replyParameters,
inReplyTo: nil,
useSendQueue: true),
thumbnailPath: thumbnailURL.path(percentEncoded: false),
videoInfo: videoInfo,
@@ -404,22 +369,15 @@ final class TimelineProxy: TimelineProxyProtocol {
func sendVoiceMessage(url: URL,
audioInfo: AudioInfo,
waveform: [UInt16],
threadRootEventID: String?,
requestHandle: @MainActor (SendAttachmentJoinHandleProtocol) -> Void) async -> Result<Void, TimelineProxyError> {
MXLog.info("Sending voice message")
let replyParameters: ReplyParameters? = if let threadRootEventID {
ReplyParameters(eventId: threadRootEventID, enforceThread: true, replyWithinThread: false)
} else {
nil
}
do {
let handle = try timeline.sendVoiceMessage(params: .init(source: .file(filename: url.path(percentEncoded: false)),
caption: nil,
formattedCaption: nil,
mentions: nil,
replyParams: replyParameters,
inReplyTo: nil,
useSendQueue: true),
audioInfo: audioInfo,
waveform: waveform,
@@ -438,14 +396,10 @@ final class TimelineProxy: TimelineProxyProtocol {
}
/// Send a message within a room. If `inReplyToEventID` is specified then it will be sent as a reply
/// to that particular message. If the `threadRootEventID` is also specified then it will be sent
/// as a reply to the given `inReplyToEventID` within the thread rooted in `threadRootEventID`
///
/// Internally `enforceThread` is set to true whenever `threadRootEventID` is specified
/// and `replyWithinThread` when `inReplyToEventID` is.
/// to that particular message. This works for both normal and threaded timelines with the relation and
/// fallback logic being handled SDK side based on the timeline instance focus mode.
func sendMessage(_ message: String,
html: String?,
threadRootEventID: String?,
inReplyToEventID: String? = nil,
intentionalMentions: IntentionalMentions) async -> Result<Void, TimelineProxyError> {
if let inReplyToEventID {
@@ -460,18 +414,10 @@ final class TimelineProxy: TimelineProxyProtocol {
do {
if let inReplyToEventID {
try await timeline.sendReply(msg: messageContent, replyParams: .init(eventId: inReplyToEventID,
enforceThread: threadRootEventID != nil,
replyWithinThread: threadRootEventID != nil))
try await timeline.sendReply(msg: messageContent, eventId: inReplyToEventID)
MXLog.info("Finished sending reply to eventID: \(inReplyToEventID)")
} else {
if let threadRootEventID {
try await timeline.sendReply(msg: messageContent, replyParams: .init(eventId: threadRootEventID,
enforceThread: true,
replyWithinThread: false))
} else {
_ = try await timeline.send(msg: messageContent)
}
_ = try await timeline.send(msg: messageContent)
MXLog.info("Finished sending message")
}
} catch {
@@ -543,8 +489,7 @@ final class TimelineProxy: TimelineProxyProtocol {
// MARK: - Polls
func createPoll(question: String, answers: [String],
pollKind: Poll.Kind,
threadRootEventID: String? = nil) async -> Result<Void, TimelineProxyError> {
pollKind: Poll.Kind) async -> Result<Void, TimelineProxyError> {
MXLog.info("Creating poll")
do {
@@ -82,40 +82,34 @@ protocol TimelineProxyProtocol {
func sendAudio(url: URL,
audioInfo: AudioInfo,
caption: String?,
threadRootEventID: String?,
requestHandle: @MainActor (SendAttachmentJoinHandleProtocol) -> Void) async -> Result<Void, TimelineProxyError>
func sendFile(url: URL,
fileInfo: FileInfo,
caption: String?,
threadRootEventID: String?,
requestHandle: @MainActor (SendAttachmentJoinHandleProtocol) -> Void) async -> Result<Void, TimelineProxyError>
func sendImage(url: URL,
thumbnailURL: URL,
imageInfo: ImageInfo,
caption: String?,
threadRootEventID: String?,
requestHandle: @MainActor (SendAttachmentJoinHandleProtocol) -> Void) async -> Result<Void, TimelineProxyError>
func sendLocation(body: String,
geoURI: GeoURI,
description: String?,
zoomLevel: UInt8?,
assetType: AssetType?,
threadRootEventID: String?) async -> Result<Void, TimelineProxyError>
assetType: AssetType?) async -> Result<Void, TimelineProxyError>
func sendVideo(url: URL,
thumbnailURL: URL,
videoInfo: VideoInfo,
caption: String?,
threadRootEventID: String?,
requestHandle: @MainActor (SendAttachmentJoinHandleProtocol) -> Void) async -> Result<Void, TimelineProxyError>
func sendVoiceMessage(url: URL,
audioInfo: AudioInfo,
waveform: [UInt16],
threadRootEventID: String?,
requestHandle: @MainActor (SendAttachmentJoinHandleProtocol) -> Void) async -> Result<Void, TimelineProxyError>
func sendReadReceipt(for eventID: String, type: ReceiptType) async -> Result<Void, TimelineProxyError>
@@ -125,13 +119,12 @@ protocol TimelineProxyProtocol {
func sendMessage(_ message: String,
html: String?,
threadRootEventID: String?,
inReplyToEventID: String?,
intentionalMentions: IntentionalMentions) async -> Result<Void, TimelineProxyError>
func toggleReaction(_ reaction: String, to eventID: TimelineItemIdentifier.EventOrTransactionID) async -> Result<Void, TimelineProxyError>
func createPoll(question: String, answers: [String], pollKind: Poll.Kind, threadRootEventID: String?) async -> Result<Void, TimelineProxyError>
func createPoll(question: String, answers: [String], pollKind: Poll.Kind) async -> Result<Void, TimelineProxyError>
func editPoll(original eventID: String,
question: String,
@@ -180,8 +180,7 @@ class VoiceMessageRecorder: VoiceMessageRecorderProtocol {
let result = await roomProxy.timeline.sendVoiceMessage(url: oggFile,
audioInfo: audioInfo,
waveform: waveform,
threadRootEventID: threadRootEventID) { _ in }
waveform: waveform) { _ in }
if case .failure(let error) = result {
MXLog.error("Failed to send the voice message. \(error)")