Remove strip_rich_reply_fallback_text in favor of remove_plain_reply_fallback from ruma events

No need to reinvent the wheel.
This commit is contained in:
Slavi Pantaleev
2024-10-03 16:02:06 +03:00
parent a7b016a3d3
commit 393be9be5a
2 changed files with 3 additions and 35 deletions

View File

@@ -9,7 +9,8 @@ use mxlink::matrix_sdk::{
ruma::events::{
relation::Thread,
room::message::{
MessageType, OriginalSyncRoomMessageEvent, Relation, RoomMessageEventContent,
sanitize::remove_plain_reply_fallback, MessageType, OriginalSyncRoomMessageEvent,
Relation, RoomMessageEventContent,
},
AnyMessageLikeEvent, AnyMessageLikeEventContent, AnyTimelineEvent, MessageLikeEvent,
},
@@ -229,7 +230,7 @@ pub fn convert_matrix_native_event_to_matrix_message(
let text = if is_reply {
// For regular replies, we need to strip the fallback-for-rich replies part.
// See: https://spec.matrix.org/v1.11/client-server-api/#fallbacks-for-rich-replies
strip_rich_reply_fallback_text(&text)
remove_plain_reply_fallback(&text).to_owned()
} else {
text
};
@@ -453,32 +454,6 @@ fn is_event_mentioning_bot(
}
}
/// Strips the rich reply fallback text from the given text.
/// See: https://spec.matrix.org/v1.11/client-server-api/#fallbacks-for-rich-replies
///
/// Example:
/// ```rust,ignore
/// let text = "> <@admin:example.com> What's the difference between Matrix and XMPP?\n\nAnswer me";
/// let stripped_text = strip_rich_reply_fallback_text(text);
/// assert_eq!(stripped_text, "Answer me");
/// ```
fn strip_rich_reply_fallback_text(text: &str) -> String {
let lines = text.lines();
let mut stripped_lines = Vec::new();
let mut encountered_non_prefix = false;
for line in lines {
if !encountered_non_prefix && line.starts_with("> ") {
continue;
} else {
encountered_non_prefix = true;
stripped_lines.push(line);
}
}
stripped_lines.join("\n").trim().to_owned()
}
fn timeline_event_to_detailed_message_payload(
timeline_event_id: &OwnedEventId,
timeline_event: TimelineEvent,

View File

@@ -296,13 +296,6 @@ async fn process_matrix_messages() {
}
}
#[test]
fn strip_rich_reply_fallback_text() {
let text = "> <@admin:example.com> What's the difference between Matrix and XMPP?\n\nAnswer me";
let stripped_text = super::strip_rich_reply_fallback_text(text);
assert_eq!(stripped_text, "Answer me");
}
#[test]
fn create_list_of_bot_user_prefixes_to_strip() {
let bot_user_id =