Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poll for posts in pull-oriented protocols #694

Closed
Tracked by #381
snarfed opened this issue Oct 24, 2023 · 1 comment
Closed
Tracked by #381

Poll for posts in pull-oriented protocols #694

snarfed opened this issue Oct 24, 2023 · 1 comment
Labels

Comments

@snarfed
Copy link
Owner

snarfed commented Oct 24, 2023

ATProto is pull-oriented, so we're currently polling notifications there to get events to propagate. We also need to poll timelines in those protocols to get posts to propagate. Whee. Should hopefully be similar to polling notifs?

Also the existing ATProto notif polling should be abstracted before we start on Nostr in earnest.

bridgy-fed/atproto.py

Lines 390 to 438 in 611bc94

def poll_notifications():
"""Fetches and enqueueus new activities from the AppView for our users.
Uses the ``listNotifications`` endpoint, which is intended for end users. 🤷
https://github.com/bluesky-social/atproto/discussions/1538
"""
repos = {r.key.id(): r for r in AtpRepo.query()}
logger.info(f'Got {len(repos)} repos')
users = itertools.chain(*(cls.query(cls.atproto_did.IN(list(repos)))
for cls in set(PROTOCOLS.values())
if cls and cls != ATProto))
# TODO: convert to Session for connection pipelining!
client = Client(f'https://{os.environ["APPVIEW_HOST"]}',
headers={'User-Agent': USER_AGENT})
for user in users:
logging.debug(f'Fetching notifs for {user.key.id()}')
# TODO: store and use cursor
# seenAt would be easier, but they don't support it yet
# https://github.com/bluesky-social/atproto/issues/1636
repo = repos[user.atproto_did]
client.access_token = service_jwt(os.environ['APPVIEW_HOST'],
repo_did=user.atproto_did,
privkey=repo.signing_key)
resp = client.app.bsky.notification.listNotifications()
for notif in resp['notifications']:
logger.debug(f'Got {notif["reason"]} from {notif["author"]["handle"]} {notif["uri"]} {notif["cid"]} : {json_dumps(notif, indent=2)}')
# TODO: verify sig. skipping this for now because we're getting
# these from the AppView, which is trusted, specifically we expect
# the BGS and/or the AppView already checked sigs.
obj = Object.get_or_create(id=notif['uri'], bsky=notif['record'],
source_protocol=ATProto.ABBREV)
if not obj.status:
obj.status = 'new'
obj.add('notify', user.key)
obj.put()
common.create_task(queue='receive', obj=obj.key.urlsafe(),
authed_as=notif['author']['did'])
# note that we don't pass a user param above. it's the acting user,
# which is different for every notif, and may not actually have a BF
# User yet.
return 'OK'

@snarfed snarfed added the now label Nov 10, 2023
@snarfed
Copy link
Owner Author

snarfed commented Nov 15, 2023

Done for ATProto. Will revisit when I abstract this for Nostr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant