chore: Util to add write relays to a vector

Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb
2025-05-07 06:10:51 +00:00
parent 577de41054
commit d9f8ce2418
2 changed files with 14 additions and 14 deletions

View File

@@ -24,6 +24,7 @@ use nostr::{
nip01::Coordinate,
nip19::{Nip19Coordinate, Nip19Event, ToBech32},
nip34::GitRepositoryAnnouncement,
nip65::{self, RelayMetadata},
},
types::RelayUrl,
};
@@ -120,3 +121,14 @@ pub fn repo_naddr(pubk: PublicKey, relays: &[RelayUrl]) -> N34Result<String> {
.to_bech32()
.map_err(N34Error::from)
}
/// Extends the given vector with write relays found in the event (if any).
pub fn add_write_relays(mut vector: Vec<RelayUrl>, event: Option<&Event>) -> Vec<RelayUrl> {
if let Some(event) = event {
vector.extend(
nip65::extract_owned_relay_list(event.clone())
.filter_map(|(r, m)| m.is_none_or(|m| m == RelayMetadata::Write).then_some(r)),
);
}
vector
}