Switch to FollowPubkey, deprecate FollowPubkeyAtRelay

This commit is contained in:
Mike Dilger 2023-09-24 16:20:16 +13:00
parent 51de6fc3d7
commit 461e9949a8
3 changed files with 10 additions and 54 deletions

View File

@ -23,7 +23,6 @@ pub enum ToOverlordMessage {
FetchEvent(Id, Vec<RelayUrl>),
FetchEventAddr(EventAddr),
FollowPubkey(PublicKey),
FollowPubkeyAndRelay(String, RelayUrl),
FollowNip05(String),
FollowNprofile(String),
GeneratePrivateKey(String),

View File

@ -609,9 +609,6 @@ impl Overlord {
ToOverlordMessage::FollowPubkey(pubkey) => {
self.follow_pubkey(pubkey).await?;
}
ToOverlordMessage::FollowPubkeyAndRelay(pubkeystr, relay) => {
self.follow_pubkey_and_relay(pubkeystr, relay).await?;
}
ToOverlordMessage::FollowNip05(nip05) => {
std::mem::drop(tokio::spawn(async move {
if let Err(e) = crate::nip05::get_and_follow_nip05(nip05).await {
@ -995,42 +992,6 @@ impl Overlord {
Ok(())
}
async fn follow_pubkey_and_relay(
&mut self,
pubkeystr: String,
relay: RelayUrl,
) -> Result<(), Error> {
let pubkey = match PublicKey::try_from_bech32_string(pubkeystr.trim(), true) {
Ok(pk) => pk,
Err(_) => PublicKey::try_from_hex_string(&pubkeystr, true)?,
};
GLOBALS.people.follow(&pubkey, true)?;
tracing::debug!("Followed {}", &pubkey.as_hex_string());
// Create relay if missing
GLOBALS.storage.write_relay_if_missing(&relay, None)?;
let now = Unixtime::now().unwrap().0 as u64;
// Save person_relay
let mut pr = match GLOBALS.storage.read_person_relay(pubkey, &relay)? {
Some(pr) => pr,
None => PersonRelay::new(pubkey, relay.clone()),
};
pr.last_suggested_kind3 = Some(now);
pr.manually_paired_read = true;
pr.manually_paired_write = true;
GLOBALS.storage.write_person_relay(&pr, None)?;
// async_follow added them to the relay tracker.
// Pick relays to start tracking them now
self.pick_relays().await;
tracing::info!("Setup 1 relay for {}", &pubkey.as_hex_string());
Ok(())
}
async fn post(
&mut self,
content: String,

View File

@ -3,7 +3,7 @@ use crate::comms::ToOverlordMessage;
use crate::globals::GLOBALS;
use eframe::egui;
use egui::{Context, Ui};
use nostr_types::RelayUrl;
use nostr_types::PublicKey;
pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
ui.add_space(30.0);
@ -56,32 +56,28 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
ui.separator();
ui.add_space(10.0);
ui.heading("Follow a public key at a relay");
ui.heading("Follow a public key");
ui.horizontal(|ui| {
ui.label("Enter public key");
ui.add(text_edit_line!(app, app.follow_pubkey).hint_text("npub1 or hex"));
});
ui.horizontal(|ui| {
ui.label("Enter a relay URL where we can find them");
ui.add(text_edit_line!(app, app.follow_pubkey_at_relay).hint_text("wss://..."));
});
if ui.button("follow").clicked() {
if let Ok(url) = RelayUrl::try_from_str(&app.follow_pubkey_at_relay) {
if let Ok(pubkey) = PublicKey::try_from_bech32_string(app.follow_pubkey.trim(), true) {
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::FollowPubkeyAndRelay(
app.follow_pubkey.clone(),
url,
));
app.follow_pubkey = "".to_owned();
app.follow_pubkey_at_relay = "".to_owned();
.send(ToOverlordMessage::FollowPubkey(pubkey));
} else if let Ok(pubkey) = PublicKey::try_from_hex_string(app.follow_pubkey.trim(), true) {
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::FollowPubkey(pubkey));
} else {
GLOBALS
.status_queue
.write()
.write("Invalid Relay Url".to_string());
.write("Invalid pubkey.".to_string());
}
app.follow_pubkey = "".to_owned();
}
ui.add_space(10.0);