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()), }