events: Be a little smarter when removing plain reply fallback

Given that the default algorithm from the spec would also remove the
beginning of a message starting with a blockquote,
let's be more conservative an check that the beginning really looks like
the fallback that was defined in the spec.
This commit is contained in:
Kévin Commaille 2024-12-01 15:21:25 +01:00 committed by strawberry
parent f05d0e03a1
commit 81611b65f8

View File

@ -4,7 +4,10 @@
/// ///
/// [rich reply fallback]: https://spec.matrix.org/latest/client-server-api/#fallbacks-for-rich-replies /// [rich reply fallback]: https://spec.matrix.org/latest/client-server-api/#fallbacks-for-rich-replies
pub fn remove_plain_reply_fallback(mut s: &str) -> &str { pub fn remove_plain_reply_fallback(mut s: &str) -> &str {
if !s.starts_with("> ") { // A reply fallback must begin with a mention of the original sender between `<` and `>`, and
// emotes add `*` as a prefix. If there is no newline, removing the detected fallback would
// result in an empty string.
if (!s.starts_with("> <") && !s.starts_with("> * <")) || !s.contains('\n') {
return s; return s;
} }