Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: simplify unfollow function #209

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions src-tauri/src/nostr/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,13 @@ pub async fn unfollow(id: &str, state: State<'_, Nostr>) -> Result<String, Strin
let contact_list = client.get_contact_list(Some(Duration::from_secs(10))).await;

match contact_list {
Ok(mut old_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();
Ok(old_list) => {
let contacts: Vec<Contact> = 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()),
}
Expand Down