From a3351df210d1a1165bec5990ebe8be4f838b45fa Mon Sep 17 00:00:00 2001 From: xy Date: Fri, 14 Jun 2024 17:19:53 +0900 Subject: [PATCH] chore: simplify unfollow function --- src-tauri/src/nostr/metadata.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src-tauri/src/nostr/metadata.rs b/src-tauri/src/nostr/metadata.rs index 3bc0e8f01..d053a71aa 100644 --- a/src-tauri/src/nostr/metadata.rs +++ b/src-tauri/src/nostr/metadata.rs @@ -194,16 +194,13 @@ pub async fn unfollow(id: &str, state: State<'_, Nostr>) -> Result { - let index = old_list - .iter() - .position(|x| x.public_key == public_key) - .unwrap(); - old_list.remove(index); - - let new_list = old_list.into_iter(); + Ok(old_list) => { + let contacts: Vec = old_list + .into_iter() + .filter(|contact| contact.public_key != public_key) + .collect(); - match client.set_contact_list(new_list).await { + match client.set_contact_list(contacts).await { Ok(event_id) => Ok(event_id.to_string()), Err(err) => Err(err.to_string()), }