diff --git a/src/account_manager.rs b/src/account_manager.rs index c71b767d..7bc95573 100644 --- a/src/account_manager.rs +++ b/src/account_manager.rs @@ -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]) @@ -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, @@ -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]) @@ -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, @@ -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); } @@ -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); } } @@ -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 {