add warning if calculated event id != requested event id

This commit is contained in:
Timo Kösters 2021-08-28 19:35:15 +02:00
parent afca61fe7c
commit 1601027605
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
3 changed files with 76 additions and 12 deletions

View file

@ -1544,6 +1544,66 @@ impl Rooms {
}
}
}
"parse_pdu" => {
if body.len() > 2
&& body[0].trim() == "```"
&& body.last().unwrap().trim() == "```"
{
let string = body[1..body.len() - 1].join("\n");
match serde_json::from_str(&string) {
Ok(value) => {
let event_id = EventId::try_from(&*format!(
"${}",
// Anything higher than version3 behaves the same
ruma::signatures::reference_hash(
&value,
&RoomVersionId::Version6
)
.expect("ruma can calculate reference hashes")
))
.expect(
"ruma's reference hashes are valid event ids",
);
match serde_json::from_value::<PduEvent>(
serde_json::to_value(value)
.expect("value is json"),
) {
Ok(pdu) => {
db.admin.send(AdminCommand::SendMessage(
message::MessageEventContent::text_plain(
format!("EventId: {:?}\n{:#?}", event_id, pdu),
),
));
}
Err(e) => {
db.admin.send(AdminCommand::SendMessage(
message::MessageEventContent::text_plain(
format!("EventId: {:?}\nCould not parse event: {}", event_id, e),
),
));
}
}
}
Err(e) => {
db.admin.send(AdminCommand::SendMessage(
message::MessageEventContent::text_plain(
format!(
"Invalid json in command body: {}",
e
),
),
));
}
}
} else {
db.admin.send(AdminCommand::SendMessage(
message::MessageEventContent::text_plain(
"Expected code block in command body.",
),
));
}
}
"get_pdu" => {
if args.len() == 1 {
if let Ok(event_id) = EventId::try_from(args[0]) {