-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nostr: add
nip17::extract_relay_list
and `nip17::extract_owned_rela…
…y_list` Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
- Loading branch information
Showing
4 changed files
with
47 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
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
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,43 @@ | ||
// Copyright (c) 2022-2023 Yuki Kishimoto | ||
// Copyright (c) 2023-2024 Rust Nostr Developers | ||
// Distributed under the MIT software license | ||
|
||
//! NIP17: Private Direct Message | ||
//! | ||
//! <https://github.com/nostr-protocol/nips/blob/master/17.md> | ||
|
||
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<dyn Iterator<Item = &'a Url> + '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<dyn Iterator<Item = Url>> { | ||
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 | ||
} | ||
})) | ||
} |
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