management: listbannedevents2

This commit is contained in:
Mike Dilger 2025-02-27 12:16:27 +13:00
parent ad687598a0
commit 4e5d7ef9fe
No known key found for this signature in database
GPG Key ID: 47581A78D4329BA4

View File

@ -18,6 +18,13 @@ struct EventResult {
reason: Option<String>,
}
#[derive(Serialize)]
struct FullEventResult {
event: String,
#[serde(skip_serializing_if = "Option::is_none")]
reason: Option<String>,
}
#[derive(Serialize)]
struct PubkeyResult {
pubkey: String,
@ -128,6 +135,7 @@ pub fn handle_inner(pubkey: Pubkey, command: Value) -> Result<Option<Value>, Err
"listallowedevents",
"listbannedevents",
"listbannedevents2",
"listallowedpubkeys",
"listbannedpubkeys",
@ -283,6 +291,25 @@ pub fn handle_inner(pubkey: Pubkey, command: Value) -> Result<Option<Value>, Err
"result": ids
})))
}
"listbannedevents2" => {
let approvals = crate::dump_event_approvals(GLOBALS.store.get().unwrap())?;
let mut results: Vec<FullEventResult> = Vec::new();
for (id, appr) in approvals.iter() {
if ! *appr {
if let Some(event) = GLOBALS.store.get().unwrap().get_event_by_id(*id)? {
results.push(
FullEventResult {
event: format!("{event}"),
reason: None,
}
);
}
}
}
Ok(Some(json!({
"result": results
})))
}
"listallowedpubkeys" => {
let approvals = crate::dump_pubkey_approvals(GLOBALS.store.get().unwrap())?;
let pubkeys: Vec<PubkeyResult> = approvals