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:
@@ -9,7 +9,8 @@ use mxlink::matrix_sdk::{
|
|||||||
ruma::events::{
|
ruma::events::{
|
||||||
relation::Thread,
|
relation::Thread,
|
||||||
room::message::{
|
room::message::{
|
||||||
MessageType, OriginalSyncRoomMessageEvent, Relation, RoomMessageEventContent,
|
sanitize::remove_plain_reply_fallback, MessageType, OriginalSyncRoomMessageEvent,
|
||||||
|
Relation, RoomMessageEventContent,
|
||||||
},
|
},
|
||||||
AnyMessageLikeEvent, AnyMessageLikeEventContent, AnyTimelineEvent, MessageLikeEvent,
|
AnyMessageLikeEvent, AnyMessageLikeEventContent, AnyTimelineEvent, MessageLikeEvent,
|
||||||
},
|
},
|
||||||
@@ -229,7 +230,7 @@ pub fn convert_matrix_native_event_to_matrix_message(
|
|||||||
let text = if is_reply {
|
let text = if is_reply {
|
||||||
// For regular replies, we need to strip the fallback-for-rich replies part.
|
// 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
|
// 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 {
|
} else {
|
||||||
text
|
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(
|
fn timeline_event_to_detailed_message_payload(
|
||||||
timeline_event_id: &OwnedEventId,
|
timeline_event_id: &OwnedEventId,
|
||||||
timeline_event: TimelineEvent,
|
timeline_event: TimelineEvent,
|
||||||
|
|||||||
@@ -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]
|
#[test]
|
||||||
fn create_list_of_bot_user_prefixes_to_strip() {
|
fn create_list_of_bot_user_prefixes_to_strip() {
|
||||||
let bot_user_id =
|
let bot_user_id =
|
||||||
|
|||||||
Reference in New Issue
Block a user