refactor: add_relay logic
This commit is contained in:
parent
d08e91b2c7
commit
09d2fc0493
5 changed files with 61 additions and 61 deletions
20
tasks.py
20
tasks.py
|
|
@ -17,31 +17,13 @@ from .services import (
|
|||
|
||||
|
||||
async def init_relays():
|
||||
# we save any subscriptions teporarily to re-add them after reinitializing the client
|
||||
subscriptions = {}
|
||||
for relay in nostr.client.relay_manager.relays.values():
|
||||
# relay.add_subscription(id, filters)
|
||||
for subscription_id, filters in relay.subscriptions.items():
|
||||
subscriptions[subscription_id] = filters
|
||||
|
||||
# reinitialize the entire client
|
||||
nostr.__init__()
|
||||
# get relays from db
|
||||
relays = await get_relays()
|
||||
# set relays and connect to them
|
||||
nostr.client.relays = list(set([r.url for r in relays.__root__ if r.url]))
|
||||
nostr.client.connect()
|
||||
|
||||
await asyncio.sleep(2)
|
||||
# re-add subscriptions
|
||||
for subscription_id, subscription in subscriptions.items():
|
||||
nostr.client.relay_manager.add_subscription(
|
||||
subscription_id, subscription.filters
|
||||
)
|
||||
s = subscription.to_json_object()
|
||||
json_str = json.dumps(["REQ", s["id"], s["filters"][0]])
|
||||
nostr.client.relay_manager.publish_message(json_str)
|
||||
return
|
||||
await nostr.client.connect()
|
||||
|
||||
|
||||
async def subscribe_events():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue