kopia lustrzana https://github.com/snarfed/bridgy-fed
nostr: misc minor bug fixes, tweaks, comments
rodzic
db7a71e720
commit
a4a5166059
7
nostr.py
7
nostr.py
|
|
@ -52,7 +52,7 @@ logger = logging.getLogger(__name__)
|
|||
class Nostr(User, Protocol):
|
||||
"""Nostr class.
|
||||
|
||||
Key id is bech32 npub id, without nostr: prefix.
|
||||
Key id is NIP-21 nostr:npub... bech32 npub URI.
|
||||
https://github.com/nostr-protocol/nips/blob/master/19.md
|
||||
"""
|
||||
ABBREV = 'nostr'
|
||||
|
|
@ -80,7 +80,7 @@ class Nostr(User, Protocol):
|
|||
|
||||
def _pre_put_hook(self):
|
||||
"""Validates that the id is a bech32-encoded nostr:npub id."""
|
||||
assert self.key.id().startswith('nostr:npub')
|
||||
assert self.key.id().startswith('nostr:npub'), self.key.id()
|
||||
return super()._pre_put_hook()
|
||||
|
||||
def hex_pubkey(self):
|
||||
|
|
@ -128,9 +128,6 @@ class Nostr(User, Protocol):
|
|||
return granary.nostr.Nostr.user_url(
|
||||
self.obj_key.id().removeprefix("nostr:"))
|
||||
|
||||
def id_uri(self):
|
||||
return f'nostr:{self.key.id()}'
|
||||
|
||||
@classmethod
|
||||
def owns_id(cls, id):
|
||||
return id.startswith('nostr:') or bool(granary.nostr.is_bech32(id))
|
||||
|
|
|
|||
14
nostr_hub.py
14
nostr_hub.py
|
|
@ -43,6 +43,7 @@ bridged_pubkeys = set()
|
|||
bridged_loaded_at = datetime(1900, 1, 1)
|
||||
pubkeys_initialized = Event()
|
||||
|
||||
# string relay websocket adddress URIs
|
||||
subscribed_relays = []
|
||||
subscribed_relays_lock = Lock()
|
||||
|
||||
|
|
@ -70,6 +71,7 @@ def _load_users():
|
|||
loaded_at = util.now().replace(tzinfo=None)
|
||||
|
||||
new_nostr = Nostr.query(Nostr.status == None,
|
||||
Nostr.enabled_protocols != None,
|
||||
Nostr.updated > nostr_loaded_at,
|
||||
).fetch()
|
||||
Nostr.load_multi(new_nostr)
|
||||
|
|
@ -109,7 +111,11 @@ def _load_users():
|
|||
|
||||
|
||||
def add_relay(relay):
|
||||
"""Subscribes to a new relay if we're not already connected to it."""
|
||||
"""Subscribes to a new relay if we're not already connected to it.
|
||||
|
||||
Args:
|
||||
relay (str): URI, relay websocket adddress, starting with ``ws://`` or ``wss://``
|
||||
"""
|
||||
if Nostr.is_blocklisted(relay):
|
||||
logger.warning(f'Not subscribing to relay {relay}')
|
||||
return
|
||||
|
|
@ -121,7 +127,11 @@ def add_relay(relay):
|
|||
|
||||
|
||||
def subscriber(relay):
|
||||
"""Wrapper around :func:`_subscribe` that catches exceptions and reconnects."""
|
||||
"""Wrapper around :func:`_subscribe` that catches exceptions and reconnects.
|
||||
|
||||
Args:
|
||||
relay (str): URI, relay websocket adddress, starting with ``ws://`` or ``wss://``
|
||||
"""
|
||||
logger.info(f'started thread to subscribe to relay {relay}')
|
||||
|
||||
with ndb_client.context(**NDB_CONTEXT_KWARGS):
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ class NostrTest(TestCase):
|
|||
self.assertEqual('npub123', Nostr(id='nostr:npub123').npub())
|
||||
|
||||
def test_id_uri(self):
|
||||
self.assertEqual('nostr:npub123', Nostr(id='npub123').id_uri())
|
||||
self.assertEqual('nostr:npub123', Nostr(id='nostr:npub123').id_uri())
|
||||
|
||||
def test_web_url(self):
|
||||
self.assertIsNone(Nostr().web_url())
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue