diff --git a/gossip-bin/src/commands.rs b/gossip-bin/src/commands.rs index cb289316..e901caac 100644 --- a/gossip-bin/src/commands.rs +++ b/gossip-bin/src/commands.rs @@ -470,25 +470,34 @@ pub fn print_relays(_cmd: Command) -> Result<(), Error> { } pub fn print_followed(_cmd: Command) -> Result<(), Error> { - let pubkeys = GLOBALS - .storage - .get_people_in_list(PersonList::Followed, None)?; - for pk in &pubkeys { + let members = GLOBALS.storage.get_people_in_list(PersonList::Followed)?; + for (pk, public) in &members { if let Some(person) = GLOBALS.storage.read_person(pk)? { - println!("{} {}", pk.as_hex_string(), person.best_name()); + println!( + "{} {} {}", + if *public { "pub" } else { "prv" }, + pk.as_hex_string(), + person.best_name() + ); } else { - println!("{}", pk.as_hex_string()); + println!( + "{} {}", + if *public { "pub" } else { "prv" }, + pk.as_hex_string() + ); } } Ok(()) } pub fn print_muted(_cmd: Command) -> Result<(), Error> { - let pubkeys = GLOBALS - .storage - .get_people_in_list(PersonList::Muted, None)?; - for pk in &pubkeys { - println!("{}", pk.as_hex_string()); + let members = GLOBALS.storage.get_people_in_list(PersonList::Muted)?; + for (pk, public) in &members { + println!( + "{} {}", + if *public { "pub" } else { "prv" }, + pk.as_hex_string() + ); } Ok(()) } @@ -497,20 +506,21 @@ pub fn print_person_lists(_cmd: Command) -> Result<(), Error> { let lists = PersonList::all_lists(); for (list, name) in lists.iter() { println!("LIST {}: {}", u8::from(*list), name); - let pubkeys = GLOBALS.storage.get_people_in_list(*list, Some(true))?; - for pk in &pubkeys { + let members = GLOBALS.storage.get_people_in_list(*list)?; + for (pk, public) in &members { if let Some(person) = GLOBALS.storage.read_person(pk)? { - println!("public: {} {}", pk.as_hex_string(), person.best_name()); + println!( + "{} {} {}", + if *public { "pub" } else { "prv" }, + pk.as_hex_string(), + person.best_name() + ); } else { - println!("public: {}", pk.as_hex_string()); - } - } - let pubkeys = GLOBALS.storage.get_people_in_list(*list, Some(false))?; - for pk in &pubkeys { - if let Some(person) = GLOBALS.storage.read_person(pk)? { - println!("private: {} {}", pk.as_hex_string(), person.best_name()); - } else { - println!("private: {}", pk.as_hex_string()); + println!( + "{} {}", + if *public { "pub" } else { "prv" }, + pk.as_hex_string() + ); } } println!(); diff --git a/gossip-bin/src/ui/people/followed.rs b/gossip-bin/src/ui/people/followed.rs index 3f0eeb5a..a2ed92a7 100644 --- a/gossip-bin/src/ui/people/followed.rs +++ b/gossip-bin/src/ui/people/followed.rs @@ -4,12 +4,16 @@ use eframe::egui; use egui::{Context, RichText, Ui}; use gossip_lib::comms::ToOverlordMessage; use gossip_lib::{Person, PersonList, GLOBALS}; +use nostr_types::PublicKey; pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) { - let followed_pubkeys = GLOBALS + let followed_pubkeys: Vec = GLOBALS .storage - .get_people_in_list(PersonList::Followed, None) - .unwrap_or_default(); + .get_people_in_list(PersonList::Followed) + .unwrap_or_default() + .drain(..) + .map(|(pk, _)| pk) + .collect(); let mut people: Vec = Vec::new(); for pk in &followed_pubkeys { if let Ok(Some(person)) = GLOBALS.storage.read_person(pk) { diff --git a/gossip-bin/src/ui/people/muted.rs b/gossip-bin/src/ui/people/muted.rs index 94e0d17a..92e7be79 100644 --- a/gossip-bin/src/ui/people/muted.rs +++ b/gossip-bin/src/ui/people/muted.rs @@ -4,13 +4,16 @@ use eframe::egui; use egui::{Context, RichText, Ui}; use gossip_lib::comms::ToOverlordMessage; use gossip_lib::{Person, PersonList, GLOBALS}; +use nostr_types::PublicKey; pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) { - let muted_pubkeys = GLOBALS + let muted_pubkeys: Vec = GLOBALS .storage - .get_people_in_list(PersonList::Muted, None) - .unwrap_or_default(); - + .get_people_in_list(PersonList::Muted) + .unwrap_or_default() + .drain(..) + .map(|(pk, _)| pk) + .collect(); let mut people: Vec = Vec::new(); for pk in &muted_pubkeys { if let Ok(Some(person)) = GLOBALS.storage.read_person(pk) { diff --git a/gossip-bin/src/ui/wizard/wizard_state.rs b/gossip-bin/src/ui/wizard/wizard_state.rs index f24c8b15..192e5c89 100644 --- a/gossip-bin/src/ui/wizard/wizard_state.rs +++ b/gossip-bin/src/ui/wizard/wizard_state.rs @@ -81,8 +81,11 @@ impl WizardState { self.followed = GLOBALS .storage - .get_people_in_list(PersonList::Followed, None) - .unwrap_or_default(); + .get_people_in_list(PersonList::Followed) + .unwrap_or_default() + .drain(..) + .map(|(pk, _)| pk) + .collect(); if self.need_discovery_relays() { let purplepages = RelayUrl::try_from_str("wss://purplepag.es/").unwrap(); diff --git a/gossip-lib/src/feed.rs b/gossip-lib/src/feed.rs index 7afea6f8..027ceacf 100644 --- a/gossip-lib/src/feed.rs +++ b/gossip-lib/src/feed.rs @@ -305,7 +305,13 @@ impl Feed { let current_feed_kind = self.current_feed_kind.read().to_owned(); match current_feed_kind { FeedKind::List(list, with_replies) => { - let pubkeys: Vec = GLOBALS.storage.get_people_in_list(list, None)?; + let pubkeys: Vec = GLOBALS + .storage + .get_people_in_list(list)? + .drain(..) + .map(|(pk, _)| pk) + .collect(); + let since = now - Duration::from_secs(GLOBALS.storage.read_setting_feed_chunk()); // FIXME we don't include delegated events. We should look for all events diff --git a/gossip-lib/src/people.rs b/gossip-lib/src/people.rs index e2e2574a..f5753aa6 100644 --- a/gossip-lib/src/people.rs +++ b/gossip-lib/src/people.rs @@ -591,12 +591,7 @@ impl People { let my_pubkey = GLOBALS.signer.public_key().unwrap(); // Read the person list in two parts - let public_people = GLOBALS - .storage - .get_people_in_list(person_list, Some(true))?; - let private_people = GLOBALS - .storage - .get_people_in_list(person_list, Some(false))?; + let people = GLOBALS.storage.get_people_in_list(person_list)?; // Determine the event kind let kind = match person_list { @@ -607,7 +602,11 @@ impl People { // Build public p-tags let mut tags: Vec = Vec::new(); - for pubkey in public_people.iter() { + for (pubkey, public) in people.iter() { + if !*public { + continue; + } + // Only include petnames in the ContactList (which is only public people) let petname = if kind == EventKind::ContactList { if let Some(person) = GLOBALS.storage.read_person(pubkey)? { @@ -656,7 +655,11 @@ impl People { } else { // Build private p-tags (except for ContactList) let mut private_p_tags: Vec = Vec::new(); - for pubkey in private_people.iter() { + for (pubkey, public) in people.iter() { + if *public { + continue; + } + private_p_tags.push(Tag::Pubkey { pubkey: pubkey.into(), recommended_relay_url: None, diff --git a/gossip-lib/src/storage/mod.rs b/gossip-lib/src/storage/mod.rs index a1f95a72..e58c383a 100644 --- a/gossip-lib/src/storage/mod.rs +++ b/gossip-lib/src/storage/mod.rs @@ -2436,12 +2436,8 @@ impl Storage { } /// Get people in a person list - pub fn get_people_in_list( - &self, - list: PersonList, - public: Option, - ) -> Result, Error> { - self.get_people_in_list2(list, public) + pub fn get_people_in_list(&self, list: PersonList) -> Result, Error> { + self.get_people_in_list2(list) } pub fn get_people_in_all_followed_lists(&self) -> Result, Error> { diff --git a/gossip-lib/src/storage/person_lists2.rs b/gossip-lib/src/storage/person_lists2.rs index b774e210..568c3c95 100644 --- a/gossip-lib/src/storage/person_lists2.rs +++ b/gossip-lib/src/storage/person_lists2.rs @@ -100,28 +100,18 @@ impl Storage { pub(crate) fn get_people_in_list2( &self, list: PersonList1, - public: Option, - ) -> Result, Error> { + ) -> Result, Error> { let txn = self.env.read_txn()?; - let mut pubkeys: Vec = Vec::new(); + let mut output: Vec<(PublicKey, bool)> = Vec::new(); for result in self.db_person_lists2()?.iter(&txn)? { let (key, val) = result?; let pubkey = PublicKey::from_bytes(key, true)?; let map = HashMap::::read_from_buffer(val)?; if let Some(actual_public) = map.get(&list) { - match public { - Some(requested_public) => { - if requested_public == *actual_public { - pubkeys.push(pubkey); - } - } - None => { - pubkeys.push(pubkey); - } - } + output.push((pubkey, *actual_public)); } } - Ok(pubkeys) + Ok(output) } pub(crate) fn clear_person_list2<'a>( diff --git a/gossip-lib/src/storage/types/person_list1.rs b/gossip-lib/src/storage/types/person_list1.rs index 62fa8bab..8f8c2c27 100644 --- a/gossip-lib/src/storage/types/person_list1.rs +++ b/gossip-lib/src/storage/types/person_list1.rs @@ -104,7 +104,7 @@ impl PersonList1 { /// Deallocate this PersonList1 pub fn deallocate(&self, txn: Option<&mut RwTxn<'_>>) -> Result<(), Error> { - if !GLOBALS.storage.get_people_in_list(*self, None)?.is_empty() { + if !GLOBALS.storage.get_people_in_list(*self)?.is_empty() { Err(ErrorKind::ListIsNotEmpty.into()) } else { if let PersonList1::Custom(i) = self {