diff --git a/src/admin/appservice/commands.rs b/src/admin/appservice/commands.rs index 5b764296..5cce8351 100644 --- a/src/admin/appservice/commands.rs +++ b/src/admin/appservice/commands.rs @@ -1,6 +1,6 @@ use ruma::{api::appservice::Registration, events::room::message::RoomMessageEventContent}; -use crate::{escape_html, services, Result}; +use crate::{services, Result}; pub(super) async fn register(body: Vec<&str>) -> Result { if body.len() < 2 || !body[0].trim().starts_with("```") || body.last().unwrap_or(&"").trim() != "```" { @@ -48,12 +48,7 @@ pub(super) async fn show(_body: Vec<&str>, appservice_identifier: String) -> Res Some(config) => { let config_str = serde_yaml::to_string(&config).expect("config should've been validated on register"); let output = format!("Config for {appservice_identifier}:\n\n```yaml\n{config_str}\n```",); - let output_html = format!( - "Config for {}:\n\n
{}
", - escape_html(&appservice_identifier), - escape_html(&config_str), - ); - Ok(RoomMessageEventContent::text_html(output, output_html)) + Ok(RoomMessageEventContent::notice_markdown(output)) }, None => Ok(RoomMessageEventContent::text_plain("Appservice does not exist.")), } diff --git a/src/admin/debug/commands.rs b/src/admin/debug/commands.rs index 0409af32..40aa0278 100644 --- a/src/admin/debug/commands.rs +++ b/src/admin/debug/commands.rs @@ -8,7 +8,6 @@ use api::client::validate_and_add_event_id; use conduit::{ debug, info, log, log::{capture, Capture}, - utils::HtmlEscape, warn, Error, Result, }; use ruma::{ @@ -93,26 +92,15 @@ pub(super) async fn get_pdu(_body: Vec<&str>, event_id: Box) -> Result< match pdu_json { Some(json) => { let json_text = serde_json::to_string_pretty(&json).expect("canonical json is valid json"); - Ok(RoomMessageEventContent::text_html( - format!( - "{}\n```json\n{}\n```", - if outlier { - "Outlier PDU found in our database" - } else { - "PDU found in our database" - }, - json_text - ), - format!( - "

{}

\n
{}\n
\n", - if outlier { - "Outlier PDU found in our database" - } else { - "PDU found in our database" - }, - HtmlEscape(&json_text) - ), - )) + Ok(RoomMessageEventContent::notice_markdown(format!( + "{}\n```json\n{}\n```", + if outlier { + "Outlier PDU found in our database" + } else { + "PDU found in our database" + }, + json_text + ))) }, None => Ok(RoomMessageEventContent::text_plain("PDU not found locally.")), } @@ -237,17 +225,10 @@ pub(super) async fn get_remote_pdu( let json_text = serde_json::to_string_pretty(&json).expect("canonical json is valid json"); - Ok(RoomMessageEventContent::text_html( - format!( - "{}\n```json\n{}\n```", - "Got PDU from specified server and handled as backfilled PDU successfully. Event body:", json_text - ), - format!( - "

{}

\n
{}\n
\n", - "Got PDU from specified server and handled as backfilled PDU successfully. Event body:", - HtmlEscape(&json_text) - ), - )) + Ok(RoomMessageEventContent::notice_markdown(format!( + "{}\n```json\n{}\n```", + "Got PDU from specified server and handled as backfilled PDU successfully. Event body:", json_text + ))) }, Err(e) => Ok(RoomMessageEventContent::text_plain(format!( "Remote server did not have PDU or failed sending request to remote server: {e}" @@ -278,14 +259,10 @@ pub(super) async fn get_room_state(_body: Vec<&str>, room_id: Box) -> Re ) })?; - Ok(RoomMessageEventContent::text_html( - format!("{}\n```json\n{}\n```", "Found full room state", json_text), - format!( - "

{}

\n
{}\n
\n", - "Found full room state", - HtmlEscape(&json_text) - ), - )) + Ok(RoomMessageEventContent::notice_markdown(format!( + "{}\n```json\n{}\n```", + "Found full room state", json_text + ))) } pub(super) async fn ping(_body: Vec<&str>, server: Box) -> Result { @@ -308,14 +285,9 @@ pub(super) async fn ping(_body: Vec<&str>, server: Box) -> ResultGot response which took {ping_time:?} time:

\n
{}\n
\n", - HtmlEscape(&json) - ), - )); + return Ok(RoomMessageEventContent::notice_markdown(format!( + "Got response which took {ping_time:?} time:\n```json\n{json}\n```" + ))); } Ok(RoomMessageEventContent::text_plain(format!( diff --git a/src/admin/federation/commands.rs b/src/admin/federation/commands.rs index 4084350d..293efdc5 100644 --- a/src/admin/federation/commands.rs +++ b/src/admin/federation/commands.rs @@ -2,7 +2,7 @@ use std::fmt::Write; use ruma::{events::room::message::RoomMessageEventContent, OwnedRoomId, RoomId, ServerName, UserId}; -use crate::{escape_html, get_room_info, services, utils::HtmlEscape, Result}; +use crate::{escape_html, get_room_info, services, Result}; pub(super) async fn disable_room(_body: Vec<&str>, room_id: Box) -> Result { services().rooms.metadata.disable_room(&room_id, true)?; @@ -63,13 +63,9 @@ pub(super) async fn fetch_support_well_known( }, }; - Ok(RoomMessageEventContent::text_html( - format!("Got JSON response:\n\n```json\n{pretty_json}\n```"), - format!( - "

Got JSON response:

\n
{}\n
\n", - HtmlEscape(&pretty_json) - ), - )) + Ok(RoomMessageEventContent::notice_markdown(format!( + "Got JSON response:\n\n```json\n{pretty_json}\n```" + ))) } pub(super) async fn remote_user_in_rooms(_body: Vec<&str>, user_id: Box) -> Result { diff --git a/src/admin/fsck/commands.rs b/src/admin/fsck/commands.rs index 9fb0281a..f3a2972a 100644 --- a/src/admin/fsck/commands.rs +++ b/src/admin/fsck/commands.rs @@ -22,5 +22,5 @@ pub(super) async fn check_all_users(_body: Vec<&str>) -> Result RoomMessageEventContent { Ok(reply_message) => reply_message, Err(error) => { let markdown_message = format!("Encountered an error while handling the command:\n```\n{error}\n```",); - let html_message = format!("Encountered an error while handling the command:\n
\n{error}\n
",); - - RoomMessageEventContent::text_html(markdown_message, html_message) + RoomMessageEventContent::notice_markdown(markdown_message) }, } } diff --git a/src/admin/room/room_info_commands.rs b/src/admin/room/room_info_commands.rs index 3b35d82c..d985fb87 100644 --- a/src/admin/room/room_info_commands.rs +++ b/src/admin/room/room_info_commands.rs @@ -1,10 +1,8 @@ -use std::fmt::Write; - use ruma::{events::room::message::RoomMessageEventContent, RoomId}; use service::services; use super::RoomInfoCommand; -use crate::{escape_html, Result}; +use crate::Result; pub(super) async fn process(command: RoomInfoCommand, body: Vec<&str>) -> Result { match command { @@ -57,26 +55,7 @@ async fn list_joined_members(_body: Vec<&str>, room_id: Box) -> Result{} Members in Room \"{}\" \nMXID\tDisplay \ - Name\n{}", - member_info.len(), - room_name, - member_info - .iter() - .fold(String::new(), |mut output, (mxid, displayname)| { - writeln!( - output, - "{}\t{}", - mxid, - escape_html(displayname.as_ref()) - ) - .expect("should be able to write to string buffer"); - output - }) - ); - - Ok(RoomMessageEventContent::text_html(output_plain, output_html)) + Ok(RoomMessageEventContent::notice_markdown(output_plain)) } async fn view_room_topic(_body: Vec<&str>, room_id: Box) -> Result { @@ -84,10 +63,7 @@ async fn view_room_topic(_body: Vec<&str>, room_id: Box) -> ResultRoom topic:

\n
\n{}
", escape_html(&room_topic)); - - Ok(RoomMessageEventContent::text_html( - format!("Room topic:\n\n```{room_topic}\n```"), - output_html, - )) + Ok(RoomMessageEventContent::notice_markdown(format!( + "Room topic:\n\n```{room_topic}\n```" + ))) } diff --git a/src/admin/room/room_moderation_commands.rs b/src/admin/room/room_moderation_commands.rs index 095ccf61..75a20584 100644 --- a/src/admin/room/room_moderation_commands.rs +++ b/src/admin/room/room_moderation_commands.rs @@ -1,5 +1,3 @@ -use std::fmt::Write; - use api::client::{get_alias_helper, leave_room}; use ruma::{ events::room::message::RoomMessageEventContent, OwnedRoomId, OwnedUserId, RoomAliasId, RoomId, RoomOrAliasId, @@ -7,7 +5,7 @@ use ruma::{ use tracing::{debug, error, info, warn}; use super::{super::Service, RoomModerationCommand}; -use crate::{escape_html, get_room_info, services, user_is_local, Result}; +use crate::{get_room_info, services, user_is_local, Result}; pub(super) async fn process(command: RoomModerationCommand, body: Vec<&str>) -> Result { match command { @@ -492,26 +490,7 @@ async fn list_banned_rooms(_body: Vec<&str>) -> Result .join("\n") ); - let output_html = format!( - "\n\t\t\n{}
Rooms Banned ({}) \ -
idmembersname
", - rooms.len(), - rooms - .iter() - .fold(String::new(), |mut output, (id, members, name)| { - writeln!( - output, - "{}\t{}\t{}", - id, - members, - escape_html(name.as_ref()) - ) - .expect("should be able to write to string buffer"); - output - }) - ); - - Ok(RoomMessageEventContent::text_html(output_plain, output_html)) + Ok(RoomMessageEventContent::notice_markdown(output_plain)) }, Err(e) => { error!("Failed to list banned rooms: {}", e); diff --git a/src/admin/user/commands.rs b/src/admin/user/commands.rs index 26ec1af5..6dc60713 100644 --- a/src/admin/user/commands.rs +++ b/src/admin/user/commands.rs @@ -26,10 +26,7 @@ pub(super) async fn list(_body: Vec<&str>) -> Result { plain_msg += &users.join("\n"); plain_msg += "\n```"; - let mut html_msg = format!("

Found {} local user account(s):

", users.len());
-			html_msg += &users.join("\n");
-			html_msg += "\n
"; - Ok(RoomMessageEventContent::text_html(&plain_msg, &html_msg)) + Ok(RoomMessageEventContent::notice_markdown(plain_msg)) }, Err(e) => Ok(RoomMessageEventContent::text_plain(e.to_string())), } @@ -419,8 +416,8 @@ pub(super) async fn get_room_tags( |e| serde_json::from_str(e.get()).expect("Bad account data in database for user {user_id}"), ); - Ok(RoomMessageEventContent::text_html( - format!("
\n{:?}\n
", tags_event.content.tags), - format!("```\n{:?}\n```", tags_event.content.tags), - )) + Ok(RoomMessageEventContent::notice_markdown(format!( + "```\n{:#?}\n```", + tags_event.content.tags + ))) } diff --git a/src/admin/utils.rs b/src/admin/utils.rs index 4c30e5a8..91982fe3 100644 --- a/src/admin/utils.rs +++ b/src/admin/utils.rs @@ -1,4 +1,3 @@ -pub(crate) use conduit::utils::HtmlEscape; use conduit_core::Error; use ruma::{OwnedRoomId, OwnedUserId, RoomId, UserId}; use service::user_is_local;