mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-24 02:22:44 +02:00
created the replace formatted text function
This commit is contained in:
@@ -21,7 +21,7 @@ extension RoomDataSource {
|
||||
private enum Constants {
|
||||
static let emoteMessageSlashCommandPrefix = String(format: "%@ ", kMXKSlashCmdEmote)
|
||||
}
|
||||
|
||||
|
||||
// MARK: - NSAttributedString Sending
|
||||
/// Send a text message to the room.
|
||||
/// While sending, a fake event will be echoed in the messages list.
|
||||
@@ -33,7 +33,7 @@ extension RoomDataSource {
|
||||
func sendAttributedTextMessage(_ attributedText: NSAttributedString,
|
||||
completion: @escaping (MXResponse<String?>) -> Void) {
|
||||
var localEcho: MXEvent?
|
||||
|
||||
|
||||
let isEmote = isAttributedTextMessageAnEmote(attributedText)
|
||||
let sanitized = sanitizedAttributedMessageText(attributedText)
|
||||
let rawText: String
|
||||
@@ -43,7 +43,7 @@ extension RoomDataSource {
|
||||
} else {
|
||||
rawText = sanitized.string
|
||||
}
|
||||
|
||||
|
||||
if isEmote {
|
||||
room.sendEmote(rawText,
|
||||
formattedText: html,
|
||||
@@ -57,7 +57,7 @@ extension RoomDataSource {
|
||||
localEcho: &localEcho,
|
||||
completion: completion)
|
||||
}
|
||||
|
||||
|
||||
if localEcho != nil {
|
||||
self.queueEvent(forProcessing: localEcho, with: self.roomState, direction: .forwards)
|
||||
self.processQueuedEvents(nil)
|
||||
@@ -88,7 +88,7 @@ extension RoomDataSource {
|
||||
self.processQueuedEvents(nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Send a reply to an event with text message to the room.
|
||||
///
|
||||
/// While sending, a fake event will be echoed in the messages list.
|
||||
@@ -102,7 +102,7 @@ extension RoomDataSource {
|
||||
withAttributedTextMessage attributedText: NSAttributedString,
|
||||
completion: @escaping (MXResponse<String?>) -> Void) {
|
||||
var localEcho: MXEvent?
|
||||
|
||||
|
||||
let sanitized = sanitizedAttributedMessageText(attributedText)
|
||||
let rawText: String
|
||||
let html: String? = htmlMessageFromSanitizedAttributedText(sanitized)
|
||||
@@ -111,9 +111,9 @@ extension RoomDataSource {
|
||||
} else {
|
||||
rawText = sanitized.string
|
||||
}
|
||||
|
||||
|
||||
let stringLocalizer: MXSendReplyEventStringLocalizerProtocol = MXKSendReplyEventStringLocalizer()
|
||||
|
||||
|
||||
room.sendReply(to: eventToReply,
|
||||
textMessage: rawText,
|
||||
formattedTextMessage: html,
|
||||
@@ -121,13 +121,13 @@ extension RoomDataSource {
|
||||
threadId: self.threadId,
|
||||
localEcho: &localEcho,
|
||||
completion: completion)
|
||||
|
||||
|
||||
if localEcho != nil {
|
||||
self.queueEvent(forProcessing: localEcho, with: self.roomState, direction: .forwards)
|
||||
self.processQueuedEvents(nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Replace a text in an event.
|
||||
///
|
||||
/// - Parameters:
|
||||
@@ -147,10 +147,33 @@ extension RoomDataSource {
|
||||
} else {
|
||||
rawText = sanitized.string
|
||||
}
|
||||
|
||||
|
||||
handleReplaceFormattedMessage(for: event, rawText: rawText, html: html, success: success, failure: failure)
|
||||
}
|
||||
|
||||
/// Replace a formatted html text in an event
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - event: The event to replace
|
||||
/// - rawText: The new rawText
|
||||
/// - html: The new html text
|
||||
/// - success: A block object called when the operation succeeds. It returns the event id of the event generated on the homeserver
|
||||
/// - failure: A block object called when the operation fails
|
||||
func replaceFormattedTextMessage( for event: MXEvent,
|
||||
rawText: String,
|
||||
html: String,
|
||||
success: @escaping ((String?) -> Void),
|
||||
failure: @escaping ((Error?) -> Void)) {
|
||||
handleReplaceFormattedMessage(for: event, rawText: rawText, html: html, success: success, failure: failure)
|
||||
}
|
||||
|
||||
private func handleReplaceFormattedMessage( for event: MXEvent,
|
||||
rawText: String,
|
||||
html: String?,
|
||||
success: @escaping ((String?) -> Void),
|
||||
failure: @escaping ((Error?) -> Void)) {
|
||||
let eventBody = event.content[kMXMessageBodyKey] as? String
|
||||
let eventFormattedBody = event.content["formatted_body"] as? String
|
||||
|
||||
if rawText != eventBody && (eventFormattedBody == nil || html != eventFormattedBody) {
|
||||
self.mxSession.aggregations.replaceTextMessageEvent(
|
||||
event,
|
||||
@@ -159,7 +182,7 @@ extension RoomDataSource {
|
||||
localEcho: { localEcho in
|
||||
// Apply the local echo to the timeline
|
||||
self.updateEvent(withReplace: localEcho)
|
||||
|
||||
|
||||
// Integrate the replace local event into the timeline like when sending a message
|
||||
// This also allows to manage read receipt on this replace event
|
||||
self.queueEvent(forProcessing: localEcho, with: self.roomState, direction: .forwards)
|
||||
|
||||
Reference in New Issue
Block a user