Reverting RTE to use SDK markdown when in markdown mode (#2327)

This commit is contained in:
Mauro
2024-01-12 12:58:36 +01:00
committed by GitHub
parent 2d66e76b51
commit 1001b5dc33
13 changed files with 76 additions and 32 deletions
@@ -25,6 +25,10 @@ struct IntentionalMentions: Equatable {
}
extension IntentionalMentions {
static var empty: Self {
IntentionalMentions(userIDs: .init(), atRoom: false)
}
func toRustMentions() -> Mentions {
Mentions(userIds: Array(userIDs), room: atRoom)
}
@@ -70,14 +70,14 @@ class MockRoomTimelineController: RoomTimelineControllerProtocol {
func processItemDisappearance(_ itemID: TimelineItemIdentifier) async { }
func sendMessage(_ message: String,
html: String,
html: String?,
inReplyTo itemID: TimelineItemIdentifier?,
intentionalMentions: IntentionalMentions) async { }
func toggleReaction(_ reaction: String, to itemID: TimelineItemIdentifier) async { }
func editMessage(_ newMessage: String,
html: String,
html: String?,
original itemID: TimelineItemIdentifier,
intentionalMentions: IntentionalMentions) async { }
@@ -114,7 +114,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
func processItemDisappearance(_ itemID: TimelineItemIdentifier) { }
func sendMessage(_ message: String,
html: String,
html: String?,
inReplyTo itemID: TimelineItemIdentifier?,
intentionalMentions: IntentionalMentions) async {
var inReplyTo: String?
@@ -155,7 +155,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
}
func editMessage(_ newMessage: String,
html: String,
html: String?,
original itemID: TimelineItemIdentifier,
intentionalMentions: IntentionalMentions) async {
MXLog.info("Edit message in \(roomID)")
@@ -52,12 +52,12 @@ protocol RoomTimelineControllerProtocol {
func sendReadReceipt(for itemID: TimelineItemIdentifier) async -> Result<Void, RoomTimelineControllerError>
func sendMessage(_ message: String,
html: String,
html: String?,
inReplyTo itemID: TimelineItemIdentifier?,
intentionalMentions: IntentionalMentions) async
func editMessage(_ newMessage: String,
html: String,
html: String?,
original itemID: TimelineItemIdentifier,
intentionalMentions: IntentionalMentions) async
@@ -78,7 +78,7 @@ protocol RoomTimelineControllerProtocol {
extension RoomTimelineControllerProtocol {
func sendMessage(_ message: String,
html: String,
html: String?,
intentionalMentions: IntentionalMentions) async {
await sendMessage(message,
html: html,
@@ -96,11 +96,11 @@ final class TimelineProxy: TimelineProxyProtocol {
}
func editMessage(_ message: String,
html: String,
html: String?,
original eventID: String,
intentionalMentions: IntentionalMentions) async -> Result<Void, TimelineProxyError> {
MXLog.info("Editing message with original event ID: \(eventID)")
sendMessageBackgroundTask = await backgroundTaskService.startBackgroundTask(withName: backgroundTaskName, isReusable: true)
defer {
sendMessageBackgroundTask?.stop()
@@ -390,7 +390,7 @@ final class TimelineProxy: TimelineProxyProtocol {
}
func sendMessage(_ message: String,
html: String,
html: String?,
inReplyTo eventID: String? = nil,
intentionalMentions: IntentionalMentions) async -> Result<Void, TimelineProxyError> {
if let eventID {
@@ -573,7 +573,7 @@ final class TimelineProxy: TimelineProxyProtocol {
// MARK: - Private
private func buildMessageContentFor(_ message: String,
html: String,
html: String?,
intentionalMentions: Mentions) -> RoomMessageEventContentWithoutRelation {
let emoteSlashCommand = "/me "
let isEmote: Bool = message.starts(with: emoteSlashCommand)
@@ -581,10 +581,18 @@ final class TimelineProxy: TimelineProxyProtocol {
let content: RoomMessageEventContentWithoutRelation
if isEmote {
let emoteMessage = String(message.dropFirst(emoteSlashCommand.count))
let emoteHtml = String(html.dropFirst(emoteSlashCommand.count))
var emoteHtml: String?
if let html {
emoteHtml = String(html.dropFirst(emoteSlashCommand.count))
}
content = buildEmoteMessageContentFor(emoteMessage, html: emoteHtml)
} else {
content = messageEventContentFromHtml(body: message, htmlBody: html)
if let html {
content = messageEventContentFromHtml(body: message, htmlBody: html)
} else {
content = messageEventContentFromMarkdown(md: message)
}
}
return content.withMentions(mentions: intentionalMentions)
}
@@ -51,7 +51,7 @@ protocol TimelineProxyProtocol {
func cancelSend(transactionID: String) async
func editMessage(_ message: String,
html: String,
html: String?,
original eventID: String,
intentionalMentions: IntentionalMentions) async -> Result<Void, TimelineProxyError>
@@ -107,7 +107,7 @@ protocol TimelineProxyProtocol {
func sendMessageEventContent(_ messageContent: RoomMessageEventContentWithoutRelation) async -> Result<Void, TimelineProxyError>
func sendMessage(_ message: String,
html: String,
html: String?,
inReplyTo eventID: String?,
intentionalMentions: IntentionalMentions) async -> Result<Void, TimelineProxyError>
@@ -125,3 +125,14 @@ protocol TimelineProxyProtocol {
func sendPollResponse(pollStartID: String, answers: [String]) async -> Result<Void, TimelineProxyError>
}
extension TimelineProxyProtocol {
func sendMessage(_ message: String,
html: String?,
intentionalMentions: IntentionalMentions) async -> Result<Void, TimelineProxyError> {
await sendMessage(message,
html: html,
inReplyTo: nil,
intentionalMentions: intentionalMentions)
}
}