Skip to content

Commit

Permalink
sdk: add reconcile_with_items method to Client
Browse files Browse the repository at this point in the history
Fix typo
  • Loading branch information
yukibtc committed Oct 23, 2023
1 parent e0ecbb5 commit c963cf7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion crates/nostr-sdk/examples/negentropy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async fn main() -> Result<()> {
.limit(10);
let relay = client.relay("wss://relay.damus.io").await?;
relay
.reconcilie(filter, my_items, Duration::from_secs(30))
.reconcile(filter, my_items, Duration::from_secs(30))
.await?;

client
Expand Down
19 changes: 16 additions & 3 deletions crates/nostr-sdk/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use nostr::types::metadata::Error as MetadataError;
use nostr::url::Url;
use nostr::{
ChannelId, ClientMessage, Contact, Entity, Event, EventBuilder, EventId, Filter, JsonUtil,
Keys, Kind, Metadata, Result, Tag,
Keys, Kind, Metadata, Result, Tag, Timestamp,
};
use nostr_sdk_db::DynNostrDatabase;
use nostr_sdk_net::futures_util::Future;
Expand Down Expand Up @@ -1283,8 +1283,21 @@ impl Client {
}

/// Negentropy reconciliation
pub async fn reconcilie(&self, filter: Filter, timeout: Duration) -> Result<(), Error> {
Ok(self.pool.reconcilie(filter, timeout).await?)
pub async fn reconcile(&self, filter: Filter, timeout: Duration) -> Result<(), Error> {
Ok(self.pool.reconcile(filter, timeout).await?)
}

/// Negentropy reconciliation with items
pub async fn reconcile_with_items(
&self,
filter: Filter,
items: Vec<(EventId, Timestamp)>,
timeout: Duration,
) -> Result<(), Error> {
Ok(self
.pool
.reconcile_with_items(filter, items, timeout)
.await?)
}

/// Get a list of channels
Expand Down
4 changes: 2 additions & 2 deletions crates/nostr-sdk/src/relay/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ impl Relay {
}

/// Negentropy reconciliation
pub async fn reconcilie(
pub async fn reconcile(
&self,
filter: Filter,
items: Vec<(EventId, Timestamp)>,
Expand Down Expand Up @@ -1585,7 +1585,7 @@ impl Relay {
let pk = Keys::generate();
let filter = Filter::new().author(pk.public_key().to_string());
match self
.reconcilie(filter, Vec::new(), Duration::from_secs(5))
.reconcile(filter, Vec::new(), Duration::from_secs(5))
.await
{
Ok(_) => Ok(true),
Expand Down
10 changes: 5 additions & 5 deletions crates/nostr-sdk/src/relay/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,13 +861,13 @@ impl RelayPool {
}

/// Negentropy reconciliation
pub async fn reconcilie(&self, filter: Filter, timeout: Duration) -> Result<(), Error> {
pub async fn reconcile(&self, filter: Filter, timeout: Duration) -> Result<(), Error> {
let items: Vec<(EventId, Timestamp)> = self.database.negentropy_items(&filter).await?;
self.reconcilie_with_items(filter, items, timeout).await
self.reconcile_with_items(filter, items, timeout).await
}

/// Negentropy reconciliation with custom items
pub async fn reconcilie_with_items(
pub async fn reconcile_with_items(
&self,
filter: Filter,
items: Vec<(EventId, Timestamp)>,
Expand All @@ -879,8 +879,8 @@ impl RelayPool {
let filter = filter.clone();
let my_items = items.clone();
let handle = thread::spawn(async move {
if let Err(e) = relay.reconcilie(filter, my_items, timeout).await {
tracing::error!("Failed to get reconcilie with {url}: {e}");
if let Err(e) = relay.reconcile(filter, my_items, timeout).await {
tracing::error!("Failed to get reconcile with {url}: {e}");
}
});
handles.push(handle);
Expand Down

0 comments on commit c963cf7

Please sign in to comment.