fix: init new relays with previous subscriptions
This commit is contained in:
parent
af14e1c47b
commit
811bfdc45a
3 changed files with 12 additions and 14 deletions
|
|
@ -20,9 +20,9 @@ class NostrClient:
|
|||
if connect:
|
||||
self.connect()
|
||||
|
||||
async def connect(self, subscriptions: dict[str, Subscription] = {}):
|
||||
async def connect(self):
|
||||
for relay in self.relays:
|
||||
self.relay_manager.add_relay(relay, subscriptions)
|
||||
self.relay_manager.add_relay(relay)
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
from asyncio import Lock
|
||||
import ssl
|
||||
import threading
|
||||
|
||||
|
|
@ -19,17 +18,18 @@ class RelayManager:
|
|||
self.threads: dict[str, threading.Thread] = {}
|
||||
self.queue_threads: dict[str, threading.Thread] = {}
|
||||
self.message_pool = MessagePool()
|
||||
self._cached_subscriptions = dict[str, Subscription] = {}
|
||||
self._subscriptions_lock = Lock()
|
||||
self._cached_subscriptions: dict[str, Subscription] = {}
|
||||
self._subscriptions_lock = threading.Lock()
|
||||
|
||||
def add_relay(
|
||||
self, url: str, read: bool = True, write: bool = True, subscriptions: dict[str, Subscription] = {}
|
||||
) -> Relay:
|
||||
def add_relay(self, url: str, read: bool = True, write: bool = True) -> Relay:
|
||||
if url in self.relays:
|
||||
return
|
||||
|
||||
with self._subscriptions_lock:
|
||||
subscriptions = self._cached_subscriptions.copy()
|
||||
|
||||
policy = RelayPolicy(read, write)
|
||||
relay = Relay(url, policy, self.message_pool, subscriptions.copy())
|
||||
relay = Relay(url, policy, self.message_pool, subscriptions)
|
||||
self.relays[url] = relay
|
||||
|
||||
self.open_connection(
|
||||
|
|
|
|||
|
|
@ -60,10 +60,8 @@ async def api_add_relay(relay: Relay) -> Optional[RelayList]:
|
|||
relay.id = urlsafe_short_hash()
|
||||
await add_relay(relay)
|
||||
|
||||
all_relays: List[NostrRelay] = nostr.client.relay_manager.relays.values()
|
||||
if len(all_relays):
|
||||
nostr.client.relays.append(relay.url)
|
||||
nostr.client.relay_manager.add_relay()
|
||||
nostr.client.relays.append(relay.url)
|
||||
nostr.client.relay_manager.add_relay(relay.url)
|
||||
|
||||
|
||||
return await get_relays()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue