diff --git a/src/overlord/mod.rs b/src/overlord/mod.rs index c242a0d4..f9834f09 100644 --- a/src/overlord/mod.rs +++ b/src/overlord/mod.rs @@ -524,6 +524,43 @@ impl Overlord { DbRelay::insert(dbrelay).await?; } } + "update_metadata" => { + tracing::debug!("Overlord got update_metadata request"); + + // Get all people we are rendering + let v: Vec = GLOBALS.people.read().await + .get_all().iter().map(|p| p.pubkey.clone()).collect(); + + // Get all relays we are connected to + let r: Vec = self.urls_watching.iter().map(|u| u.inner().to_owned()).collect(); + + // Match up people with relays, sorted into per-relay buckets + let matching = DbPersonRelay::fetch_matching(v.clone(), r.clone()).await?; + let mut by_relay: HashMap> = HashMap::new(); + for person_relay in matching.iter() { + let pkh = PublicKeyHex(person_relay.person.clone()); + by_relay.entry(person_relay.relay.clone()) + .and_modify(|v| v.push(pkh.clone())) + .or_insert_with(|| { + vec![pkh] + }); + } + + // Tell each minion in turn to subscribe to ephemeral data for all + // the people we are watching that use that relay + for (relay, people) in by_relay.iter() { + + tracing::debug!("Overlord asking {} to update metadata for {} people", + &relay, people.len()); + + // "subscribe_ephemeral_for_all" + let _ = self.to_minions.send(BusMessage { + target: relay.to_string(), + kind: "subscribe_ephemeral_for_all".to_string(), + json_payload: serde_json::to_string(people).unwrap(), + }); + } + } _ => {} }, _ => {} diff --git a/src/people.rs b/src/people.rs index c57f2588..92d1ee7e 100644 --- a/src/people.rs +++ b/src/people.rs @@ -195,7 +195,7 @@ impl People { } } - pub fn get_all(&mut self) -> Vec { + pub fn get_all(&self) -> Vec { let mut v: Vec = self.people.values().map(|p| p.to_owned()).collect(); v.sort_by(|a, b| { let c = a.name.cmp(&b.name); diff --git a/src/ui/feed.rs b/src/ui/feed.rs index 2abdef3d..218506b1 100644 --- a/src/ui/feed.rs +++ b/src/ui/feed.rs @@ -31,21 +31,35 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram }; ui.with_layout(Layout::right_to_left(Align::TOP), |ui| { - if ui - .button(&format!("QM {}", desired_count)) - .on_hover_text("Query Relays for Missing Events") - .clicked() - { - let tx = GLOBALS.to_overlord.clone(); - let _ = tx.send(BusMessage { - target: "overlord".to_string(), - kind: "get_missing_events".to_string(), - json_payload: serde_json::to_string("").unwrap(), - }); - } + + ui.menu_button("Query", |ui| { + if ui.button("Missing Events") + .on_hover_text("Query Relays for Missing Events") + .clicked() + { + let _ = GLOBALS.to_overlord.send(BusMessage { + target: "overlord".to_string(), + kind: "get_missing_events".to_string(), + json_payload: serde_json::to_string("").unwrap(), + }); + } + + if ui.button("Metadata") + .on_hover_text("Metadata and contact lists for everyone in the feed") + .clicked() + { + let _ = GLOBALS.to_overlord.send(BusMessage { + target: "overlord".to_string(), + kind: "update_metadata".to_string(), + json_payload: serde_json::to_string("").unwrap(), + }); + } + }); + + ui.label(&format!("Missing={}", desired_count)); if ui - .button(&format!("PQ {}", incoming_count)) + .button(&format!("Process={}", incoming_count)) .on_hover_text("Process Queue of Incoming Events") .clicked() {