Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nostrs: Add text-note dislike command
- Loading branch information
Showing
3 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters