chore: add some small improvements

This commit is contained in:
2024-09-30 04:49:17 +07:00
parent f0fc89724d
commit 09db39fce1
6 changed files with 53 additions and 49 deletions

View File

@@ -324,6 +324,8 @@ pub async fn login(
.await
.unwrap();
state.contact_list.lock().await.clone_from(&contact_list);
// Get user's contact list
if !contact_list.is_empty() {
let authors: Vec<PublicKey> = contact_list.iter().map(|f| f.public_key).collect();

View File

@@ -154,19 +154,13 @@ pub async fn set_profile(profile: Profile, state: State<'_, Nostr>) -> Result<St
#[tauri::command]
#[specta::specta]
pub async fn check_contact(hex: String, state: State<'_, Nostr>) -> Result<bool, String> {
let client = &state.client;
let contact_list = client
.get_contact_list(Some(Duration::from_secs(5)))
.await
.map_err(|e| e.to_string())?;
pub async fn check_contact(id: String, state: State<'_, Nostr>) -> Result<bool, String> {
let contact_list = &state.contact_list.lock().await;
let public_key = PublicKey::from_str(&id).map_err(|e| e.to_string())?;
match PublicKey::parse(&hex) {
Ok(public_key) => match contact_list.iter().position(|x| x.public_key == public_key) {
Some(_) => Ok(true),
None => Ok(false),
},
Err(e) => Err(e.to_string()),
match contact_list.iter().position(|x| x.public_key == public_key) {
Some(_) => Ok(true),
None => Ok(false),
}
}

View File

@@ -31,6 +31,7 @@ pub mod common;
pub struct Nostr {
client: Client,
settings: Mutex<Settings>,
contact_list: Mutex<Vec<Contact>>,
circles: Mutex<HashMap<PublicKey, Vec<PublicKey>>>,
}
@@ -277,6 +278,7 @@ fn main() {
app.manage(Nostr {
client,
settings: Mutex::new(Settings::default()),
contact_list: Mutex::new(Vec::new()),
circles: Mutex::new(HashMap::new()),
});