Structured files/directories and nip01, nip02, nip17 implementation
This commit is contained in:
26
src/functions/get_contacts.rs
Normal file
26
src/functions/get_contacts.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
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()),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user