Skip to content

Commit

Permalink
Merge pull request #56 from nodetec/cleanup
Browse files Browse the repository at this point in the history
refactor: NostrModule::get_state() takes self as arg
  • Loading branch information
tvolk131 authored Oct 13, 2024
2 parents b844ad4 + c121c46 commit 84c2330
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/nostr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl NostrModule {
pub fn subscription(&self) -> Subscription<NostrState> {
const POLL_DURATION: Duration = Duration::from_millis(200);

let client = self.client.clone();
let self_clone = self.clone();

Subscription::run_with_id(
std::any::TypeId::of::<NostrState>(),
Expand All @@ -57,7 +57,7 @@ impl NostrModule {
async_stream::stream! {
let mut last_state = NostrState::default();
loop {
let new_state = Self::get_state(&client).await;
let new_state = self_clone.get_state().await;
if new_state != last_state {
yield new_state.clone();
last_state = new_state;
Expand All @@ -72,10 +72,10 @@ impl NostrModule {
/// Fetches the current state of the Nostr SDK client.
/// Note: This is async because it's grabbing read locks
/// on the relay `RwLock`s. No network requests are made.
async fn get_state(client: &nostr_sdk::Client) -> NostrState {
async fn get_state(&self) -> NostrState {
let mut relay_connections = BTreeMap::new();

for (url, relay) in client.relays().await {
for (url, relay) in self.client.relays().await {
relay_connections.insert(url.clone(), relay.status().await);
}

Expand Down

0 comments on commit 84c2330

Please sign in to comment.