Skip to content

Commit

Permalink
sdk: fix RelayPoolNotification::Event not sent
Browse files Browse the repository at this point in the history
  • Loading branch information
yukibtc committed Nov 14, 2023
1 parent 53962ec commit 2a6212a
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions crates/nostr-sdk/src/relay/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,25 +172,6 @@ impl RelayPoolTask {
);

match msg {
RelayMessage::Event { event, .. } => {
// Check if event was already seen
match this.database.has_event_already_been_seen(event.id).await
{
Ok(seen) => {
if !seen {
let _ =
this.notification_sender.send(RelayPoolNotification::Event(
relay_url,
*event.clone(),
));
}
}
Err(e) => tracing::error!(
"Impossible to check if event {} was already seen: {e}",
event.id
),
}
}
RelayMessage::Notice { message } => {
tracing::warn!("Notice from {relay_url}: {message}")
}
Expand Down Expand Up @@ -258,10 +239,16 @@ impl RelayPoolTask {
// Deserialize partial event (id, pubkey and sig)
let partial_event: PartialEvent = PartialEvent::from_json(event.to_string())?;

// Check if event id was already seen
let seen: bool = self
.database
.has_event_already_been_seen(partial_event.id)
.await?;

// Set event as seen by relay
if let Err(e) = self
.database
.event_id_seen(partial_event.id, relay_url)
.event_id_seen(partial_event.id, relay_url.clone())
.await
{
tracing::error!(
Expand All @@ -276,7 +263,7 @@ impl RelayPoolTask {
.has_event_already_been_saved(partial_event.id)
.await?
{
tracing::trace!("Event {} already saved into database", partial_event.id);
tracing::warn!("Event {} already saved into database", partial_event.id);
return Ok(None);
}

Expand All @@ -301,6 +288,13 @@ impl RelayPoolTask {
// Save event
self.database.save_event(&event).await?;

// If not seed, send RelayPoolNotification::Event
if !seen {
let _ = self
.notification_sender
.send(RelayPoolNotification::Event(relay_url, event.clone()));
}

// Compose RelayMessage
Ok(Some(RelayMessage::Event {
subscription_id: SubscriptionId::new(subscription_id),
Expand Down

0 comments on commit 2a6212a

Please sign in to comment.