mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-05 11:58:32 +00:00
Initial integration of RTE (#1464)
* Initial integration of RTE * Fix `clipped`, `focused` and composer view type * Remove horizontal padding * Add `ComposerToolbar` mock * Restore `composerFocusedSubject` * Allow using HTML from RTE on message sent * Fix new message content API * Add feature flag for Rich Text Editor
This commit is contained in:
@@ -262,15 +262,19 @@ class RoomProxy: RoomProxyProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func sendMessage(_ message: String, inReplyTo eventID: String? = nil) async -> Result<Void, RoomProxyError> {
|
||||
func sendMessage(_ message: String, html: String?, inReplyTo eventID: String? = nil) async -> Result<Void, RoomProxyError> {
|
||||
sendMessageBackgroundTask = await backgroundTaskService.startBackgroundTask(withName: backgroundTaskName, isReusable: true)
|
||||
defer {
|
||||
sendMessageBackgroundTask?.stop()
|
||||
}
|
||||
|
||||
let transactionId = genTransactionId()
|
||||
let messageContent = messageEventContentFromMarkdown(md: message)
|
||||
|
||||
let messageContent: RoomMessageEventContentWithoutRelation
|
||||
if let html {
|
||||
messageContent = messageEventContentFromHtml(body: message, htmlBody: html)
|
||||
} else {
|
||||
messageContent = messageEventContentFromMarkdown(md: message)
|
||||
}
|
||||
return await Task.dispatch(on: messageSendingDispatchQueue) {
|
||||
do {
|
||||
if let eventID {
|
||||
@@ -443,17 +447,22 @@ class RoomProxy: RoomProxyProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func editMessage(_ newMessage: String, original eventID: String) async -> Result<Void, RoomProxyError> {
|
||||
func editMessage(_ newMessage: String, html: String?, original eventID: String) async -> Result<Void, RoomProxyError> {
|
||||
sendMessageBackgroundTask = await backgroundTaskService.startBackgroundTask(withName: backgroundTaskName, isReusable: true)
|
||||
defer {
|
||||
sendMessageBackgroundTask?.stop()
|
||||
}
|
||||
|
||||
let transactionId = genTransactionId()
|
||||
let newMessageContent: RoomMessageEventContentWithoutRelation
|
||||
if let html {
|
||||
newMessageContent = messageEventContentFromHtml(body: newMessage, htmlBody: html)
|
||||
} else {
|
||||
newMessageContent = messageEventContentFromMarkdown(md: newMessage)
|
||||
}
|
||||
|
||||
return await Task.dispatch(on: messageSendingDispatchQueue) {
|
||||
do {
|
||||
let newMessageContent = messageEventContentFromMarkdown(md: newMessage)
|
||||
try self.room.edit(newMsg: newMessageContent, originalEventId: eventID, txnId: transactionId)
|
||||
return .success(())
|
||||
} catch {
|
||||
|
||||
@@ -92,7 +92,7 @@ protocol RoomProxyProtocol {
|
||||
|
||||
func sendMessageEventContent(_ messageContent: RoomMessageEventContentWithoutRelation) async -> Result<Void, RoomProxyError>
|
||||
|
||||
func sendMessage(_ message: String, inReplyTo eventID: String?) async -> Result<Void, RoomProxyError>
|
||||
func sendMessage(_ message: String, html: String?, inReplyTo eventID: String?) async -> Result<Void, RoomProxyError>
|
||||
|
||||
func toggleReaction(_ reaction: String, to eventID: String) async -> Result<Void, RoomProxyError>
|
||||
|
||||
@@ -130,7 +130,7 @@ protocol RoomProxyProtocol {
|
||||
/// Cancels a failed message given its transaction ID from the timeline
|
||||
func cancelSend(transactionID: String) async
|
||||
|
||||
func editMessage(_ newMessage: String, original eventID: String) async -> Result<Void, RoomProxyError>
|
||||
func editMessage(_ newMessage: String, html: String?, original eventID: String) async -> Result<Void, RoomProxyError>
|
||||
|
||||
func redact(_ eventID: String) async -> Result<Void, RoomProxyError>
|
||||
|
||||
@@ -181,8 +181,8 @@ extension RoomProxyProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func sendMessage(_ message: String) async -> Result<Void, RoomProxyError> {
|
||||
await sendMessage(message, inReplyTo: nil)
|
||||
func sendMessage(_ message: String, html: String?) async -> Result<Void, RoomProxyError> {
|
||||
await sendMessage(message, html: html, inReplyTo: nil)
|
||||
}
|
||||
|
||||
// Avoids to duplicate the same logic around in the app
|
||||
|
||||
+2
-2
@@ -66,11 +66,11 @@ class MockRoomTimelineController: RoomTimelineControllerProtocol {
|
||||
|
||||
func processItemTap(_ itemID: TimelineItemIdentifier) async -> RoomTimelineControllerAction { .none }
|
||||
|
||||
func sendMessage(_ message: String, inReplyTo itemID: TimelineItemIdentifier?) async { }
|
||||
func sendMessage(_ message: String, html: String?, inReplyTo itemID: TimelineItemIdentifier?) async { }
|
||||
|
||||
func toggleReaction(_ reaction: String, to itemID: TimelineItemIdentifier) async { }
|
||||
|
||||
func editMessage(_ newMessage: String, original itemID: TimelineItemIdentifier) async { }
|
||||
func editMessage(_ newMessage: String, html: String?, original itemID: TimelineItemIdentifier) async { }
|
||||
|
||||
func redact(_ itemID: TimelineItemIdentifier) async { }
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func sendMessage(_ message: String, inReplyTo itemID: TimelineItemIdentifier?) async {
|
||||
func sendMessage(_ message: String, html: String?, inReplyTo itemID: TimelineItemIdentifier?) async {
|
||||
var inReplyTo: String?
|
||||
if itemID == nil {
|
||||
MXLog.info("Send message in \(roomID)")
|
||||
@@ -133,7 +133,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
||||
return
|
||||
}
|
||||
|
||||
switch await roomProxy.sendMessage(message, inReplyTo: inReplyTo) {
|
||||
switch await roomProxy.sendMessage(message, html: html, inReplyTo: inReplyTo) {
|
||||
case .success:
|
||||
MXLog.info("Finished sending message")
|
||||
case .failure(let error):
|
||||
@@ -156,16 +156,16 @@ class RoomTimelineController: RoomTimelineControllerProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func editMessage(_ newMessage: String, original itemID: TimelineItemIdentifier) async {
|
||||
func editMessage(_ newMessage: String, html: String?, original itemID: TimelineItemIdentifier) async {
|
||||
MXLog.info("Edit message in \(roomID)")
|
||||
if let timelineItem = timelineItems.firstUsingStableID(itemID),
|
||||
let item = timelineItem as? EventBasedTimelineItemProtocol,
|
||||
item.hasFailedToSend {
|
||||
MXLog.info("Editing a failed echo, will cancel and resend it as a new message")
|
||||
await cancelSend(itemID)
|
||||
await sendMessage(newMessage)
|
||||
await sendMessage(newMessage, html: html)
|
||||
} else if let eventID = itemID.eventID {
|
||||
switch await roomProxy.editMessage(newMessage, original: eventID) {
|
||||
switch await roomProxy.editMessage(newMessage, html: html, original: eventID) {
|
||||
case .success:
|
||||
MXLog.info("Finished editing message")
|
||||
case .failure(let error):
|
||||
|
||||
+4
-4
@@ -51,9 +51,9 @@ protocol RoomTimelineControllerProtocol {
|
||||
|
||||
func sendReadReceipt(for itemID: TimelineItemIdentifier) async -> Result<Void, RoomTimelineControllerError>
|
||||
|
||||
func sendMessage(_ message: String, inReplyTo itemID: TimelineItemIdentifier?) async
|
||||
func sendMessage(_ message: String, html: String?, inReplyTo itemID: TimelineItemIdentifier?) async
|
||||
|
||||
func editMessage(_ newMessage: String, original itemID: TimelineItemIdentifier) async
|
||||
func editMessage(_ newMessage: String, html: String?, original itemID: TimelineItemIdentifier) async
|
||||
|
||||
func toggleReaction(_ reaction: String, to itemID: TimelineItemIdentifier) async
|
||||
|
||||
@@ -67,7 +67,7 @@ protocol RoomTimelineControllerProtocol {
|
||||
}
|
||||
|
||||
extension RoomTimelineControllerProtocol {
|
||||
func sendMessage(_ message: String) async {
|
||||
await sendMessage(message, inReplyTo: nil)
|
||||
func sendMessage(_ message: String, html: String?) async {
|
||||
await sendMessage(message, html: html, inReplyTo: nil)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user