Skip to content

Commit

Permalink
Generate and publish blossom servers on button-press
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedilger committed Nov 22, 2024
1 parent e6a2b4b commit a2f6730
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
8 changes: 8 additions & 0 deletions gossip-bin/src/ui/settings/posting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use crate::ui::GossipUi;
use eframe::egui;
use egui::widgets::Slider;
use egui::{Context, TextEdit, Ui};
use gossip_lib::comms::ToOverlordMessage;
use gossip_lib::GLOBALS;

pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Frame, ui: &mut Ui) {
ui.heading("Posting Settings");
Expand Down Expand Up @@ -40,5 +42,11 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
);
});

if ui.button("Publish Blossom Servers").clicked() {
let _ = GLOBALS
.to_overlord
.send(ToOverlordMessage::PushBlossomServers);
};

ui.add_space(20.0);
}
6 changes: 6 additions & 0 deletions gossip-lib/src/comms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ pub enum ToOverlordMessage {
/// Calls [prune_unused_people](crate::Overlord::prune_unused_people)
PruneUnusedPeople,

/// Calls [push_blossom_servers](crate::Overlord::push_blossom_servers)
PushBlossomServers,

/// Calls [push_person_list](crate::Overlord::push_person_list)
PushPersonList(PersonList),

Expand Down Expand Up @@ -299,6 +302,7 @@ pub enum RelayConnectionReason {
Follow,
Giftwraps,
NostrConnect,
PostBlossomServers,
PostEvent,
PostContacts,
PostLike,
Expand Down Expand Up @@ -331,6 +335,7 @@ impl RelayConnectionReason {
Follow => "Following the posts of people in our Contact List",
Giftwraps => "Fetch giftwraps addressed to you",
NostrConnect => "Nostr connect",
PostBlossomServers => "Posting blossom servers",
PostEvent => "Posting an event",
Advertising => "Advertising our relay list",
PostLike => "Posting a reaction to an event",
Expand Down Expand Up @@ -358,6 +363,7 @@ impl RelayConnectionReason {
Follow => true,
Giftwraps => true,
NostrConnect => true,
PostBlossomServers => false,
PostEvent => false,
Advertising => false,
PostLike => false,
Expand Down
41 changes: 41 additions & 0 deletions gossip-lib/src/overlord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,9 @@ impl Overlord {
ToOverlordMessage::PruneUnusedPeople => {
Self::prune_unused_people()?;
}
ToOverlordMessage::PushBlossomServers => {
self.push_blossom_servers().await?;
}
ToOverlordMessage::PushPersonList(person_list) => {
self.push_person_list(person_list).await?;
}
Expand Down Expand Up @@ -2021,6 +2024,44 @@ impl Overlord {
Ok(())
}

pub async fn push_blossom_servers(&mut self) -> Result<(), Error> {
let public_key = match GLOBALS.identity.public_key() {
Some(pk) => pk,
None => return Err((ErrorKind::NoPrivateKey, file!(), line!()).into()), // not even a public key
};

let mut tags: Vec<Tag> = Vec::new();
let blossom_servers = GLOBALS.db().read_setting_blossom_servers();
for server in blossom_servers.split_whitespace() {
tags.push(Tag::new(&["server", &server]));
}

let pre_event = PreEvent {
pubkey: public_key,
created_at: Unixtime::now(),
kind: EventKind::UserServerList,
tags,
content: "".to_string(),
};

let event = GLOBALS.identity.sign_event(pre_event)?;

let config_relays: Vec<RelayUrl> = Relay::choose_relay_urls(Relay::WRITE, |_| true)?;

manager::run_jobs_on_all_relays(
config_relays,
vec![RelayJob {
reason: RelayConnectionReason::PostBlossomServers,
payload: ToMinionPayload {
job_id: rand::random::<u64>(),
detail: ToMinionPayloadDetail::PostEvents(vec![event.clone()]),
},
}],
);

Ok(())
}

/// Publish the user's specified PersonList
pub async fn push_person_list(&mut self, list: PersonList) -> Result<(), Error> {
let metadata = match GLOBALS.db().get_person_list_metadata(list)? {
Expand Down

0 comments on commit a2f6730

Please sign in to comment.