redo start_long_lived_subscriptions after the wizard completes so people don't need to restart

This commit is contained in:
Mike Dilger 2023-12-08 13:39:45 +13:00
parent b6e19360b9
commit 3e276803aa
5 changed files with 104 additions and 66 deletions

View File

@ -3,7 +3,7 @@ use crate::ui::{GossipUi, Page};
use eframe::egui;
use egui::{Context, RichText, Ui};
use gossip_lib::comms::ToOverlordMessage;
use gossip_lib::{FeedKind, Person, PersonList, GLOBALS};
use gossip_lib::{Person, PersonList, GLOBALS};
use gossip_relay_picker::Direction;
use nostr_types::{Profile, PublicKey};
@ -153,8 +153,7 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
.to_overlord
.send(ToOverlordMessage::PushPersonList(PersonList::Followed));
let _ = GLOBALS.storage.set_flag_wizard_complete(true, None);
app.page = Page::Feed(FeedKind::List(PersonList::Followed, false));
super::complete_wizard(app);
}
ui.add_space(20.0);
@ -163,16 +162,14 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
label = label.color(app.theme.accent_color());
}
if ui.button(label).clicked() {
let _ = GLOBALS.storage.set_flag_wizard_complete(true, None);
app.page = Page::Feed(FeedKind::List(PersonList::Followed, false));
super::complete_wizard(app);
}
} else {
ui.add_space(20.0);
let mut label = RichText::new(" > Finish");
label = label.color(app.theme.accent_color());
if ui.button(label).clicked() {
let _ = GLOBALS.storage.set_flag_wizard_complete(true, None);
app.page = Page::Feed(FeedKind::List(PersonList::Followed, false));
super::complete_wizard(app);
}
}
}

View File

@ -2,6 +2,7 @@ use crate::ui::{GossipUi, Page};
use eframe::egui;
use egui::widgets::{Button, Slider};
use egui::{Align, Context, Layout};
use gossip_lib::comms::ToOverlordMessage;
use gossip_lib::{FeedKind, PersonList, Relay, GLOBALS};
mod follow_people;
@ -198,8 +199,7 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
ui.add_space(20.0);
if wp != WizardPage::FollowPeople {
if ui.button(" X Exit this Wizard").clicked() {
let _ = GLOBALS.storage.set_flag_wizard_complete(true, None);
app.page = Page::Feed(FeedKind::List(PersonList::Followed, false));
complete_wizard(app);
}
}
@ -264,3 +264,15 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, frame: &mut eframe::Fram
});
});
}
fn complete_wizard(app: &mut GossipUi) {
let _ = GLOBALS.storage.set_flag_wizard_complete(true, None);
app.page = Page::Feed(FeedKind::List(PersonList::Followed, false));
// Once the wizard is complete, we need to tell the overlord to re-run
// its startup stuff, because we now have configuration that matters, and
// this way people don't have to restart gossip
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::StartLongLivedSubscriptions);
}

View File

