Files
easy-nostr/src/functions/get_contacts.rs

26 lines
891 B
Rust

use anyhow::Result;
use nostr_sdk::prelude::*;
use nostr_sdk::nostr::TagStandard;
use crate::nips::nip02;
pub async fn get_contacts(client: &Client) -> Result<Vec<Contact>> {
let event_opt = nip02::get_contact_list_event(client).await?;
match event_opt {
Some(event) => {
let mut contacts = Vec::new();
for tag in event.tags {
if let Some(TagStandard::PublicKey { public_key, relay_url, alias, .. }) = tag.as_standardized() {
// Werte kopieren/klonen (Ownership Fix)
let mut contact = Contact::new(*public_key);
contact.relay_url = relay_url.clone();
contact.alias = alias.clone();
contacts.push(contact);
}
}
Ok(contacts)
}
None => Ok(Vec::new()),
}
}