feat: add contact list commands
This commit is contained in:
@@ -18,12 +18,7 @@ function Home() {
|
|||||||
queryKey: ["timeline"],
|
queryKey: ["timeline"],
|
||||||
initialPageParam: 0,
|
initialPageParam: 0,
|
||||||
queryFn: async ({ pageParam }: { pageParam: number }) => {
|
queryFn: async ({ pageParam }: { pageParam: number }) => {
|
||||||
const events = await ark.get_text_events(
|
const events = await ark.get_text_events(FETCH_LIMIT, pageParam, true);
|
||||||
FETCH_LIMIT,
|
|
||||||
pageParam,
|
|
||||||
undefined,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
return events;
|
return events;
|
||||||
},
|
},
|
||||||
getNextPageParam: (lastPage) => {
|
getNextPageParam: (lastPage) => {
|
||||||
|
|||||||
@@ -109,7 +109,6 @@ export class Ark {
|
|||||||
public async get_text_events(
|
public async get_text_events(
|
||||||
limit: number,
|
limit: number,
|
||||||
asOf?: number,
|
asOf?: number,
|
||||||
authors?: string[],
|
|
||||||
dedup?: boolean,
|
dedup?: boolean,
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
@@ -118,12 +117,10 @@ export class Ark {
|
|||||||
|
|
||||||
const seenIds = new Set<string>();
|
const seenIds = new Set<string>();
|
||||||
const dedupQueue = new Set<string>();
|
const dedupQueue = new Set<string>();
|
||||||
const contact_list = authors ?? this.account.contacts;
|
|
||||||
|
|
||||||
const nostrEvents: Event[] = await invoke("get_text_events", {
|
const nostrEvents: Event[] = await invoke("get_local_events", {
|
||||||
limit,
|
limit,
|
||||||
until,
|
until,
|
||||||
contact_list,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (dedup) {
|
if (dedup) {
|
||||||
|
|||||||
@@ -13,7 +13,10 @@ use tauri::Manager;
|
|||||||
use tauri_plugin_autostart::MacosLauncher;
|
use tauri_plugin_autostart::MacosLauncher;
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
pub struct NostrClient(Mutex<Client>);
|
pub struct Nostr {
|
||||||
|
client: Mutex<Client>,
|
||||||
|
contact_list: Mutex<Option<Vec<PublicKey>>>,
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut ctx = tauri::generate_context!();
|
let mut ctx = tauri::generate_context!();
|
||||||
@@ -58,7 +61,10 @@ fn main() {
|
|||||||
client.connect().await;
|
client.connect().await;
|
||||||
|
|
||||||
// Update global state
|
// Update global state
|
||||||
handle.manage(NostrClient(Mutex::new(client)))
|
handle.manage(Nostr {
|
||||||
|
client: Mutex::new(client),
|
||||||
|
contact_list: Mutex::new(None),
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -92,8 +98,11 @@ fn main() {
|
|||||||
nostr::metadata::get_profile,
|
nostr::metadata::get_profile,
|
||||||
nostr::metadata::get_contact_list,
|
nostr::metadata::get_contact_list,
|
||||||
nostr::metadata::create_profile,
|
nostr::metadata::create_profile,
|
||||||
|
nostr::metadata::follow,
|
||||||
|
nostr::metadata::unfollow,
|
||||||
nostr::event::get_event,
|
nostr::event::get_event,
|
||||||
nostr::event::get_text_events,
|
nostr::event::get_local_events,
|
||||||
|
nostr::event::get_global_events,
|
||||||
nostr::event::get_event_thread,
|
nostr::event::get_event_thread,
|
||||||
nostr::event::publish,
|
nostr::event::publish,
|
||||||
nostr::event::reply_to,
|
nostr::event::reply_to,
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use crate::NostrClient;
|
use crate::Nostr;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use std::{str::FromStr, time::Duration};
|
use std::{str::FromStr, time::Duration};
|
||||||
use tauri::State;
|
use tauri::State;
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn get_event(id: &str, state: State<'_, NostrClient>) -> Result<String, String> {
|
pub async fn get_event(id: &str, state: State<'_, Nostr>) -> Result<String, String> {
|
||||||
let client = state.0.lock().await;
|
let client = state.client.lock().await;
|
||||||
let event_id: Option<EventId> = match Nip19::from_bech32(id) {
|
let event_id: Option<EventId> = match Nip19::from_bech32(id) {
|
||||||
Ok(val) => match val {
|
Ok(val) => match val {
|
||||||
Nip19::EventId(id) => Some(id),
|
Nip19::EventId(id) => Some(id),
|
||||||
@@ -39,30 +39,25 @@ pub async fn get_event(id: &str, state: State<'_, NostrClient>) -> Result<String
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn get_text_events(
|
pub async fn get_local_events(
|
||||||
limit: usize,
|
limit: usize,
|
||||||
until: Option<&str>,
|
until: Option<&str>,
|
||||||
contact_list: Option<Vec<&str>>,
|
state: State<'_, Nostr>,
|
||||||
state: State<'_, NostrClient>,
|
) -> Result<Vec<Event>, String> {
|
||||||
) -> Result<Vec<Event>, ()> {
|
let client = state.client.lock().await;
|
||||||
let client = state.0.lock().await;
|
let f_until = match until {
|
||||||
|
Some(until) => Timestamp::from_str(until).unwrap(),
|
||||||
|
None => Timestamp::now(),
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(list) = contact_list {
|
let contact_list = state.contact_list.lock().await;
|
||||||
let authors: Vec<PublicKey> = list
|
|
||||||
.into_iter()
|
|
||||||
.map(|x| PublicKey::from_str(x).unwrap())
|
|
||||||
.collect();
|
|
||||||
let mut final_until = Timestamp::now();
|
|
||||||
|
|
||||||
if let Some(t) = until {
|
|
||||||
final_until = Timestamp::from_str(&t).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if let Some(authors) = contact_list.clone() {
|
||||||
let filter = Filter::new()
|
let filter = Filter::new()
|
||||||
.kinds(vec![Kind::TextNote, Kind::Repost])
|
.kinds(vec![Kind::TextNote, Kind::Repost])
|
||||||
.authors(authors)
|
.authors(authors)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.until(final_until);
|
.until(f_until);
|
||||||
|
|
||||||
if let Ok(events) = client
|
if let Ok(events) = client
|
||||||
.get_events_of(vec![filter], Some(Duration::from_secs(10)))
|
.get_events_of(vec![filter], Some(Duration::from_secs(10)))
|
||||||
@@ -70,16 +65,43 @@ pub async fn get_text_events(
|
|||||||
{
|
{
|
||||||
Ok(events)
|
Ok(events)
|
||||||
} else {
|
} else {
|
||||||
Err(())
|
Err("Get text event failed".into())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(())
|
Err("Contact list not found".into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn get_event_thread(id: &str, state: State<'_, NostrClient>) -> Result<Vec<Event>, ()> {
|
pub async fn get_global_events(
|
||||||
let client = state.0.lock().await;
|
limit: usize,
|
||||||
|
until: Option<&str>,
|
||||||
|
state: State<'_, Nostr>,
|
||||||
|
) -> Result<Vec<Event>, String> {
|
||||||
|
let client = state.client.lock().await;
|
||||||
|
let f_until = match until {
|
||||||
|
Some(until) => Timestamp::from_str(until).unwrap(),
|
||||||
|
None => Timestamp::now(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let filter = Filter::new()
|
||||||
|
.kinds(vec![Kind::TextNote, Kind::Repost])
|
||||||
|
.limit(limit)
|
||||||
|
.until(f_until);
|
||||||
|
|
||||||
|
if let Ok(events) = client
|
||||||
|
.get_events_of(vec![filter], Some(Duration::from_secs(10)))
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(events)
|
||||||
|
} else {
|
||||||
|
Err("Get text event failed".into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn get_event_thread(id: &str, state: State<'_, Nostr>) -> Result<Vec<Event>, ()> {
|
||||||
|
let client = state.client.lock().await;
|
||||||
let event_id = EventId::from_hex(id).unwrap();
|
let event_id = EventId::from_hex(id).unwrap();
|
||||||
let filter = Filter::new().kinds(vec![Kind::TextNote]).event(event_id);
|
let filter = Filter::new().kinds(vec![Kind::TextNote]).event(event_id);
|
||||||
|
|
||||||
@@ -94,8 +116,8 @@ pub async fn get_event_thread(id: &str, state: State<'_, NostrClient>) -> Result
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn publish(content: &str, state: State<'_, NostrClient>) -> Result<EventId, ()> {
|
pub async fn publish(content: &str, state: State<'_, Nostr>) -> Result<EventId, ()> {
|
||||||
let client = state.0.lock().await;
|
let client = state.client.lock().await;
|
||||||
let event = client
|
let event = client
|
||||||
.publish_text_note(content, [])
|
.publish_text_note(content, [])
|
||||||
.await
|
.await
|
||||||
@@ -108,9 +130,9 @@ pub async fn publish(content: &str, state: State<'_, NostrClient>) -> Result<Eve
|
|||||||
pub async fn reply_to(
|
pub async fn reply_to(
|
||||||
content: &str,
|
content: &str,
|
||||||
tags: Vec<String>,
|
tags: Vec<String>,
|
||||||
state: State<'_, NostrClient>,
|
state: State<'_, Nostr>,
|
||||||
) -> Result<EventId, String> {
|
) -> Result<EventId, String> {
|
||||||
let client = state.0.lock().await;
|
let client = state.client.lock().await;
|
||||||
if let Ok(event_tags) = Tag::parse(tags) {
|
if let Ok(event_tags) = Tag::parse(tags) {
|
||||||
let event = client
|
let event = client
|
||||||
.publish_text_note(content, vec![event_tags])
|
.publish_text_note(content, vec![event_tags])
|
||||||
@@ -124,8 +146,8 @@ pub async fn reply_to(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn repost(id: &str, pubkey: &str, state: State<'_, NostrClient>) -> Result<EventId, ()> {
|
pub async fn repost(id: &str, pubkey: &str, state: State<'_, Nostr>) -> Result<EventId, ()> {
|
||||||
let client = state.0.lock().await;
|
let client = state.client.lock().await;
|
||||||
let public_key = PublicKey::from_str(pubkey).unwrap();
|
let public_key = PublicKey::from_str(pubkey).unwrap();
|
||||||
let event_id = EventId::from_hex(id).unwrap();
|
let event_id = EventId::from_hex(id).unwrap();
|
||||||
|
|
||||||
@@ -138,8 +160,8 @@ pub async fn repost(id: &str, pubkey: &str, state: State<'_, NostrClient>) -> Re
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn upvote(id: &str, pubkey: &str, state: State<'_, NostrClient>) -> Result<EventId, ()> {
|
pub async fn upvote(id: &str, pubkey: &str, state: State<'_, Nostr>) -> Result<EventId, ()> {
|
||||||
let client = state.0.lock().await;
|
let client = state.client.lock().await;
|
||||||
let public_key = PublicKey::from_str(pubkey).unwrap();
|
let public_key = PublicKey::from_str(pubkey).unwrap();
|
||||||
let event_id = EventId::from_hex(id).unwrap();
|
let event_id = EventId::from_hex(id).unwrap();
|
||||||
|
|
||||||
@@ -152,12 +174,8 @@ pub async fn upvote(id: &str, pubkey: &str, state: State<'_, NostrClient>) -> Re
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn downvote(
|
pub async fn downvote(id: &str, pubkey: &str, state: State<'_, Nostr>) -> Result<EventId, ()> {
|
||||||
id: &str,
|
let client = state.client.lock().await;
|
||||||
pubkey: &str,
|
|
||||||
state: State<'_, NostrClient>,
|
|
||||||
) -> Result<EventId, ()> {
|
|
||||||
let client = state.0.lock().await;
|
|
||||||
let public_key = PublicKey::from_str(pubkey).unwrap();
|
let public_key = PublicKey::from_str(pubkey).unwrap();
|
||||||
let event_id = EventId::from_hex(id).unwrap();
|
let event_id = EventId::from_hex(id).unwrap();
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::NostrClient;
|
use crate::Nostr;
|
||||||
use keyring::Entry;
|
use keyring::Entry;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use std::io::{BufReader, Read};
|
use std::io::{BufReader, Read};
|
||||||
@@ -31,7 +31,7 @@ pub fn create_keys() -> Result<CreateKeysResponse, ()> {
|
|||||||
pub async fn save_key(
|
pub async fn save_key(
|
||||||
nsec: &str,
|
nsec: &str,
|
||||||
app_handle: tauri::AppHandle,
|
app_handle: tauri::AppHandle,
|
||||||
state: State<'_, NostrClient>,
|
state: State<'_, Nostr>,
|
||||||
) -> Result<bool, ()> {
|
) -> Result<bool, ()> {
|
||||||
if let Ok(nostr_secret_key) = SecretKey::from_bech32(nsec) {
|
if let Ok(nostr_secret_key) = SecretKey::from_bech32(nsec) {
|
||||||
let nostr_keys = Keys::new(nostr_secret_key);
|
let nostr_keys = Keys::new(nostr_secret_key);
|
||||||
@@ -39,9 +39,19 @@ pub async fn save_key(
|
|||||||
let signer = NostrSigner::Keys(nostr_keys);
|
let signer = NostrSigner::Keys(nostr_keys);
|
||||||
|
|
||||||
// Update client's signer
|
// Update client's signer
|
||||||
let client = state.0.lock().await;
|
let client = state.client.lock().await;
|
||||||
client.set_signer(Some(signer)).await;
|
client.set_signer(Some(signer)).await;
|
||||||
|
|
||||||
|
// Update contact list
|
||||||
|
let mut contact_list = state.contact_list.lock().await;
|
||||||
|
if let Ok(list) = client
|
||||||
|
.get_contact_list_public_keys(Some(Duration::from_secs(10)))
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
println!("total contacts: {}", list.len());
|
||||||
|
*contact_list = Some(list);
|
||||||
|
}
|
||||||
|
|
||||||
let keyring_entry = Entry::new("Lume Secret Storage", "AppKey").unwrap();
|
let keyring_entry = Entry::new("Lume Secret Storage", "AppKey").unwrap();
|
||||||
let secret_key = keyring_entry.get_password().unwrap();
|
let secret_key = keyring_entry.get_password().unwrap();
|
||||||
let app_key = age::x25519::Identity::from_str(&secret_key).unwrap();
|
let app_key = age::x25519::Identity::from_str(&secret_key).unwrap();
|
||||||
@@ -81,8 +91,8 @@ pub fn get_public_key(nsec: &str) -> Result<String, ()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn update_signer(nsec: &str, state: State<'_, NostrClient>) -> Result<(), ()> {
|
pub async fn update_signer(nsec: &str, state: State<'_, Nostr>) -> Result<(), ()> {
|
||||||
let client = state.0.lock().await;
|
let client = state.client.lock().await;
|
||||||
let secret_key = SecretKey::from_bech32(nsec).unwrap();
|
let secret_key = SecretKey::from_bech32(nsec).unwrap();
|
||||||
let keys = Keys::new(secret_key);
|
let keys = Keys::new(secret_key);
|
||||||
let signer = NostrSigner::Keys(keys);
|
let signer = NostrSigner::Keys(keys);
|
||||||
@@ -93,8 +103,8 @@ pub async fn update_signer(nsec: &str, state: State<'_, NostrClient>) -> Result<
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn verify_signer(state: State<'_, NostrClient>) -> Result<bool, ()> {
|
pub async fn verify_signer(state: State<'_, Nostr>) -> Result<bool, ()> {
|
||||||
let client = state.0.lock().await;
|
let client = state.client.lock().await;
|
||||||
|
|
||||||
if let Ok(_) = client.signer().await {
|
if let Ok(_) = client.signer().await {
|
||||||
Ok(true)
|
Ok(true)
|
||||||
@@ -107,9 +117,9 @@ pub async fn verify_signer(state: State<'_, NostrClient>) -> Result<bool, ()> {
|
|||||||
pub async fn load_selected_account(
|
pub async fn load_selected_account(
|
||||||
npub: &str,
|
npub: &str,
|
||||||
app_handle: tauri::AppHandle,
|
app_handle: tauri::AppHandle,
|
||||||
state: State<'_, NostrClient>,
|
state: State<'_, Nostr>,
|
||||||
) -> Result<bool, String> {
|
) -> Result<bool, String> {
|
||||||
let client = state.0.lock().await;
|
let client = state.client.lock().await;
|
||||||
let config_dir = app_handle.path().app_config_dir().unwrap();
|
let config_dir = app_handle.path().app_config_dir().unwrap();
|
||||||
let keyring_entry = Entry::new("Lume Secret Storage", "AppKey").unwrap();
|
let keyring_entry = Entry::new("Lume Secret Storage", "AppKey").unwrap();
|
||||||
|
|
||||||
@@ -146,12 +156,14 @@ pub async fn load_selected_account(
|
|||||||
client.set_signer(Some(signer)).await;
|
client.set_signer(Some(signer)).await;
|
||||||
|
|
||||||
// Update contact list
|
// Update contact list
|
||||||
let _contact_list = Some(
|
let mut contact_list = state.contact_list.lock().await;
|
||||||
client
|
if let Ok(list) = client
|
||||||
.get_contact_list(Some(Duration::from_secs(10)))
|
.get_contact_list_public_keys(Some(Duration::from_secs(10)))
|
||||||
.await
|
.await
|
||||||
.unwrap(),
|
{
|
||||||
);
|
println!("total contacts: {}", list.len());
|
||||||
|
*contact_list = Some(list);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(true)
|
Ok(true)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
use crate::NostrClient;
|
use crate::Nostr;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use std::{str::FromStr, time::Duration};
|
use std::{str::FromStr, time::Duration};
|
||||||
use tauri::State;
|
use tauri::State;
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn get_profile(id: &str, state: State<'_, NostrClient>) -> Result<Metadata, String> {
|
pub async fn get_profile(id: &str, state: State<'_, Nostr>) -> Result<Metadata, String> {
|
||||||
let client = state.0.lock().await;
|
let client = state.client.lock().await;
|
||||||
let public_key: Option<PublicKey> = match Nip19::from_bech32(id) {
|
let public_key: Option<PublicKey> = match Nip19::from_bech32(id) {
|
||||||
Ok(val) => match val {
|
Ok(val) => match val {
|
||||||
Nip19::Pubkey(pubkey) => Some(pubkey),
|
Nip19::Pubkey(pubkey) => Some(pubkey),
|
||||||
@@ -38,8 +38,8 @@ pub async fn get_profile(id: &str, state: State<'_, NostrClient>) -> Result<Meta
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn get_contact_list(state: State<'_, NostrClient>) -> Result<Vec<String>, String> {
|
pub async fn get_contact_list(state: State<'_, Nostr>) -> Result<Vec<String>, String> {
|
||||||
let client = state.0.lock().await;
|
let client = state.client.lock().await;
|
||||||
let contact_list = client.get_contact_list(Some(Duration::from_secs(10))).await;
|
let contact_list = client.get_contact_list(Some(Duration::from_secs(10))).await;
|
||||||
|
|
||||||
if let Ok(list) = contact_list {
|
if let Ok(list) = contact_list {
|
||||||
@@ -60,9 +60,9 @@ pub async fn create_profile(
|
|||||||
nip05: &str,
|
nip05: &str,
|
||||||
lud16: &str,
|
lud16: &str,
|
||||||
website: &str,
|
website: &str,
|
||||||
state: State<'_, NostrClient>,
|
state: State<'_, Nostr>,
|
||||||
) -> Result<EventId, ()> {
|
) -> Result<EventId, ()> {
|
||||||
let client = state.0.lock().await;
|
let client = state.client.lock().await;
|
||||||
let metadata = Metadata::new()
|
let metadata = Metadata::new()
|
||||||
.name(name)
|
.name(name)
|
||||||
.display_name(display_name)
|
.display_name(display_name)
|
||||||
@@ -79,3 +79,53 @@ pub async fn create_profile(
|
|||||||
Err(())
|
Err(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn follow(
|
||||||
|
id: &str,
|
||||||
|
alias: Option<&str>,
|
||||||
|
state: State<'_, Nostr>,
|
||||||
|
) -> Result<EventId, String> {
|
||||||
|
let client = state.client.lock().await;
|
||||||
|
let public_key = PublicKey::from_str(id).unwrap();
|
||||||
|
let contact = Contact::new(public_key, None, alias);
|
||||||
|
let contact_list = client.get_contact_list(Some(Duration::from_secs(10))).await;
|
||||||
|
|
||||||
|
if let Ok(mut old_list) = contact_list {
|
||||||
|
old_list.push(contact);
|
||||||
|
let new_list = old_list.into_iter();
|
||||||
|
|
||||||
|
if let Ok(event_id) = client.set_contact_list(new_list).await {
|
||||||
|
Ok(event_id)
|
||||||
|
} else {
|
||||||
|
Err("Follow failed".into())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err("Follow failed".into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
pub async fn unfollow(id: &str, state: State<'_, Nostr>) -> Result<EventId, String> {
|
||||||
|
let client = state.client.lock().await;
|
||||||
|
let public_key = PublicKey::from_str(id).unwrap();
|
||||||
|
let contact_list = client.get_contact_list(Some(Duration::from_secs(10))).await;
|
||||||
|
|
||||||
|
if let Ok(mut old_list) = contact_list {
|
||||||
|
let index = old_list
|
||||||
|
.iter()
|
||||||
|
.position(|x| x.public_key == public_key)
|
||||||
|
.unwrap();
|
||||||
|
old_list.remove(index);
|
||||||
|
|
||||||
|
let new_list = old_list.into_iter();
|
||||||
|
|
||||||
|
if let Ok(event_id) = client.set_contact_list(new_list).await {
|
||||||
|
Ok(event_id)
|
||||||
|
} else {
|
||||||
|
Err("Follow failed".into())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err("Follow failed".into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
use crate::NostrClient;
|
use crate::Nostr;
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
use tauri::State;
|
use tauri::State;
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn list_connected_relays(state: State<'_, NostrClient>) -> Result<Vec<Url>, ()> {
|
pub async fn list_connected_relays(state: State<'_, Nostr>) -> Result<Vec<Url>, ()> {
|
||||||
let client = state.0.lock().await;
|
let client = state.client.lock().await;
|
||||||
let relays = client.relays().await;
|
let relays = client.relays().await;
|
||||||
let list: Vec<Url> = relays.into_keys().collect();
|
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]
|
#[tauri::command]
|
||||||
pub async fn connect_relay(relay: &str, state: State<'_, NostrClient>) -> Result<bool, ()> {
|
pub async fn connect_relay(relay: &str, state: State<'_, Nostr>) -> Result<bool, ()> {
|
||||||
let client = state.0.lock().await;
|
let client = state.client.lock().await;
|
||||||
if let Ok(_) = client.add_relay(relay).await {
|
if let Ok(_) = client.add_relay(relay).await {
|
||||||
Ok(true)
|
Ok(true)
|
||||||
} else {
|
} else {
|
||||||
@@ -22,8 +22,8 @@ pub async fn connect_relay(relay: &str, state: State<'_, NostrClient>) -> Result
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn remove_relay(relay: &str, state: State<'_, NostrClient>) -> Result<bool, ()> {
|
pub async fn remove_relay(relay: &str, state: State<'_, Nostr>) -> Result<bool, ()> {
|
||||||
let client = state.0.lock().await;
|
let client = state.client.lock().await;
|
||||||
if let Ok(_) = client.remove_relay(relay).await {
|
if let Ok(_) = client.remove_relay(relay).await {
|
||||||
Ok(true)
|
Ok(true)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user