chore: Add the relays for read and write

Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb
2025-05-06 12:15:12 +00:00
parent c0a5e47793
commit 93c8743dc7
3 changed files with 11 additions and 13 deletions

View File

@@ -72,6 +72,8 @@ impl CommandRunner for AnnounceArgs {
let mut write_relays = options.relays.clone();
let mut maintainers = vec![user_pubk];
write_relays.sort_unstable();
write_relays.dedup();
maintainers.extend(self.maintainers);
if let Some(event) = relays_list.clone() {
@@ -99,7 +101,7 @@ impl CommandRunner for AnnounceArgs {
let result = client
.send_event_to(event, relays_list.as_ref(), write_relays)
.send_event_to(event, relays_list.as_ref(), &write_relays)
.await?;
for relay in &result.success {

View File

@@ -37,7 +37,7 @@ impl CommandRunner for ViewArgs {
async fn run(self, options: CliOptions) -> N34Result<()> {
let client = NostrClient::init(&options).await;
if !self.naddr.relays.is_empty() {
client.add_read_relays(&self.naddr.relays).await;
client.add_relays(&self.naddr.relays).await;
}
let repo = client.fetch_repo(&self.naddr).await?;

View File

@@ -65,15 +65,15 @@ impl NostrClient {
.build(),
);
client.add_read_relays(&options.relays).await;
client.add_relays(&options.relays).await;
client
}
/// Add read relays and connect to them
pub async fn add_read_relays(&self, relays: &[RelayUrl]) {
/// Add relays and connect to them
pub async fn add_relays(&self, relays: &[RelayUrl]) {
for relay in relays {
self.client
.add_read_relay(relay)
.add_relay(relay)
.await
.expect("It's a valid relay url");
if let Err(err) = self.client.try_connect_relay(relay, CLIENT_TIMEOUT).await {
@@ -87,16 +87,12 @@ impl NostrClient {
&self,
event: UnsignedEvent,
relays_list: Option<&Event>,
mut relays: Vec<RelayUrl>,
relays: &[RelayUrl],
) -> N34Result<Output<EventId>> {
relays.sort_unstable();
relays.dedup();
for relay in &relays {
let _ = self.client.add_write_relay(relay).await;
}
self.add_relays(relays).await;
if let Some(event) = relays_list {
let _ = self.client.send_event_to(&relays, event).await;
let _ = self.client.send_event_to(relays, event).await;
}
self.client
.send_event_to(relays, &event.sign(&self.client.signer().await?).await?)