From 27cd06f6a73859d67176bc7e9e320eed85c262c6 Mon Sep 17 00:00:00 2001 From: Mike Dilger Date: Thu, 14 Sep 2023 11:00:43 +1200 Subject: [PATCH] fix: update local contact list edit when edits are made --- src/people.rs | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/src/people.rs b/src/people.rs index bb41a3be8..3c4dbd77a 100644 --- a/src/people.rs +++ b/src/people.rs @@ -583,8 +583,8 @@ impl People { // We don't use the data, but we shouldn't clobber it. let content = match GLOBALS - .storage - .get_replaceable_event(public_key, EventKind::ContactList)? + .storage + .get_replaceable_event(public_key, EventKind::ContactList)? { Some(c) => c.content, None => "".to_owned(), @@ -603,17 +603,27 @@ impl People { } pub fn follow(&self, pubkey: &PublicKey, follow: bool) -> Result<(), Error> { + let mut txn = GLOBALS.storage.get_write_txn()?; + if follow { GLOBALS .storage - .add_person_to_list(pubkey, PersonList::Followed, None)?; + .add_person_to_list(pubkey, PersonList::Followed, Some(&mut txn))?; } else { - GLOBALS - .storage - .remove_person_from_list(pubkey, PersonList::Followed, None)?; + GLOBALS.storage.remove_person_from_list( + pubkey, + PersonList::Followed, + Some(&mut txn), + )?; } GLOBALS.ui_people_to_invalidate.write().push(*pubkey); + GLOBALS + .storage + .write_last_contact_list_edit(Unixtime::now().unwrap().0, Some(&mut txn))?; + + txn.commit()?; + Ok(()) } @@ -633,21 +643,34 @@ impl People { GLOBALS.ui_people_to_invalidate.write().push(*pubkey); } + GLOBALS + .storage + .write_last_contact_list_edit(Unixtime::now().unwrap().0, Some(&mut txn))?; + + txn.commit()?; + // Add the people to the relay_picker for picking for pubkey in pubkeys.iter() { GLOBALS.relay_picker.add_someone(pubkey.to_owned())?; } - txn.commit()?; - Ok(()) } pub fn follow_none(&self) -> Result<(), Error> { + let mut txn = GLOBALS.storage.get_write_txn()?; + GLOBALS .storage - .clear_person_list(PersonList::Followed, None)?; + .clear_person_list(PersonList::Followed, Some(&mut txn))?; + GLOBALS + .storage + .write_last_contact_list_edit(Unixtime::now().unwrap().0, Some(&mut txn))?; + + txn.commit()?; + GLOBALS.ui_invalidate_all.store(false, Ordering::Relaxed); + Ok(()) }