@ -138,6 +138,9 @@ pub enum ToOverlordMessage {
/// internal
SetDmChannel(DmChannel),
/// Calls [start_long_lived_subscriptions](crate::Overlord::start_long_lived_subscriptions)
StartLongLivedSubscriptions,
/// Calls [subscribe_config](crate::Overlord::subscribe_config)
SubscribeConfig(RelayUrl),

View File

@ -177,66 +177,11 @@ impl Overlord {
// Start periodic tasks in people manager (after signer)
crate::people::People::start();
// FIXME - if this needs doing, it should be done dynamically as
// new people are encountered, not batch-style on startup.
// Create a person record for every person seen
// Initialize the relay picker
GLOBALS.relay_picker.init().await?;
// Pick Relays and start Minions
if !GLOBALS.storage.read_setting_offline() {
self.pick_relays().await;
}
// Separately subscribe to RelayList discovery for everyone we follow
// We just do this once at startup. Relay lists don't change that frequently.
let followed = GLOBALS.people.get_subscribed_pubkeys();
self.subscribe_discover(followed, None).await?;
// Separately subscribe to our outbox events on our write relays
let write_relay_urls: Vec<RelayUrl> = GLOBALS
.storage
.filter_relays(|r| r.has_usage_bits(Relay::WRITE) && r.rank != 0)?
.iter()
.map(|relay| relay.url.clone())
.collect();
for relay_url in write_relay_urls.iter() {
self.engage_minion(
relay_url.to_owned(),
vec![RelayJob {
reason: RelayConnectionReason::Config,
payload: ToMinionPayload {
job_id: rand::random::<u64>(),
detail: ToMinionPayloadDetail::SubscribeOutbox,
},
}],
)
.await?;
}
// Separately subscribe to our mentions on our read relays
// NOTE: we also do this on all dynamically connected relays since NIP-65 is
// not in widespread usage.
let read_relay_urls: Vec<RelayUrl> = GLOBALS
.storage
.filter_relays(|r| r.has_usage_bits(Relay::READ) && r.rank != 0)?
.iter()
.map(|relay| relay.url.clone())
.collect();
for relay_url in read_relay_urls.iter() {
self.engage_minion(
relay_url.to_owned(),
vec![RelayJob {
reason: RelayConnectionReason::FetchMentions,
payload: ToMinionPayload {
job_id: rand::random::<u64>(),
detail: ToMinionPayloadDetail::SubscribeMentions,
},
}],
)
.await?;
}
// Do the startup procedures
self.start_long_lived_subscriptions().await?;
'mainloop: loop {
if let Err(e) = self.loop_handler().await {
@ -684,6 +629,9 @@ impl Overlord {
ToOverlordMessage::SetDmChannel(dmchannel) => {
self.set_dm_channel(dmchannel).await?;
}
ToOverlordMessage::StartLongLivedSubscriptions => {
self.start_long_lived_subscriptions().await?;
}
ToOverlordMessage::SubscribeConfig(relay_url) => {
self.subscribe_config(relay_url).await?;
}
@ -2372,6 +2320,65 @@ impl Overlord {
Ok(())
}
/// This is done at startup and after the wizard.
pub async fn start_long_lived_subscriptions(&mut self) -> Result<(), Error> {
// Pick Relays and start Minions
if !GLOBALS.storage.read_setting_offline() {
self.pick_relays().await;
}
// Separately subscribe to RelayList discovery for everyone we follow
// We just do this once at startup. Relay lists don't change that frequently.
let followed = GLOBALS.people.get_subscribed_pubkeys();
self.subscribe_discover(followed, None).await?;
// Separately subscribe to our outbox events on our write relays
let write_relay_urls: Vec<RelayUrl> = GLOBALS
.storage
.filter_relays(|r| r.has_usage_bits(Relay::WRITE) && r.rank != 0)?
.iter()
.map(|relay| relay.url.clone())
.collect();
for relay_url in write_relay_urls.iter() {
self.engage_minion(
relay_url.to_owned(),
vec![RelayJob {
reason: RelayConnectionReason::Config,
payload: ToMinionPayload {
job_id: rand::random::<u64>(),
detail: ToMinionPayloadDetail::SubscribeOutbox,
},
}],
)
.await?;
}
// Separately subscribe to our mentions on our read relays
// NOTE: we also do this on all dynamically connected relays since NIP-65 is
// not in widespread usage.
let read_relay_urls: Vec<RelayUrl> = GLOBALS
.storage
.filter_relays(|r| r.has_usage_bits(Relay::READ) && r.rank != 0)?
.iter()
.map(|relay| relay.url.clone())
.collect();
for relay_url in read_relay_urls.iter() {
self.engage_minion(
relay_url.to_owned(),
vec![RelayJob {
reason: RelayConnectionReason::FetchMentions,
payload: ToMinionPayload {
job_id: rand::random::<u64>(),
detail: ToMinionPayloadDetail::SubscribeMentions,
},
}],
)
.await?;
}
Ok(())
}
/// Subscribe to the user's configuration events from the given relay
pub async fn subscribe_config(&mut self, relay_url: RelayUrl) -> Result<(), Error> {
self.engage_minion(

19
gossip.log.txt Normal file
View File

@ -0,0 +1,19 @@
2023-12-07T22:56:27.257056Z  INFO gossip-lib/src/filter.rs:43: Spam filter loaded.
2023-12-07T22:56:27.288275Z  INFO /home/mike/.cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.28.7/src/platform_impl/linux/x11/window.rs:156: Guessed window scale factor: 1.0416666666666667
2023-12-07T22:56:27.405842Z  INFO gossip-bin/src/ui/mod.rs:478: DPI (native): 75
2023-12-07T22:56:33.171088Z DEBUG gossip-lib/src/overlord/mod.rs:282: Picked wss://nostr-pub.wellorder.net/ covering 151 pubkeys
2023-12-07T22:56:33.171554Z DEBUG gossip-lib/src/overlord/mod.rs:282: Picked wss://nos.lol/ covering 152 pubkeys
2023-12-07T22:56:33.171745Z DEBUG gossip-lib/src/overlord/mod.rs:282: Picked wss://eden.nostr.land/ covering 1 pubkeys
2023-12-07T22:56:33.171772Z DEBUG gossip-lib/src/overlord/mod.rs:277: Done picking relays: All people accounted for.
2023-12-07T22:56:33.399922Z DEBUG gossip-lib/src/overlord/minion/mod.rs:133: wss://nostr.mikedilger.com/: Relay Information: Name="nostr-rs-relay" Description="Mike Dilger's archive relay, not for general use." Pubkey="ee11a5dff40c19a555f41fe42b48f00e618c91225622ae37b6c2bb67b76c4e49" Contact="mailto:mike@mikedilger.com" NIPS=[1, 2, 9, 11, 12, 15, 16, 20, 22, 33, 40, 42] Software="https://git.sr.ht/~gheartsfield/nostr-rs-relay" Version="0.8.9" Limitation="Relay Limitation: PaymentRequired="false"" id=""wss://nostr.mikedilger.com""
2023-12-07T22:56:33.523633Z DEBUG gossip-lib/src/overlord/minion/mod.rs:228: wss://nostr.mikedilger.com/: Connected
2023-12-07T22:56:33.525790Z DEBUG gossip-lib/src/overlord/minion/mod.rs:909: NEW SUBSCRIPTION on wss://nostr.mikedilger.com/ handle=config_feed, id=0
2023-12-07T22:56:33.602171Z DEBUG gossip-lib/src/process.rs:164: wss://nostr.mikedilger.com/: New Event: config_feed ContactList @1699940805
2023-12-07T22:56:34.067527Z DEBUG gossip-lib/src/overlord/minion/mod.rs:133: wss://nostr.wine/: Relay Information: Name="nostr.wine" Description="A paid nostr relay for wine enthusiasts and everyone else." Pubkey="4918eb332a41b71ba9a74b1dc64276cfff592e55107b93baae38af3520e55975" Contact="wino@nostr.wine" NIPS=[1, 2, 4, 9, 11, 12, 15, 16, 20, 22, 28, 33, 40, 42] Software="https://nostr.wine" Version="0.3.1" Limitation="Relay Limitation: MaxMessageLength="131072" MaxSubscriptions="50" MaxLimit="1000" MaxSubidLength="71" MaxEventTags="2000" MinPowDifficulty="0" AuthRequired="false" PaymentRequired="true"" PaymentsUrl=https://nostr.wine/invoices Fees=Relay Fees: Admission=[Fee=[18888000 msats Kinds="[]"] ],Subscription=[],Publication=[] icon=""https://image.nostr.build/dda8ffb9d8d87d34c7d0b0b9cf54a0466bfab69939b0c9a2bd430bac1540cadf.jpg""
2023-12-07T22:56:34.077020Z DEBUG gossip-lib/src/process.rs:164: wss://nostr.mikedilger.com/: New Event: config_feed Metadata @1700863736
2023-12-07T22:56:34.091929Z DEBUG gossip-lib/src/process.rs:164: wss://nostr.mikedilger.com/: New Event: config_feed FollowSets @1701213881
2023-12-07T22:56:34.443721Z DEBUG gossip-lib/src/overlord/minion/mod.rs:133: wss://offchain.pub/: Relay Information: Name="offchain.pub" Description="public nostr relay running strfry" Pubkey="6b1b35c6dee48851bac53a4494ca8f819503be00212dbceb899dc03acd7641db" Contact="admin@offchain.pub" NIPS=[1, 2, 4, 9, 11, 12, 16, 20, 22, 28, 33, 40] Software="git+https://github.com/hoytech/strfry.git" Version="0.9.6"
2023-12-07T22:56:34.511799Z DEBUG gossip-lib/src/overlord/minion/mod.rs:133: wss://nos.lol/: Relay Information: Name="nos.lol" Description="Generally accepts notes, except spammy ones." Contact="unset" NIPS=[1, 2, 4, 9, 11, 12, 16, 20, 22, 28, 33, 40] Software="git+https://github.com/hoytech/strfry.git" Version="0.9.6"
2023-12-07T22:56:34.667891Z DEBUG gossip-lib/src/overlord/minion/mod.rs:133: wss://purplepag.es/: Relay Information: Name="purplepag.es" Description="Nostr's Purple Pages" Pubkey="fa984bd7dbb282f07e16e7ae87b26a2a7b9b90b7246a44771f0cf5ae58018f52" Contact="pablof7z.com" NIPS=[1, 2, 4, 9, 11, 12, 16, 20, 22, 28, 33, 40] Software="git+https://github.com/hoytech/strfry.git" Version="0.9.6-7-g7196547"
2023-12-07T22:56:34.691831Z DEBUG gossip-lib/src/overlord/minion/mod.rs:228: wss://nostr.wine/: Connected
DEBUG: SAVING SETTINGS seeking a write txn...