Skip to content

Commit

Permalink
f: add missing remote subscriptions to existing relays
Browse files Browse the repository at this point in the history
  • Loading branch information
ksedgwic committed Nov 15, 2024
1 parent e6dc09c commit d093725
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/account_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct AccountRelayData {
}

impl AccountRelayData {
pub fn new(ndb: &Ndb, pubkey: &[u8; 32]) -> Self {
pub fn new(ndb: &Ndb, pool: &mut RelayPool, pubkey: &[u8; 32]) -> Self {
// Construct a filter for the user's NIP-65 relay list
let filter = Filter::new()
.authors([pubkey])
Expand Down Expand Up @@ -65,6 +65,9 @@ impl AccountRelayData {
// Id for future remote relay subscriptions
let subid = Uuid::new_v4().to_string();

// Add remote subscription to existing relays
pool.subscribe(subid.clone(), vec![filter.clone()]);

AccountRelayData {
filter,
subid,
Expand Down Expand Up @@ -104,7 +107,7 @@ pub struct AccountMutedData {
}

impl AccountMutedData {
pub fn new(ndb: &Ndb, pubkey: &[u8; 32]) -> Self {
pub fn new(ndb: &Ndb, pool: &mut RelayPool, pubkey: &[u8; 32]) -> Self {
// Construct a filter for the user's NIP-51 muted list
let filter = Filter::new()
.authors([pubkey])
Expand Down Expand Up @@ -132,6 +135,9 @@ impl AccountMutedData {
// Id for future remote relay subscriptions
let subid = Uuid::new_v4().to_string();

// Add remote subscription to existing relays
pool.subscribe(subid.clone(), vec![filter.clone()]);

AccountMutedData {
filter,
subid,
Expand Down Expand Up @@ -422,13 +428,13 @@ impl AccountManager {
(added, removed)
}

fn handle_added_account(&mut self, ndb: &Ndb, pubkey: &[u8; 32]) {
fn handle_added_account(&mut self, ndb: &Ndb, pool: &mut RelayPool, pubkey: &[u8; 32]) {
debug!("handle_added_account {}", hex::encode(pubkey));

// Create the user account data
let new_account_data = AccountData {
relay: AccountRelayData::new(ndb, pubkey),
muted: AccountMutedData::new(ndb, pubkey),
relay: AccountRelayData::new(ndb, pool, pubkey),
muted: AccountMutedData::new(ndb, pool, pubkey),
};
self.account_data.insert(*pubkey, new_account_data);
}
Expand Down Expand Up @@ -501,7 +507,7 @@ impl AccountManager {
let _ = pool.add_urls(add, wakeup);
}
if !sub.is_empty() {
debug!("removing configured relays: {:#?}", sub);
debug!("removing unwanted relays: {:#?}", sub);
pool.remove_urls(&sub);
}
}
Expand All @@ -521,7 +527,7 @@ impl AccountManager {
// Were any accounts added or removed?
let (added, removed) = self.delta_accounts();
for pk in added {
self.handle_added_account(ndb, &pk);
self.handle_added_account(ndb, pool, &pk);
relays_changed = true;
}
for pk in removed {
Expand Down

0 comments on commit d093725

Please sign in to comment.