diff --git a/CHANGELOG.md b/CHANGELOG.md index 0905e79b2..6b56159ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -85,6 +85,7 @@ * nostr: add `NostrSigner::backend` ([Yuki Kishimoto]) * nostr: add `EventBuilder::private_msg` ([Yuki Kishimoto]) * nostr: add `EventBuilder::tag` and `EventBuilder::tags` ([Yuki Kishimoto]) +* nostr: add `nip17::extract_relay_list` and `nip17::extract_owned_relay_list` ([Yuki Kishimoto]) * database: add `NostrEventsDatabase` trait ([Yuki Kishimoto]) * pool: add relay reconnection and disconnection unit tests ([Yuki Kishimoto]) * sdk: allow to specify relay pool notification channel size in `Options` ([Yuki Kishimoto]) diff --git a/crates/nostr/src/nips/mod.rs b/crates/nostr/src/nips/mod.rs index fd2839a96..cc2d3c2d8 100644 --- a/crates/nostr/src/nips/mod.rs +++ b/crates/nostr/src/nips/mod.rs @@ -20,6 +20,7 @@ pub mod nip10; pub mod nip11; pub mod nip13; pub mod nip15; +pub mod nip17; pub mod nip19; pub mod nip21; pub mod nip26; diff --git a/crates/nostr/src/nips/nip17.rs b/crates/nostr/src/nips/nip17.rs new file mode 100644 index 000000000..cbcb6d277 --- /dev/null +++ b/crates/nostr/src/nips/nip17.rs @@ -0,0 +1,43 @@ +// Copyright (c) 2022-2023 Yuki Kishimoto +// Copyright (c) 2023-2024 Rust Nostr Developers +// Distributed under the MIT software license + +//! NIP17: Private Direct Message +//! +//! + +use alloc::boxed::Box; +use core::iter; + +use crate::types::Url; +use crate::{Event, Kind, TagStandard}; + +/// Extracts the relay list +pub fn extract_relay_list<'a>(event: &'a Event) -> Box + 'a> { + if event.kind != Kind::InboxRelays { + return Box::new(iter::empty()); + } + + Box::new(event.tags.iter().filter_map(|tag| { + if let Some(TagStandard::Relay(url)) = tag.as_standardized() { + Some(url) + } else { + None + } + })) +} + +/// Extracts the relay list +pub fn extract_owned_relay_list(event: Event) -> Box> { + if event.kind != Kind::InboxRelays { + return Box::new(iter::empty()); + } + + Box::new(event.tags.into_iter().filter_map(|tag| { + if let Some(TagStandard::Relay(url)) = tag.to_standardized() { + Some(url) + } else { + None + } + })) +} diff --git a/crates/nostr/src/prelude.rs b/crates/nostr/src/prelude.rs index 866cabb58..efb13a8f2 100644 --- a/crates/nostr/src/prelude.rs +++ b/crates/nostr/src/prelude.rs @@ -4,6 +4,7 @@ //! Prelude +#![allow(unused_imports)] #![allow(unknown_lints)] #![allow(ambiguous_glob_reexports)] #![doc(hidden)] @@ -40,6 +41,7 @@ pub use crate::nips::nip10::{self, *}; pub use crate::nips::nip11::{self, *}; pub use crate::nips::nip13::{self, *}; pub use crate::nips::nip15::{self, *}; +pub use crate::nips::nip17::{self, *}; pub use crate::nips::nip19::{self, *}; pub use crate::nips::nip21::{self, *}; pub use crate::nips::nip26::{self, *};