chore: minor fixes

This commit is contained in:
2025-12-05 10:26:24 +07:00
parent 6b5adb0a56
commit 4637478a0b
5 changed files with 34 additions and 17 deletions

View File

@@ -158,6 +158,8 @@ impl NostrRegistry {
let urls: Vec<RelayUrl> = Self::extract_write_relays(&event);
let author = event.pubkey;
log::info!("Write relays: {urls:?}");
// Fetch user's encryption announcement event
Self::get(client, &urls, author, Kind::Custom(10044)).await;
// Fetch user's messaging relays event
@@ -305,7 +307,20 @@ impl NostrRegistry {
Ok(())
}
fn extract_write_relays(event: &Event) -> Vec<RelayUrl> {
pub fn extract_read_relays(event: &Event) -> Vec<RelayUrl> {
nip65::extract_relay_list(event)
.filter_map(|(url, metadata)| {
if metadata.is_none() || metadata == &Some(RelayMetadata::Read) {
Some(url.to_owned())
} else {
None
}
})
.take(3)
.collect()
}
pub fn extract_write_relays(event: &Event) -> Vec<RelayUrl> {
nip65::extract_relay_list(event)
.filter_map(|(url, metadata)| {
if metadata.is_none() || metadata == &Some(RelayMetadata::Write) {
@@ -332,8 +347,7 @@ impl NostrRegistry {
.tags
.find(TagKind::Client)
.and_then(|tag| tag.content())
.map(|c| c.to_string())
.context("Cannot parse client name from the event's tags")?;
.map(|c| c.to_string());
Ok(Announcement::new(event.id, client_name, public_key))
}

View File

@@ -8,15 +8,15 @@ use crate::NostrRegistry;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Announcement {
id: EventId,
client: String,
public_key: PublicKey,
client_name: Option<String>,
}
impl Announcement {
pub fn new(id: EventId, client_name: String, public_key: PublicKey) -> Self {
pub fn new(id: EventId, client_name: Option<String>, public_key: PublicKey) -> Self {
Self {
id,
client: client_name,
client_name,
public_key,
}
}
@@ -29,8 +29,11 @@ impl Announcement {
self.public_key
}
pub fn client(&self) -> SharedString {
SharedString::from(self.client.clone())
pub fn client_name(&self) -> SharedString {
self.client_name
.as_ref()
.map(SharedString::from)
.unwrap_or(SharedString::from("Unknown"))
}
}