use codeblocks instead of HTML tables for some admin commands

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-09-01 00:44:22 -04:00
parent 2fcedad2b1
commit fc1834d629
2 changed files with 8 additions and 44 deletions

View file

@ -1,9 +1,7 @@
use std::fmt::Write;
use conduit::Result;
use ruma::events::room::message::RoomMessageEventContent;
use crate::{admin_command, escape_html, get_room_info, PAGE_SIZE};
use crate::{admin_command, get_room_info, PAGE_SIZE};
#[admin_command]
pub(super) async fn list_rooms(
@ -61,29 +59,14 @@ pub(super) async fn list_rooms(
};
let output_plain = format!(
"Rooms:\n{}",
"Rooms ({}):\n```\n{}\n```",
rooms.len(),
rooms
.iter()
.map(|(id, members, name)| format!("{id}\tMembers: {members}\tName: {name}"))
.collect::<Vec<_>>()
.join("\n")
);
let output_html = format!(
"<table><caption>Room list - page \
{page}</caption>\n<tr><th>id</th>\t<th>members</th>\t<th>name</th></tr>\n{}</table>",
rooms
.iter()
.fold(String::new(), |mut output, (id, members, name)| {
writeln!(
output,
"<tr><td>{}</td>\t<td>{}</td>\t<td>{}</td></tr>",
escape_html(id.as_ref()),
members,
escape_html(name)
)
.expect("should be able to write to string buffer");
output
})
);
Ok(RoomMessageEventContent::text_html(output_plain, output_html))
Ok(RoomMessageEventContent::notice_markdown(output_plain))
}

View file

@ -13,7 +13,7 @@ use ruma::{
use serde_json::value::to_raw_value;
use crate::{
admin_command, escape_html, get_room_info,
admin_command, get_room_info,
utils::{parse_active_local_user_id, parse_local_user_id},
};
@ -320,7 +320,7 @@ pub(super) async fn list_joined_rooms(&self, user_id: String) -> Result<RoomMess
rooms.reverse();
let output_plain = format!(
"Rooms {user_id} Joined ({}):\n{}",
"Rooms {user_id} Joined ({}):\n```\n{}\n```",
rooms.len(),
rooms
.iter()
@ -329,26 +329,7 @@ pub(super) async fn list_joined_rooms(&self, user_id: String) -> Result<RoomMess
.join("\n")
);
let output_html = format!(
"<table><caption>Rooms {user_id} Joined \
({})</caption>\n<tr><th>id</th>\t<th>members</th>\t<th>name</th></tr>\n{}</table>",
rooms.len(),
rooms
.iter()
.fold(String::new(), |mut output, (id, members, name)| {
writeln!(
output,
"<tr><td>{}</td>\t<td>{}</td>\t<td>{}</td></tr>",
escape_html(id.as_ref()),
members,
escape_html(name)
)
.unwrap();
output
})
);
Ok(RoomMessageEventContent::text_html(output_plain, output_html))
Ok(RoomMessageEventContent::notice_markdown(output_plain))
}
#[admin_command]