add Accounts::add_advertised_relay
This commit is contained in:
@@ -589,6 +589,33 @@ impl Accounts {
|
|||||||
|
|
||||||
None
|
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> {
|
fn get_selected_index(accounts: &[UserAccount], keystore: &KeyStorageType) -> Option<usize> {
|
||||||
|
|||||||
@@ -291,7 +291,7 @@ fn render_nav_body(
|
|||||||
}
|
}
|
||||||
Route::Relays => {
|
Route::Relays => {
|
||||||
let manager = RelayPoolManager::new(ctx.pool);
|
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
|
None
|
||||||
}
|
}
|
||||||
Route::ComposeNote => {
|
Route::ComposeNote => {
|
||||||
|
|||||||
@@ -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 egui::{Align, Button, Frame, Id, Image, Layout, Margin, Rgba, RichText, Rounding, Ui, Vec2};
|
||||||
|
|
||||||
use enostr::RelayPool;
|
use enostr::RelayPool;
|
||||||
use notedeck::NotedeckTextStyle;
|
use notedeck::{Accounts, NotedeckTextStyle};
|
||||||
|
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
@@ -14,6 +14,7 @@ use super::add_column::sized_button;
|
|||||||
use super::padding;
|
use super::padding;
|
||||||
|
|
||||||
pub struct RelayView<'a> {
|
pub struct RelayView<'a> {
|
||||||
|
accounts: &'a mut Accounts,
|
||||||
manager: RelayPoolManager<'a>,
|
manager: RelayPoolManager<'a>,
|
||||||
id_string_map: &'a mut HashMap<Id, String>,
|
id_string_map: &'a mut HashMap<Id, String>,
|
||||||
}
|
}
|
||||||
@@ -40,16 +41,21 @@ impl View for RelayView<'_> {
|
|||||||
self.manager.remove_relays(indices);
|
self.manager.remove_relays(indices);
|
||||||
}
|
}
|
||||||
ui.add_space(8.0);
|
ui.add_space(8.0);
|
||||||
if let Some(add_relay) = self.show_add_relay_ui(ui) {
|
if let Some(relay_to_add) = self.show_add_relay_ui(ui) {
|
||||||
debug!("add relay \"{}\"", add_relay);
|
self.accounts.add_advertised_relay(&relay_to_add);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> RelayView<'a> {
|
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 {
|
RelayView {
|
||||||
|
accounts,
|
||||||
manager,
|
manager,
|
||||||
id_string_map,
|
id_string_map,
|
||||||
}
|
}
|
||||||
@@ -278,10 +284,15 @@ mod preview {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl App for RelayViewPreview {
|
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();
|
self.pool.try_recv();
|
||||||
let mut id_string_map = HashMap::new();
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user