Skip to content

Commit

Permalink
pool: add RelayPool::save_subscription
Browse files Browse the repository at this point in the history
Closes rust-nostr#523

Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Aug 7, 2024
1 parent 881e302 commit 263f600
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
7 changes: 3 additions & 4 deletions crates/nostr-relay-pool/src/pool/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl InternalRelayPool {
subscriptions.get(id).cloned()
}

async fn update_pool_subscription(&self, id: SubscriptionId, filters: Vec<Filter>) {
pub async fn save_subscription(&self, id: SubscriptionId, filters: Vec<Filter>) {
let mut subscriptions = self.subscriptions.write().await;
let current: &mut Vec<Filter> = subscriptions.entry(id).or_default();
*current = filters;
Expand Down Expand Up @@ -459,9 +459,8 @@ impl InternalRelayPool {
) -> Result<Output<()>, 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
Expand Down
8 changes: 8 additions & 0 deletions crates/nostr-relay-pool/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Filter>) {
self.inner.save_subscription(id, filters).await
}

/// Send client message to all connected relays
#[inline]
pub async fn send_msg(
Expand Down

0 comments on commit 263f600

Please sign in to comment.