feat: finish settings screen

This commit is contained in:
2024-04-16 15:28:38 +07:00
parent 2eb2010d43
commit 413d8d82df
13 changed files with 461 additions and 61 deletions

View File

@@ -11,6 +11,35 @@ pub struct CacheContact {
profile: Metadata,
}
#[tauri::command]
pub async fn get_current_user_profile(state: State<'_, Nostr>) -> Result<Metadata, String> {
let client = &state.client;
let signer = client.signer().await.unwrap();
let public_key = signer.public_key().await.unwrap();
let filter = Filter::new()
.author(public_key)
.kind(Kind::Metadata)
.limit(1);
match client
.get_events_of(vec![filter], Some(Duration::from_secs(10)))
.await
{
Ok(events) => {
if let Some(event) = events.first() {
if let Ok(metadata) = Metadata::from_json(&event.content) {
Ok(metadata)
} else {
Err("Parse metadata failed".into())
}
} else {
Err("Not found".into())
}
}
Err(_) => Err("Not found".into()),
}
}
#[tauri::command]
pub async fn get_profile(id: &str, state: State<'_, Nostr>) -> Result<Metadata, String> {
let client = &state.client;