commit fe3e2dad14dd5d14eeb2e2e950ce51c13d9202c1
parent e436be400e12720f74e2943d145672c072a70e3c
Author: Ken Sedgwick <ken@bonsai.com>
Date: Tue, 21 Jan 2025 16:03:44 -0800
add Accounts::add_advertised_relay
Diffstat:
3 files changed, 45 insertions(+), 7 deletions(-)
diff --git a/crates/notedeck/src/accounts.rs b/crates/notedeck/src/accounts.rs
@@ -589,6 +589,33 @@ impl Accounts {
None
}
+
+ pub fn add_advertised_relay(&mut self, relay_to_add: &str) {
+ info!("add advertised relay \"{}\"", relay_to_add);
+ match self.currently_selected_account {
+ None => error!("no account is currently selected."),
+ Some(index) => match self.accounts.get(index) {
+ None => error!("selected account index {} is out of range.", index),
+ Some(keypair) => {
+ let key_bytes: [u8; 32] = *keypair.pubkey.bytes();
+ match self.account_data.get_mut(&key_bytes) {
+ None => error!("no account data found for the provided key."),
+ Some(account_data) => {
+ let advertised = &mut account_data.relay.advertised;
+ if advertised.is_empty() {
+ // If the selected account has no advertised relays
+ // iniitialize with the bootstrapping set.
+ advertised.extend(self.bootstrap_relays.iter().cloned());
+ }
+ advertised.insert(relay_to_add.to_string());
+ self.needs_relay_config = true;
+ // FIXME - need to publish the advertised set
+ }
+ }
+ }
+ },
+ }
+ }
}
fn get_selected_index(accounts: &[UserAccount], keystore: &KeyStorageType) -> Option<usize> {
diff --git a/crates/notedeck_columns/src/nav.rs b/crates/notedeck_columns/src/nav.rs
@@ -291,7 +291,7 @@ fn render_nav_body(
}
Route::Relays => {
let manager = RelayPoolManager::new(ctx.pool);
- RelayView::new(manager, &mut app.view_state.id_string_map).ui(ui);
+ RelayView::new(ctx.accounts, manager, &mut app.view_state.id_string_map).ui(ui);
None
}
Route::ComposeNote => {
diff --git a/crates/notedeck_columns/src/ui/relay.rs b/crates/notedeck_columns/src/ui/relay.rs
@@ -6,7 +6,7 @@ use crate::ui::{Preview, PreviewConfig, View};
use egui::{Align, Button, Frame, Id, Image, Layout, Margin, Rgba, RichText, Rounding, Ui, Vec2};
use enostr::RelayPool;
-use notedeck::NotedeckTextStyle;
+use notedeck::{Accounts, NotedeckTextStyle};
use tracing::debug;
@@ -14,6 +14,7 @@ use super::add_column::sized_button;
use super::padding;
pub struct RelayView<'a> {
+ accounts: &'a mut Accounts,
manager: RelayPoolManager<'a>,
id_string_map: &'a mut HashMap<Id, String>,
}
@@ -40,16 +41,21 @@ impl View for RelayView<'_> {
self.manager.remove_relays(indices);
}
ui.add_space(8.0);
- if let Some(add_relay) = self.show_add_relay_ui(ui) {
- debug!("add relay \"{}\"", add_relay);
+ if let Some(relay_to_add) = self.show_add_relay_ui(ui) {
+ self.accounts.add_advertised_relay(&relay_to_add);
}
});
}
}
impl<'a> RelayView<'a> {
- pub fn new(manager: RelayPoolManager<'a>, id_string_map: &'a mut HashMap<Id, String>) -> Self {
+ pub fn new(
+ accounts: &'a mut Accounts,
+ manager: RelayPoolManager<'a>,
+ id_string_map: &'a mut HashMap<Id, String>,
+ ) -> Self {
RelayView {
+ accounts,
manager,
id_string_map,
}
@@ -278,10 +284,15 @@ mod preview {
}
impl App for RelayViewPreview {
- fn update(&mut self, _app: &mut AppContext<'_>, ui: &mut egui::Ui) {
+ fn update(&mut self, app: &mut AppContext<'_>, ui: &mut egui::Ui) {
self.pool.try_recv();
let mut id_string_map = HashMap::new();
- RelayView::new(RelayPoolManager::new(&mut self.pool), &mut id_string_map).ui(ui);
+ RelayView::new(
+ app.accounts,
+ RelayPoolManager::new(&mut self.pool),
+ &mut id_string_map,
+ )
+ .ui(ui);
}
}