Skip to content

Commit

Permalink
nostr: Update EventBuilder::request_vanish{_with_reason,} to takes …
Browse files Browse the repository at this point in the history
…`VanishTarget`

Signed-off-by: Awiteb <a@4rs.nl>
  • Loading branch information
TheAwiteb committed Feb 20, 2025
1 parent 2920a7b commit bcb627b
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions crates/nostr/src/event/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use serde_json::{json, Value};

#[cfg(all(feature = "std", feature = "nip04", feature = "nip46"))]
use crate::nips::nip46::Message as NostrConnectMessage;
use crate::nips::nip62::VanishTarget;
use crate::prelude::*;

/// Wrong kind error
Expand Down Expand Up @@ -732,23 +733,11 @@ impl EventBuilder {
/// Must include at least one relay.
///
/// <https://github.com/nostr-protocol/nips/blob/master/62.md>
pub fn request_vanish_with_reason<I, S>(relays: I, reason: S) -> Result<Self, Error>
pub fn request_vanish_with_reason<S>(vanish_target: VanishTarget, reason: S) -> Self
where
I: IntoIterator<Item = RelayUrl>,
S: Into<String>,
{
let tags: Vec<_> = relays
.into_iter()
.map(TagStandard::Relay)
.map(Tag::from_standardized)
.collect();

if tags.is_empty() {
// FIXME(awiteb): Return a valid error, where there is must be at lest one relay
return Err(Error::Event(event::Error::InvalidId));
}

Ok(Self::new(Kind::RequestToVanish, reason).tags(tags))
Self::new(Kind::RequestToVanish, reason).tags(Tags::from(vanish_target))
}

/// Request to vanish
Expand All @@ -757,11 +746,8 @@ impl EventBuilder {
///
/// <https://github.com/nostr-protocol/nips/blob/master/62.md>
#[inline]
pub fn request_vanish<I>(relays: I) -> Result<Self, Error>
where
I: IntoIterator<Item = RelayUrl>,
{
Self::request_vanish_with_reason(relays, "")
pub fn request_vanish<I>(vanish_target: VanishTarget) -> Self {
Self::request_vanish_with_reason(vanish_target, "")
}

/// Add reaction (like/upvote, dislike/downvote or emoji) to an event
Expand Down

0 comments on commit bcb627b

Please sign in to comment.