Skip to content

Commit 263f600

Browse files
committed
pool: add RelayPool::save_subscription
Closes #523 Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 881e302 commit 263f600

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
* nostr: add `Request::multi_pay_invoice` constructor ([Yuki Kishimoto])
5959
* nostr: add `Jsonutil::as_pretty_json` and `JsonUtil::try_as_pretty_json` methods ([Yuki Kishimoto])
6060
* pool: add `RelayPoolNotification::Authenticated` variant ([Yuki Kishimoto])
61+
* pool: add `RelayPool::save_subscription` ([Yuki Kishimoto])
6162
* sdk: add `Client::gift_wrap_to` and `Client::send_private_msg_to` ([reyamir])
6263
* sdk: add option to autoconnect relay on `Client::add_relay` method call ([Yuki Kishimoto])
6364
* sdk: add support to embedded tor client ([Yuki Kishimoto])

crates/nostr-relay-pool/src/pool/internal.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl InternalRelayPool {
122122
subscriptions.get(id).cloned()
123123
}
124124

125-
async fn update_pool_subscription(&self, id: SubscriptionId, filters: Vec<Filter>) {
125+
pub async fn save_subscription(&self, id: SubscriptionId, filters: Vec<Filter>) {
126126
let mut subscriptions = self.subscriptions.write().await;
127127
let current: &mut Vec<Filter> = subscriptions.entry(id).or_default();
128128
*current = filters;
@@ -459,9 +459,8 @@ impl InternalRelayPool {
459459
) -> Result<Output<()>, Error> {
460460
// Check if isn't auto-closing subscription
461461
if !opts.is_auto_closing() {
462-
// Update pool subscriptions
463-
self.update_pool_subscription(id.clone(), filters.clone())
464-
.await;
462+
// Save subscription
463+
self.save_subscription(id.clone(), filters.clone()).await;
465464
}
466465

467466
// Get relays

crates/nostr-relay-pool/src/pool/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,14 @@ impl RelayPool {
217217
self.inner.subscription(id).await
218218
}
219219

220+
/// Register subscription in the [RelayPool]
221+
///
222+
/// When a new relay will be added, saved subscriptions will be automatically used for it.
223+
#[inline]
224+
pub async fn save_subscription(&self, id: SubscriptionId, filters: Vec<Filter>) {
225+
self.inner.save_subscription(id, filters).await
226+
}
227+
220228
/// Send client message to all connected relays
221229
#[inline]
222230
pub async fn send_msg(

0 commit comments

Comments
 (0)