feat: add more nostr commands
This commit is contained in:
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