Skip to content

Commit

Permalink
nostrs: Add text-note dislike command
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Feb 26, 2023
1 parent 6e9301c commit 2d16ac0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions 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;
24 changes: 24 additions & 0 deletions 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 <https://github.com/nostr-protocol/nips/blob/master/25.md>
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(())
}
3 changes: 3 additions & 0 deletions nostrs/src/main.rs
Expand Up @@ -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
Expand All @@ -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,
},
Expand Down

0 comments on commit 2d16ac0

Please sign in to comment.