From 040cf3b301eda2c592afc601221f315c0ecbe8ee Mon Sep 17 00:00:00 2001 From: Yuki Kishimoto Date: Thu, 12 Oct 2023 14:29:29 +0200 Subject: [PATCH] db: add `event_id_already_seen` method --- crates/nostr-sdk-db/src/lib.rs | 3 +++ crates/nostr-sdk-db/src/memory.rs | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/crates/nostr-sdk-db/src/lib.rs b/crates/nostr-sdk-db/src/lib.rs index e10466dd4..24616611f 100644 --- a/crates/nostr-sdk-db/src/lib.rs +++ b/crates/nostr-sdk-db/src/lib.rs @@ -45,6 +45,9 @@ pub trait NostrDatabase: AsyncTraitDeps { /// Save [`Event`] into store async fn save_event(&self, event: &Event) -> Result<(), Self::Err>; + /// Check if [`EventId`] was already seen + async fn event_id_already_seen(&self, event_id: EventId) -> Result; + /// Save [`EventId`] seen by relay /// /// Useful for NIP65 (gossip) diff --git a/crates/nostr-sdk-db/src/memory.rs b/crates/nostr-sdk-db/src/memory.rs index 2119f6a6a..bc20380b5 100644 --- a/crates/nostr-sdk-db/src/memory.rs +++ b/crates/nostr-sdk-db/src/memory.rs @@ -48,6 +48,11 @@ impl NostrDatabase for MemoryDatabase { Ok(()) } + async fn event_id_already_seen(&self, event_id: EventId) -> Result { + let seen_event_ids = self.seen_event_ids.read().await; + Ok(seen_event_ids.contains_key(&event_id)) + } + async fn save_event_id_seen_by_relay( &self, event_id: EventId,