events: Don't send pretty-printed HTML fallback in replies

This commit is contained in:
Kévin Commaille 2022-06-01 10:27:20 +02:00 committed by Kévin Commaille
parent 3c507afc90
commit 806d389e13
2 changed files with 23 additions and 17 deletions

View File

@ -23,7 +23,7 @@ server = []
api = ["http", "thiserror"]
compat = ["ruma-macros/compat", "ruma-identifiers-validation/compat"]
events = ["indoc", "thiserror"]
events = ["thiserror"]
# TODO: Use weak dependency features once MSRV >= 1.60
js = ["js-sys", "getrandom/js", "uuid/js"]
markdown = ["pulldown-cmark"]
@ -56,7 +56,6 @@ form_urlencoded = "1.0.0"
getrandom = { version = "0.2.6", optional = true }
http = { version = "0.2.2", optional = true }
indexmap = { version = "1.6.2", features = ["serde-1"] }
indoc = { version = "1.0", optional = true }
itoa = "1.0.1"
js_int = { version = "0.2.0", features = ["serde"] }
js_option = "0.1.0"

View File

@ -1,7 +1,5 @@
use std::fmt;
use indoc::formatdoc;
use super::{FormattedBody, MessageType, OriginalRoomMessageEvent};
pub fn get_message_quote_fallbacks(
@ -44,17 +42,15 @@ fn get_quotes(
(
format!("> {emote_sign}<{sender}> {body}").replace('\n', "\n> "),
formatdoc!(
"
<mx-reply>
<blockquote>
<a href=\"https://matrix.to/#/{room_id}/{event_id}\">In reply to</a>
{emote_sign}<a href=\"https://matrix.to/#/{sender}\">{sender}</a>
<br>
{html_body}
</blockquote>
</mx-reply>
"
format!(
"<mx-reply>\
<blockquote>\
<a href=\"https://matrix.to/#/{room_id}/{event_id}\">In reply to</a> \
{emote_sign}<a href=\"https://matrix.to/#/{sender}\">{sender}</a>\
<br>\
{html_body}\
</blockquote>\
</mx-reply>"
),
)
}
@ -98,8 +94,8 @@ mod tests {
use super::OriginalRoomMessageEvent;
#[test]
fn plain_quote_fallback_multiline() {
let (plain_quote, _html_quote) =
fn fallback_multiline() {
let (plain_quote, html_quote) =
super::get_message_quote_fallbacks(&OriginalRoomMessageEvent {
content: RoomMessageEventContent::text_plain("multi\nline"),
event_id: event_id!("$1598361704261elfgc:localhost").to_owned(),
@ -110,5 +106,16 @@ mod tests {
});
assert_eq!(plain_quote, "> <@alice:example.com> multi\n> line");
assert_eq!(
html_quote,
"<mx-reply>\
<blockquote>\
<a href=\"https://matrix.to/#/!n8f893n9:example.com/$1598361704261elfgc:localhost\">In reply to</a> \
<a href=\"https://matrix.to/#/@alice:example.com\">@alice:example.com</a>\
<br>\
multi\nline\
</blockquote>\
</mx-reply>"
);
}
}