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