feat: add more nostr commands

This commit is contained in:
2024-02-13 09:36:11 +07:00
parent 90f149b09c
commit 4292def206
3 changed files with 64 additions and 0 deletions

View 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)
}
}