feat: add contact list commands

This commit is contained in:
2024-02-20 14:46:21 +07:00
parent d0c9f93ebb
commit 090e54ec5a
7 changed files with 160 additions and 79 deletions

View File

@@ -1,10 +1,10 @@
use crate::NostrClient;
use crate::Nostr;
use nostr_sdk::prelude::*;
use tauri::State;
#[tauri::command]
pub async fn list_connected_relays(state: State<'_, NostrClient>) -> Result<Vec<Url>, ()> {
let client = state.0.lock().await;
pub async fn list_connected_relays(state: State<'_, Nostr>) -> Result<Vec<Url>, ()> {
let client = state.client.lock().await;
let relays = client.relays().await;
let list: Vec<Url> = relays.into_keys().collect();
@@ -12,8 +12,8 @@ pub async fn list_connected_relays(state: State<'_, NostrClient>) -> Result<Vec<
}
#[tauri::command]
pub async fn connect_relay(relay: &str, state: State<'_, NostrClient>) -> Result<bool, ()> {
let client = state.0.lock().await;
pub async fn connect_relay(relay: &str, state: State<'_, Nostr>) -> Result<bool, ()> {
let client = state.client.lock().await;
if let Ok(_) = client.add_relay(relay).await {
Ok(true)
} else {
@@ -22,8 +22,8 @@ pub async fn connect_relay(relay: &str, state: State<'_, NostrClient>) -> Result
}
#[tauri::command]
pub async fn remove_relay(relay: &str, state: State<'_, NostrClient>) -> Result<bool, ()> {
let client = state.0.lock().await;
pub async fn remove_relay(relay: &str, state: State<'_, Nostr>) -> Result<bool, ()> {
let client = state.client.lock().await;
if let Ok(_) = client.remove_relay(relay).await {
Ok(true)
} else {