diff --git a/CHANGELOG.md b/CHANGELOG.md index baa71f471..80236fb01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ * nostr: add `Request::multi_pay_invoice` constructor ([Yuki Kishimoto]) * nostr: add `Jsonutil::as_pretty_json` and `JsonUtil::try_as_pretty_json` methods ([Yuki Kishimoto]) * pool: add `RelayPoolNotification::Authenticated` variant ([Yuki Kishimoto]) +* pool: add `RelayPool::save_subscription` ([Yuki Kishimoto]) * sdk: add `Client::gift_wrap_to` and `Client::send_private_msg_to` ([reyamir]) * sdk: add option to autoconnect relay on `Client::add_relay` method call ([Yuki Kishimoto]) * sdk: add support to embedded tor client ([Yuki Kishimoto]) diff --git a/crates/nostr-relay-pool/src/pool/internal.rs b/crates/nostr-relay-pool/src/pool/internal.rs index 7af9432d3..7370ef369 100644 --- a/crates/nostr-relay-pool/src/pool/internal.rs +++ b/crates/nostr-relay-pool/src/pool/internal.rs @@ -122,7 +122,7 @@ impl InternalRelayPool { subscriptions.get(id).cloned() } - async fn update_pool_subscription(&self, id: SubscriptionId, filters: Vec) { + pub async fn save_subscription(&self, id: SubscriptionId, filters: Vec) { let mut subscriptions = self.subscriptions.write().await; let current: &mut Vec = subscriptions.entry(id).or_default(); *current = filters; @@ -459,9 +459,8 @@ impl InternalRelayPool { ) -> Result, Error> { // Check if isn't auto-closing subscription if !opts.is_auto_closing() { - // Update pool subscriptions - self.update_pool_subscription(id.clone(), filters.clone()) - .await; + // Save subscription + self.save_subscription(id.clone(), filters.clone()).await; } // Get relays diff --git a/crates/nostr-relay-pool/src/pool/mod.rs b/crates/nostr-relay-pool/src/pool/mod.rs index 103c5a965..2a8446eb2 100644 --- a/crates/nostr-relay-pool/src/pool/mod.rs +++ b/crates/nostr-relay-pool/src/pool/mod.rs @@ -217,6 +217,14 @@ impl RelayPool { self.inner.subscription(id).await } + /// Register subscription in the [RelayPool] + /// + /// When a new relay will be added, saved subscriptions will be automatically used for it. + #[inline] + pub async fn save_subscription(&self, id: SubscriptionId, filters: Vec) { + self.inner.save_subscription(id, filters).await + } + /// Send client message to all connected relays #[inline] pub async fn send_msg(