diff --git a/nostrs/src/handler/text_note.rs b/nostrs/src/handler/text_note.rs index 01ad1037..7cf9b580 100644 --- a/nostrs/src/handler/text_note.rs +++ b/nostrs/src/handler/text_note.rs @@ -1,9 +1,11 @@ mod create; mod delete; +mod dislike; mod like; mod list; pub use self::create::handle as create; pub use self::delete::handle as delete; +pub use self::dislike::handle as dislike; pub use self::like::handle as like; pub use self::list::handle as list; diff --git a/nostrs/src/handler/text_note/dislike.rs b/nostrs/src/handler/text_note/dislike.rs new file mode 100644 index 00000000..5dbfba66 --- /dev/null +++ b/nostrs/src/handler/text_note/dislike.rs @@ -0,0 +1,24 @@ +use std::time::Duration; + +use anyhow::bail; +use nostr_sdk::prelude::{EventId, Kind, SubscriptionFilter}; + +use crate::client::new_client; + +// NIP-25 +pub async fn handle(event_id: String) -> anyhow::Result<()> { + let event_id = EventId::from_hex(event_id)?; + let filter = SubscriptionFilter::new() + .kind(Kind::TextNote) + .id(event_id.to_hex()) + .limit(1); + let timeout = Duration::from_secs(10); + let client = new_client().await?; + let events = client.get_events_of(vec![filter], Some(timeout)).await?; + if events.is_empty() { + bail!("event ({event_id:?}) not found"); + } + let public_key = events[0].pubkey; + client.dislike(event_id, public_key).await?; + Ok(()) +} diff --git a/nostrs/src/main.rs b/nostrs/src/main.rs index cfdd6583..75fb2cf9 100644 --- a/nostrs/src/main.rs +++ b/nostrs/src/main.rs @@ -75,6 +75,8 @@ enum TextNoteCommand { Create { content: String }, /// Delete the note Delete { event_id: String }, + /// Dislike the note + Dislike { event_id: String }, /// Like the note Like { event_id: String }, /// List notes @@ -98,6 +100,7 @@ async fn main() -> anyhow::Result<()> { Resource::TextNote { command } => match command { TextNoteCommand::Create { content } => handler::text_note::create(content).await, TextNoteCommand::Delete { event_id } => handler::text_note::delete(event_id).await, + TextNoteCommand::Dislike { event_id } => handler::text_note::dislike(event_id).await, TextNoteCommand::Like { event_id } => handler::text_note::like(event_id).await, TextNoteCommand::List => handler::text_note::list().await, },