filter: add protected_events filter
This adds support for protected events Link: https://github.com/nostr-protocol/nips/pull/1030 Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
parent
20a8773631
commit
e28454ac32
7 changed files with 55 additions and 4 deletions
|
|
@ -1,5 +1,7 @@
|
|||
mod protected_events;
|
||||
mod ratelimit;
|
||||
mod whitelist;
|
||||
|
||||
pub use protected_events::ProtectedEvents;
|
||||
pub use ratelimit::RateLimit;
|
||||
pub use whitelist::Whitelist;
|
||||
|
|
|
|||
29
src/filters/protected_events.rs
Normal file
29
src/filters/protected_events.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
use crate::{Action, InputMessage, NoteFilter, OutputMessage};
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Deserialize, Default)]
|
||||
pub struct ProtectedEvents {}
|
||||
|
||||
impl NoteFilter for ProtectedEvents {
|
||||
fn filter_note(&mut self, input: &InputMessage) -> OutputMessage {
|
||||
for tag in &input.event.tags {
|
||||
for entry in tag {
|
||||
if entry == "-" {
|
||||
return OutputMessage::new(
|
||||
input.event.id.clone(),
|
||||
Action::Reject,
|
||||
Some("blocked: event marked as protected".to_string()),
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
OutputMessage::new(input.event.id.clone(), Action::Accept, None)
|
||||
}
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
"protected_events"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
use noteguard::filters::{RateLimit, Whitelist};
|
||||
use noteguard::filters::{ProtectedEvents, RateLimit, Whitelist};
|
||||
use noteguard::{Action, InputMessage, NoteFilter, OutputMessage};
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::Deserialize;
|
||||
|
|
@ -42,6 +42,7 @@ impl Noteguard {
|
|||
fn register_builtin_filters(&mut self) {
|
||||
self.register_filter::<RateLimit>();
|
||||
self.register_filter::<Whitelist>();
|
||||
self.register_filter::<ProtectedEvents>();
|
||||
}
|
||||
|
||||
/// Run the loaded filters. You must call `load_config` before calling this, otherwise
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue