mirror of
https://github.com/mikedilger/chorus.git
synced 2026-08-31 07:31:01 +00:00
nip86: fix output of some commands to be array of objects with keys
This commit is contained in:
parent
1eb74885aa
commit
7b988d820d
@ -12,9 +12,17 @@ use serde_json::{json, Map, Value};
|
|||||||
mod auth;
|
mod auth;
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct EventNeedingModeration {
|
struct EventResult {
|
||||||
id: String,
|
id: String,
|
||||||
reason: String,
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
reason: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct PubkeyResult {
|
||||||
|
pubkey: String,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
reason: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn respond(
|
fn respond(
|
||||||
@ -166,7 +174,7 @@ pub fn handle_inner(pubkey: Pubkey, command: Value) -> Result<Option<Value>, Err
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut need_moderation: Vec<EventNeedingModeration> = Vec::new();
|
let mut need_moderation: Vec<EventResult> = Vec::new();
|
||||||
|
|
||||||
let (mut events, _redacted) = GLOBALS
|
let (mut events, _redacted) = GLOBALS
|
||||||
.store
|
.store
|
||||||
@ -191,9 +199,9 @@ pub fn handle_inner(pubkey: Pubkey, command: Value) -> Result<Option<Value>, Err
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
need_moderation.push(EventNeedingModeration {
|
need_moderation.push(EventResult {
|
||||||
id: event.id().as_hex_string(),
|
id: event.id().as_hex_string(),
|
||||||
reason: "unmoderated".to_string(),
|
reason: Some("unmoderated".to_string()),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,11 +248,14 @@ pub fn handle_inner(pubkey: Pubkey, command: Value) -> Result<Option<Value>, Err
|
|||||||
|
|
||||||
"listallowedevents" => {
|
"listallowedevents" => {
|
||||||
let approvals = crate::dump_event_approvals(GLOBALS.store.get().unwrap())?;
|
let approvals = crate::dump_event_approvals(GLOBALS.store.get().unwrap())?;
|
||||||
let ids: Vec<String> = approvals
|
let ids: Vec<EventResult> = approvals
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(id, appr)| {
|
.filter_map(|(id, appr)| {
|
||||||
if *appr {
|
if *appr {
|
||||||
Some(id.as_hex_string())
|
Some(EventResult {
|
||||||
|
id: id.as_hex_string(),
|
||||||
|
reason: None,
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@ -256,13 +267,16 @@ pub fn handle_inner(pubkey: Pubkey, command: Value) -> Result<Option<Value>, Err
|
|||||||
}
|
}
|
||||||
"listbannedevents" => {
|
"listbannedevents" => {
|
||||||
let approvals = crate::dump_event_approvals(GLOBALS.store.get().unwrap())?;
|
let approvals = crate::dump_event_approvals(GLOBALS.store.get().unwrap())?;
|
||||||
let ids: Vec<String> = approvals
|
let ids: Vec<EventResult> = approvals
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(id, appr)| {
|
.filter_map(|(id, appr)| {
|
||||||
if *appr {
|
if *appr {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(id.as_hex_string())
|
Some(EventResult {
|
||||||
|
id: id.as_hex_string(),
|
||||||
|
reason: None,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
@ -272,11 +286,14 @@ pub fn handle_inner(pubkey: Pubkey, command: Value) -> Result<Option<Value>, Err
|
|||||||
}
|
}
|
||||||
"listallowedpubkeys" => {
|
"listallowedpubkeys" => {
|
||||||
let approvals = crate::dump_pubkey_approvals(GLOBALS.store.get().unwrap())?;
|
let approvals = crate::dump_pubkey_approvals(GLOBALS.store.get().unwrap())?;
|
||||||
let pubkeys: Vec<String> = approvals
|
let pubkeys: Vec<PubkeyResult> = approvals
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(pk, appr)| {
|
.filter_map(|(pk, appr)| {
|
||||||
if *appr {
|
if *appr {
|
||||||
Some(pk.as_hex_string())
|
Some(PubkeyResult {
|
||||||
|
pubkey: pk.as_hex_string(),
|
||||||
|
reason: None,
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@ -288,13 +305,16 @@ pub fn handle_inner(pubkey: Pubkey, command: Value) -> Result<Option<Value>, Err
|
|||||||
}
|
}
|
||||||
"listbannedpubkeys" => {
|
"listbannedpubkeys" => {
|
||||||
let approvals = crate::dump_pubkey_approvals(GLOBALS.store.get().unwrap())?;
|
let approvals = crate::dump_pubkey_approvals(GLOBALS.store.get().unwrap())?;
|
||||||
let pubkeys: Vec<String> = approvals
|
let pubkeys: Vec<PubkeyResult> = approvals
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(pk, appr)| {
|
.filter_map(|(pk, appr)| {
|
||||||
if *appr {
|
if *appr {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(pk.as_hex_string())
|
Some(PubkeyResult {
|
||||||
|
pubkey: pk.as_hex_string(),
|
||||||
|
reason: None,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user