Command to post nip46 server results

This commit is contained in:
Mike Dilger 2024-01-26 09:01:57 +13:00
parent 43cf37b6f2
commit 8eda848746
2 changed files with 34 additions and 0 deletions

View File

@ -101,6 +101,9 @@ pub enum ToOverlordMessage {
dm_channel: Option<DmChannel>,
},
/// Calls [post_nip46_event](crate::Overlord::post_nip46_event)
PostNip46Event(Event, Vec<RelayUrl>),
/// Calls [prune_cache](crate::Overlord::prune_cache)
PruneCache,
@ -255,6 +258,7 @@ pub enum RelayConnectionReason {
PostLike,
PostMetadata,
PostMuteList,
PostNostrConnect,
ReadThread,
SubscribePerson,
}
@ -285,6 +289,7 @@ impl RelayConnectionReason {
PostContacts => "Posting our contact list",
PostMuteList => "Posting our mute list",
PostMetadata => "Posting our metadata",
PostNostrConnect => "Posting nostrconnect",
ReadThread => "Reading ancestors to build a thread",
SubscribePerson => "Subscribe to the events of a person",
}
@ -308,6 +313,7 @@ impl RelayConnectionReason {
PostContacts => false,
PostMuteList => false,
PostMetadata => false,
PostNostrConnect => false,
ReadThread => true,
SubscribePerson => false,
}

View File

@ -622,6 +622,9 @@ impl Overlord {
} => {
self.post(content, tags, in_reply_to, dm_channel).await?;
}
ToOverlordMessage::PostNip46Event(event, relays) => {
self.post_nip46_event(event, relays).await?;
}
ToOverlordMessage::PruneCache => {
Self::prune_cache().await?;
}
@ -1873,6 +1876,31 @@ impl Overlord {
Ok(())
}
pub async fn post_nip46_event(
&mut self,
event: Event,
relays: Vec<RelayUrl>,
) -> Result<(), Error> {
for url in relays {
// Send it the event to post
tracing::debug!("Asking {} to post nostrconnect", &url);
self.engage_minion(
url.clone(),
vec![RelayJob {
reason: RelayConnectionReason::PostNostrConnect,
payload: ToMinionPayload {
job_id: rand::random::<u64>(),
detail: ToMinionPayloadDetail::PostEvent(Box::new(event.clone())),
},
}],
)
.await?;
}
Ok(())
}
/// Prune the cache (downloaded files)
pub async fn prune_cache() -> Result<(), Error> {
GLOBALS