events: Improve compatibility of generated and stripped plain reply fallback
This commit is contained in:
parent
9b694cdfa8
commit
e017e65277
@ -46,6 +46,8 @@ Improvements:
|
|||||||
- Stabilize support for annotations and reactions (MSC2677 / Matrix 1.7)
|
- Stabilize support for annotations and reactions (MSC2677 / Matrix 1.7)
|
||||||
- Add support for intentional mentions push rules (MSC3952 / Matrix 1.7)
|
- Add support for intentional mentions push rules (MSC3952 / Matrix 1.7)
|
||||||
- Stabilize support for VoIP signalling improvements (MSC2746 / Matrix 1.7)
|
- Stabilize support for VoIP signalling improvements (MSC2746 / Matrix 1.7)
|
||||||
|
- Make the generated and stripped plain text reply fallback behavior more compatible with most
|
||||||
|
of the Matrix ecosystem.
|
||||||
|
|
||||||
# 0.11.3
|
# 0.11.3
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ pub fn plain_and_formatted_reply_body(
|
|||||||
) -> (String, String) {
|
) -> (String, String) {
|
||||||
let (quoted, quoted_html) = get_message_quote_fallbacks(original_message);
|
let (quoted, quoted_html) = get_message_quote_fallbacks(original_message);
|
||||||
|
|
||||||
let plain = format!("{quoted}\n{body}");
|
let plain = format!("{quoted}\n\n{body}");
|
||||||
let html = match formatted {
|
let html = match formatted {
|
||||||
Some(formatted) => format!("{quoted_html}{formatted}"),
|
Some(formatted) => format!("{quoted_html}{formatted}"),
|
||||||
None => format!("{quoted_html}{}", EscapeHtmlEntities(body)),
|
None => format!("{quoted_html}{}", EscapeHtmlEntities(body)),
|
||||||
|
@ -71,6 +71,10 @@ pub fn remove_html_reply_fallback(s: &str) -> String {
|
|||||||
///
|
///
|
||||||
/// [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("> ") {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
while s.starts_with("> ") {
|
while s.starts_with("> ") {
|
||||||
if let Some((_line, rest)) = s.split_once('\n') {
|
if let Some((_line, rest)) = s.split_once('\n') {
|
||||||
s = rest;
|
s = rest;
|
||||||
@ -79,8 +83,13 @@ pub fn remove_plain_reply_fallback(mut s: &str) -> &str {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Strip the first line after the fallback if it is empty.
|
||||||
|
if let Some(rest) = s.strip_prefix('\n') {
|
||||||
|
rest
|
||||||
|
} else {
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
@ -194,16 +203,18 @@ mod tests {
|
|||||||
remove_plain_reply_fallback(
|
remove_plain_reply_fallback(
|
||||||
"> <@user:notareal.hs> Replied to on\n\
|
"> <@user:notareal.hs> Replied to on\n\
|
||||||
> two lines\n\
|
> two lines\n\
|
||||||
|
\n\
|
||||||
|
\n\
|
||||||
This is my reply"
|
This is my reply"
|
||||||
),
|
),
|
||||||
"This is my reply"
|
"\nThis is my reply"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(remove_plain_reply_fallback("\n> Not on first line"), "\n> Not on first line");
|
assert_eq!(remove_plain_reply_fallback("\n> Not on first line"), "\n> Not on first line");
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
remove_plain_reply_fallback("> <@user:notareal.hs> Previous message\n\n> New quote"),
|
remove_plain_reply_fallback("> <@user:notareal.hs> Previous message\n\n> New quote"),
|
||||||
"\n> New quote"
|
"> New quote"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -282,6 +282,7 @@ fn escape_tags_in_plain_reply_body() {
|
|||||||
body,
|
body,
|
||||||
"\
|
"\
|
||||||
> <@user:example.org> Usage: cp <source> <destination>\n\
|
> <@user:example.org> Usage: cp <source> <destination>\n\
|
||||||
|
\n\
|
||||||
Usage: rm <path>\
|
Usage: rm <path>\
|
||||||
"
|
"
|
||||||
);
|
);
|
||||||
@ -352,6 +353,7 @@ fn reply_sanitize() {
|
|||||||
body,
|
body,
|
||||||
"\
|
"\
|
||||||
> <@user:example.org> # This is the first message\n\
|
> <@user:example.org> # This is the first message\n\
|
||||||
|
\n\
|
||||||
This is the _second_ message\
|
This is the _second_ message\
|
||||||
"
|
"
|
||||||
);
|
);
|
||||||
@ -379,6 +381,7 @@ fn reply_sanitize() {
|
|||||||
body,
|
body,
|
||||||
"\
|
"\
|
||||||
> <@user:example.org> This is the _second_ message\n\
|
> <@user:example.org> This is the _second_ message\n\
|
||||||
|
\n\
|
||||||
This is **my** reply\
|
This is **my** reply\
|
||||||
"
|
"
|
||||||
);
|
);
|
||||||
@ -448,6 +451,7 @@ fn make_replacement_with_reply() {
|
|||||||
body,
|
body,
|
||||||
"\
|
"\
|
||||||
> <@user:example.org> # This is the first message\n\
|
> <@user:example.org> # This is the first message\n\
|
||||||
|
\n\
|
||||||
* This is _an edited_ reply.\
|
* This is _an edited_ reply.\
|
||||||
"
|
"
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user