mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-29 00:11:01 +00:00
Method to manually add a relay for a person
This commit is contained in:
parent
6e597ae72e
commit
ad499f565d
@ -7,6 +7,7 @@ use std::fmt;
|
||||
/// This is a message sent to the Overlord
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ToOverlordMessage {
|
||||
AddPubkeyRelay(PublicKey, RelayUrl),
|
||||
AddRelay(RelayUrl),
|
||||
AdjustRelayUsageBit(RelayUrl, u64, bool),
|
||||
AdvertiseRelayList,
|
||||
|
@ -493,6 +493,9 @@ impl Overlord {
|
||||
|
||||
async fn handle_message(&mut self, message: ToOverlordMessage) -> Result<bool, Error> {
|
||||
match message {
|
||||
ToOverlordMessage::AddPubkeyRelay(pubkey, relayurl) => {
|
||||
self.add_pubkey_relay(pubkey, relayurl).await?;
|
||||
}
|
||||
ToOverlordMessage::AddRelay(relay_url) => {
|
||||
// Create relay if missing
|
||||
GLOBALS.storage.write_relay_if_missing(&relay_url, None)?;
|
||||
@ -918,6 +921,23 @@ impl Overlord {
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
async fn add_pubkey_relay(&mut self, pubkey: PublicKey, relay: RelayUrl) -> Result<(), Error> {
|
||||
// Save person_relay
|
||||
let mut pr = match GLOBALS.storage.read_person_relay(pubkey, &relay)? {
|
||||
Some(pr) => pr,
|
||||
None => PersonRelay::new(pubkey, relay.clone()),
|
||||
};
|
||||
let now = Unixtime::now().unwrap().0 as u64;
|
||||
pr.last_suggested_kind3 = Some(now); // not kind3, but we have no other field for this
|
||||
pr.manually_paired_read = true;
|
||||
pr.manually_paired_write = true;
|
||||
GLOBALS.storage.write_person_relay(&pr, None)?;
|
||||
|
||||
self.pick_relays().await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn maybe_disconnect_relay(&mut self, url: &RelayUrl) -> Result<(), Error> {
|
||||
if let Some(refmut) = GLOBALS.connected_relays.get_mut(url) {
|
||||
// If no job remains, disconnect the relay
|
||||
|
@ -6,7 +6,7 @@ use crate::ui::widgets::CopyButton;
|
||||
use crate::AVATAR_SIZE_F32;
|
||||
use eframe::egui;
|
||||
use egui::{Context, Frame, RichText, ScrollArea, TextEdit, Ui, Vec2};
|
||||
use nostr_types::PublicKey;
|
||||
use nostr_types::{PublicKey, RelayUrl};
|
||||
use serde_json::Value;
|
||||
|
||||
pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
|
||||
@ -258,6 +258,26 @@ fn content(app: &mut GossipUi, ctx: &Context, ui: &mut Ui, pubkey: PublicKey, pe
|
||||
for (relay_url, score) in relays.iter() {
|
||||
ui.label(format!("{} (score={})", relay_url, score));
|
||||
}
|
||||
|
||||
// Add a relay for them
|
||||
ui.add_space(10.0);
|
||||
ui.label("Manually specify a relay they use (read and write):");
|
||||
ui.horizontal(|ui| {
|
||||
ui.add(text_edit_line!(app, app.follow_pubkey_at_relay).hint_text("wss://..."));
|
||||
if ui.button("Add").clicked() {
|
||||
if let Ok(url) = RelayUrl::try_from_str(&app.follow_pubkey_at_relay) {
|
||||
let _ = GLOBALS
|
||||
.to_overlord
|
||||
.send(ToOverlordMessage::AddPubkeyRelay(pubkey, url));
|
||||
app.follow_pubkey_at_relay = "".to_owned();
|
||||
} else {
|
||||
GLOBALS
|
||||
.status_queue
|
||||
.write()
|
||||
.write("Invalid Relay Url".to_string());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
if need_to_set_active_person && !app.setting_active_person {
|
||||
|
Loading…
Reference in New Issue
Block a user