mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 03:33:53 +00:00
Refresh metadata of all following
This commit is contained in:
parent
7474d8427c
commit
9516513d84
@ -20,6 +20,7 @@ pub enum ToOverlordMessage {
|
||||
PullFollowMerge,
|
||||
PullFollowOverwrite,
|
||||
PushFollow,
|
||||
RefreshFollowedMetadata,
|
||||
SaveRelays,
|
||||
SaveSettings,
|
||||
SetThreadFeed(Id, Id),
|
||||
@ -47,6 +48,6 @@ pub enum ToMinionPayload {
|
||||
SubscribeGeneralFeed,
|
||||
SubscribePersonFeed(PublicKeyHex),
|
||||
SubscribeThreadFeed(IdHex, Vec<IdHex>),
|
||||
TempSubscribeMetadata(PublicKeyHex),
|
||||
TempSubscribeMetadata(Vec<PublicKeyHex>),
|
||||
UnsubscribeThreadFeed,
|
||||
}
|
||||
|
@ -256,8 +256,8 @@ impl Minion {
|
||||
ToMinionPayload::SubscribeThreadFeed(main, parents) => {
|
||||
self.subscribe_thread_feed(main, parents).await?;
|
||||
}
|
||||
ToMinionPayload::TempSubscribeMetadata(pubkeyhex) => {
|
||||
self.temp_subscribe_metadata(pubkeyhex).await?;
|
||||
ToMinionPayload::TempSubscribeMetadata(pubkeyhexs) => {
|
||||
self.temp_subscribe_metadata(pubkeyhexs).await?;
|
||||
}
|
||||
ToMinionPayload::UnsubscribeThreadFeed => {
|
||||
self.unsubscribe_thread_feed().await?;
|
||||
@ -677,10 +677,13 @@ impl Minion {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn temp_subscribe_metadata(&mut self, pubkeyhex: PublicKeyHex) -> Result<(), Error> {
|
||||
let handle = format!("temp_subscribe_metadata_{}", &pubkeyhex.0);
|
||||
async fn temp_subscribe_metadata(
|
||||
&mut self,
|
||||
pubkeyhexs: Vec<PublicKeyHex>,
|
||||
) -> Result<(), Error> {
|
||||
let handle = "temp_subscribe_metadata".to_string();
|
||||
let filter = Filter {
|
||||
authors: vec![pubkeyhex],
|
||||
authors: pubkeyhexs,
|
||||
kinds: vec![EventKind::Metadata],
|
||||
// FIXME: we could probably get a since-last-fetched-their-metadata here.
|
||||
// but relays should just return the lastest of these.
|
||||
|
@ -478,6 +478,9 @@ impl Overlord {
|
||||
ToOverlordMessage::PushFollow => {
|
||||
self.push_following().await?;
|
||||
}
|
||||
ToOverlordMessage::RefreshFollowedMetadata => {
|
||||
self.refresh_followed_metadata().await?;
|
||||
}
|
||||
ToOverlordMessage::SaveRelays => {
|
||||
let dirty_relays: Vec<DbRelay> = GLOBALS
|
||||
.relays
|
||||
@ -540,7 +543,7 @@ impl Overlord {
|
||||
// Subscribe to metadata and contact lists for this person
|
||||
let _ = self.to_minions.send(ToMinionMessage {
|
||||
target: person_relay.relay.to_string(),
|
||||
payload: ToMinionPayload::TempSubscribeMetadata(pubkey.clone()),
|
||||
payload: ToMinionPayload::TempSubscribeMetadata(vec![pubkey.clone()]),
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -959,6 +962,43 @@ impl Overlord {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// This gets it whether we had it or not. Because it might have changed.
|
||||
async fn refresh_followed_metadata(&mut self) -> Result<(), Error> {
|
||||
let pubkeys = GLOBALS.people.get_followed_pubkeys();
|
||||
|
||||
let num_relays_per_person = GLOBALS.settings.read().await.num_relays_per_person;
|
||||
|
||||
let mut map: HashMap<Url, Vec<PublicKeyHex>> = HashMap::new();
|
||||
|
||||
// Sort the people into the relays we will find their metadata at
|
||||
for pubkey in &pubkeys {
|
||||
for relay in DbPersonRelay::get_best_relays(pubkey.to_owned())
|
||||
.await?
|
||||
.drain(..)
|
||||
.take(num_relays_per_person as usize)
|
||||
{
|
||||
map.entry(relay)
|
||||
.and_modify(|e| e.push(pubkey.to_owned()))
|
||||
.or_insert_with(|| vec![pubkey.to_owned()]);
|
||||
}
|
||||
}
|
||||
|
||||
for (url, pubkeys) in map.drain() {
|
||||
// Start minion if needed
|
||||
if !GLOBALS.relays_watching.read().await.contains(&url) {
|
||||
self.start_minion(url.inner().to_string()).await?;
|
||||
}
|
||||
|
||||
// Subscribe to their metadata
|
||||
let _ = self.to_minions.send(ToMinionMessage {
|
||||
target: url.inner().to_string(),
|
||||
payload: ToMinionPayload::TempSubscribeMetadata(pubkeys),
|
||||
});
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn set_thread_feed(&mut self, id: Id, referenced_by: Id) -> Result<(), Error> {
|
||||
// Cancel current thread subscriptions, if any
|
||||
let _ = self.to_minions.send(ToMinionMessage {
|
||||
|
@ -518,7 +518,8 @@ fn render_post_actual(
|
||||
// Under row
|
||||
if !as_reply_to {
|
||||
ui.horizontal(|ui| {
|
||||
if ui.add(CopyButton {})
|
||||
if ui
|
||||
.add(CopyButton {})
|
||||
.on_hover_text("Copy Contents")
|
||||
.clicked()
|
||||
{
|
||||
|
@ -400,7 +400,8 @@ impl GossipUi {
|
||||
}
|
||||
|
||||
ui.label(RichText::new("🔑").text_style(TextStyle::Small).weak());
|
||||
if ui.add(CopyButton {})
|
||||
if ui
|
||||
.add(CopyButton {})
|
||||
.on_hover_text("Copy Public Key")
|
||||
.clicked()
|
||||
{
|
||||
|
@ -48,6 +48,12 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
|
||||
if ui.button("↑ PUSH ↑\n").clicked() {
|
||||
let _ = GLOBALS.to_overlord.send(ToOverlordMessage::PushFollow);
|
||||
}
|
||||
|
||||
if ui.button("Refresh\nMetadata").clicked() {
|
||||
let _ = GLOBALS
|
||||
.to_overlord
|
||||
.send(ToOverlordMessage::RefreshFollowedMetadata);
|
||||
}
|
||||
});
|
||||
|
||||
ui.add_space(10.0);
|
||||
|
Loading…
Reference in New Issue
Block a user