diff --git a/pages.py b/pages.py index dbb8557..c3d5694 100644 --- a/pages.py +++ b/pages.py @@ -43,11 +43,11 @@ def load_user(protocol, id): Raises: :class:`werkzeug.exceptions.HTTPException` on error or redirect """ + assert id cls = PROTOCOLS[protocol] g.user = cls.get_by_id(id) - # TODO(#512): generalize across protocols - if protocol == 'activitypub': + if protocol != 'web': if not g.user: g.user = cls.query(cls.readable_id == id).get() if g.user and g.user.use_instead: diff --git a/protocol.py b/protocol.py index 85656e2..09e3498 100644 --- a/protocol.py +++ b/protocol.py @@ -45,6 +45,7 @@ objects_cache_lock = threading.Lock() logger = logging.getLogger(__name__) +# TODO: merge Protocol and User classes? class Protocol: """Base protocol class. Not to be instantiated; classmethods only. @@ -173,8 +174,8 @@ class Protocol: error(f'Undo of Follow requires actor id and object id. Got: {actor_id} {inner_obj_id} {obj.as1}') # deactivate Follower - # TODO(#512): generalize across protocols - # TODO(#512): merge Protocol and User + # TODO(#512): generalize across protocols. use inner_obj_id's + # brid.gy subdomain to determine protocol? followee_domain = util.domain_from_link(inner_obj_id, minimize=False) from web import Web follower = Follower.query( @@ -372,17 +373,16 @@ class Protocol: # TODO(#512): generalize protocol from web import Web - recip = Web(id=domain).key - if recip not in obj.users: - if not recip.get(): + recip = Web(id=domain) + if recip.key not in obj.users: + if not recip.key.get(): logger.info(f'No Web user for {domain}; skipping {target.uri}') no_user_domains.add(domain) continue - obj.users.append(recip) + obj.users.append(recip.key) try: - # TODO(#512): generalize protocol - if Web.send(obj, target.uri): + if recip.send(obj, target.uri): obj.delivered.append(target) if 'notification' not in obj.labels: obj.labels.append('notification') diff --git a/redirect.py b/redirect.py index f46a4da..e3ec87c 100644 --- a/redirect.py +++ b/redirect.py @@ -1,14 +1,18 @@ """Simple conneg endpoint that serves AS2 or redirects to to the original post. -Serves /r/https://foo.com/bar URL paths, where https://foo.com/bar is an -original post. Needed for Mastodon interop, they require that AS2 object ids and -urls are on the same domain that serves them. Background: +Only for Web users. Other protocols (including Web sometimes) use /convert/ in +convert.py instead. + +Serves /r/https://foo.com/bar URL paths, where https://foo.com/bar is a original +post for a Web user. Needed for Mastodon interop, they require that AS2 object +ids and urls are on the same domain that serves them. Background: https://github.com/snarfed/bridgy-fed/issues/16#issuecomment-424799599 https://github.com/tootsuite/mastodon/pull/6219#issuecomment-429142747 The conneg makes these /r/ URLs searchable in Mastodon: https://github.com/snarfed/bridgy-fed/issues/352 + """ import logging import re @@ -76,8 +80,6 @@ def redir(to): to_domain)) for domain in domains: if domain: - # TODO(#512): do we need to parameterize this by protocol? or is it - # only for web? g.user = Web.get_by_id(domain) if g.user: logger.info(f'Found web user for domain {domain}') diff --git a/tests/testutil.py b/tests/testutil.py index 152d234..4a26ce6 100644 --- a/tests/testutil.py +++ b/tests/testutil.py @@ -163,7 +163,7 @@ class TestCase(unittest.TestCase, testutil.Asserts): result.failures = prune(result.failures) return result - # TODO(#512): switch default to Fake, start using that more + # TODO: switch default to Fake, start using that more @staticmethod def make_user(id, cls=Web, **kwargs): """Reuse RSA key across Users because generating it is expensive."""