feat: add more nostr commands
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
pub mod event;
|
pub mod event;
|
||||||
pub mod keys;
|
pub mod keys;
|
||||||
pub mod metadata;
|
pub mod metadata;
|
||||||
|
pub mod relay;
|
||||||
|
|||||||
@@ -33,3 +33,34 @@ pub async fn get_profile(id: &str, nostr: State<'_, Nostr>) -> Result<Metadata,
|
|||||||
Err(())
|
Err(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command(async)]
|
||||||
|
pub async fn create_profile(
|
||||||
|
name: &str,
|
||||||
|
display_name: &str,
|
||||||
|
about: &str,
|
||||||
|
picture: &str,
|
||||||
|
banner: &str,
|
||||||
|
nip05: &str,
|
||||||
|
lud16: &str,
|
||||||
|
website: &str,
|
||||||
|
nostr: State<'_, Nostr>,
|
||||||
|
) -> Result<EventId, ()> {
|
||||||
|
let client = &nostr.client;
|
||||||
|
|
||||||
|
let metadata = Metadata::new()
|
||||||
|
.name(name)
|
||||||
|
.display_name(display_name)
|
||||||
|
.about(about)
|
||||||
|
.nip05(nip05)
|
||||||
|
.lud16(lud16)
|
||||||
|
.picture(Url::parse(picture).unwrap())
|
||||||
|
.banner(Url::parse(banner).unwrap())
|
||||||
|
.website(Url::parse(website).unwrap());
|
||||||
|
|
||||||
|
if let Ok(event_id) = client.set_metadata(&metadata).await {
|
||||||
|
Ok(event_id)
|
||||||
|
} else {
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
32
src-tauri/src/nostr/relay.rs
Normal file
32
src-tauri/src/nostr/relay.rs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
use crate::Nostr;
|
||||||
|
use nostr_sdk::prelude::*;
|
||||||
|
use tauri::State;
|
||||||
|
|
||||||
|
#[tauri::command(async)]
|
||||||
|
pub async fn list_connected_relays(nostr: State<'_, Nostr>) -> Result<Vec<Url>, ()> {
|
||||||
|
let client = &nostr.client;
|
||||||
|
let relays = client.relays().await;
|
||||||
|
let list: Vec<Url> = relays.into_keys().collect();
|
||||||
|
|
||||||
|
Ok(list)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command(async)]
|
||||||
|
pub async fn connect_relay(relay: &str, nostr: State<'_, Nostr>) -> Result<bool, ()> {
|
||||||
|
let client = &nostr.client;
|
||||||
|
if let Ok(_) = client.add_relay(relay).await {
|
||||||
|
Ok(true)
|
||||||
|
} else {
|
||||||
|
Ok(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command(async)]
|
||||||
|
pub async fn remove_relay(relay: &str, nostr: State<'_, Nostr>) -> Result<bool, ()> {
|
||||||
|
let client = &nostr.client;
|
||||||
|
if let Ok(_) = client.remove_relay(relay).await {
|
||||||
|
Ok(true)
|
||||||
|
} else {
|
||||||
|
Ok(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user