mirror of
https://github.com/mikedilger/chorus.git
synced 2026-08-31 07:31:01 +00:00
Deal with event/pubkey approvals in event screens (in and out)
This commit is contained in:
parent
9c3d35666b
commit
15bb8c23c1
@ -215,6 +215,18 @@ impl WebSocketService {
|
||||
PERSONAL_MSG.to_owned(),
|
||||
)
|
||||
}
|
||||
ChorusError::BannedEvent => NostrReply::Ok(
|
||||
id,
|
||||
false,
|
||||
NostrReplyPrefix::Blocked,
|
||||
"Event has been banned".to_string(),
|
||||
),
|
||||
ChorusError::BannedUser => NostrReply::Ok(
|
||||
id,
|
||||
false,
|
||||
NostrReplyPrefix::Blocked,
|
||||
"Author has been banned".to_string(),
|
||||
),
|
||||
_ => NostrReply::Ok(id, false, NostrReplyPrefix::Error, format!("{}", e)),
|
||||
};
|
||||
self.websocket.send(Message::text(reply.as_json())).await?;
|
||||
@ -393,6 +405,26 @@ async fn screen_incoming_event(
|
||||
event_flags: EventFlags,
|
||||
authorized_user: bool,
|
||||
) -> Result<bool, Error> {
|
||||
// Reject if event approval is false
|
||||
if let Some(false) = GLOBALS
|
||||
.store
|
||||
.get()
|
||||
.unwrap()
|
||||
.get_event_approval(event.id())?
|
||||
{
|
||||
return Err(ChorusError::BannedEvent.into());
|
||||
}
|
||||
|
||||
// Reject if pubkey approval is false
|
||||
if let Some(false) = GLOBALS
|
||||
.store
|
||||
.get()
|
||||
.unwrap()
|
||||
.get_pubkey_approval(event.pubkey())?
|
||||
{
|
||||
return Err(ChorusError::BannedUser.into());
|
||||
}
|
||||
|
||||
// If the event has a '-' tag, require the user to be AUTHed and match
|
||||
// the event author
|
||||
for mut tag in event.tags()?.iter() {
|
||||
@ -481,6 +513,21 @@ pub fn screen_outgoing_event(
|
||||
return true;
|
||||
}
|
||||
|
||||
// Allow if event is explicitly approved
|
||||
if let Ok(Some(true)) = GLOBALS.store.get().unwrap().get_event_approval(event.id()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Allow if author is explicitly approved
|
||||
if let Ok(Some(true)) = GLOBALS
|
||||
.store
|
||||
.get()
|
||||
.unwrap()
|
||||
.get_pubkey_approval(event.pubkey())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Do not allow the rest
|
||||
false
|
||||
}
|
||||
|
||||
@ -34,6 +34,12 @@ pub enum ChorusError {
|
||||
// Bad hex input
|
||||
BadHexInput,
|
||||
|
||||
// Event is banned
|
||||
BannedEvent,
|
||||
|
||||
// User is banned
|
||||
BannedUser,
|
||||
|
||||
// Output buffer too small
|
||||
BufferTooSmall,
|
||||
|
||||
@ -147,6 +153,8 @@ impl std::fmt::Display for ChorusError {
|
||||
ChorusError::AuthRequired => write!(f, "AUTH required"),
|
||||
ChorusError::BadEventId => write!(f, "Bad event id, does not match hash"),
|
||||
ChorusError::BadHexInput => write!(f, "Bad hex input"),
|
||||
ChorusError::BannedEvent => write!(f, "Event is banned"),
|
||||
ChorusError::BannedUser => write!(f, "User is banned"),
|
||||
ChorusError::BufferTooSmall => write!(f, "Output buffer too small"),
|
||||
ChorusError::ChannelRecv(e) => write!(f, "{e}"),
|
||||
ChorusError::ChannelSend(e) => write!(f, "{e}"),
|
||||
@ -227,6 +235,8 @@ impl ChorusError {
|
||||
ChorusError::AuthRequired => 0.0,
|
||||
ChorusError::BadEventId => 0.1,
|
||||
ChorusError::BadHexInput => 0.4,
|
||||
ChorusError::BannedEvent => 0.1,
|
||||
ChorusError::BannedUser => 0.2,
|
||||
ChorusError::BufferTooSmall => 0.0,
|
||||
ChorusError::ChannelRecv(_) => 0.0,
|
||||
ChorusError::ChannelSend(_) => 0.0,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user