kopia lustrzana https://github.com/snarfed/bridgy-fed
add orig_obj kwarg to Protocol.send
rodzic
37188f3cca
commit
7e7962fe45
|
@ -186,7 +186,7 @@ class ActivityPub(User, Protocol):
|
|||
return actor.get('publicInbox') or actor.get('inbox')
|
||||
|
||||
@classmethod
|
||||
def send(to_cls, obj, url, log_data=True):
|
||||
def send(to_cls, obj, url, orig_obj=None, log_data=True):
|
||||
"""Delivers an activity to an inbox URL.
|
||||
|
||||
If ``obj.recipient_obj`` is set, it's interpreted as the receiving actor
|
||||
|
@ -196,8 +196,6 @@ class ActivityPub(User, Protocol):
|
|||
logger.info(f'Skipping sending to {url}')
|
||||
return False
|
||||
|
||||
# this is set in web.webmention_task()
|
||||
orig_obj = getattr(obj, 'orig_obj', None)
|
||||
orig_as2 = orig_obj.as_as2() if orig_obj else None
|
||||
activity = obj.as2 or postprocess_as2(as2.from_as1(obj.as1),
|
||||
orig_obj=orig_as2)
|
||||
|
|
|
@ -251,7 +251,7 @@ class ATProto(User, Protocol):
|
|||
user.put()
|
||||
|
||||
@classmethod
|
||||
def send(to_cls, obj, url, log_data=True):
|
||||
def send(to_cls, obj, url, orig_obj=None, log_data=True):
|
||||
"""Creates a record if we own its repo.
|
||||
|
||||
Creates the repo first if it doesn't exist.
|
||||
|
|
20
protocol.py
20
protocol.py
|
@ -357,7 +357,7 @@ class Protocol:
|
|||
return g.user.key
|
||||
|
||||
@classmethod
|
||||
def send(to_cls, obj, url, log_data=True):
|
||||
def send(to_cls, obj, url, orig_obj=None, log_data=True):
|
||||
"""Sends an outgoing activity.
|
||||
|
||||
To be implemented by subclasses.
|
||||
|
@ -365,16 +365,18 @@ class Protocol:
|
|||
Args:
|
||||
obj (models.Object): with activity to send
|
||||
url (str): destination URL to send to
|
||||
orig_obj (models.Object): the "original object" that this object
|
||||
refers to, eg replies to or reposts or likes
|
||||
log_data (bool): whether to log full data object
|
||||
|
||||
Returns:
|
||||
True if the activity is sent successfully, False if it is ignored or
|
||||
otherwise unsent due to protocol logic, eg no webmention endpoint,
|
||||
protocol doesn't support the activity type. (Failures are raised as
|
||||
exceptions.)
|
||||
bool: True if the activity is sent successfully, False if it is
|
||||
ignored or otherwise unsent due to protocol logic, eg no webmention
|
||||
endpoint, protocol doesn't support the activity type. (Failures are
|
||||
raised as exceptions.)
|
||||
|
||||
Raises:
|
||||
:class:`werkzeug.HTTPException` if the request fails
|
||||
werkzeug.HTTPException if the request fails
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
|
@ -822,11 +824,9 @@ class Protocol:
|
|||
assert target.uri
|
||||
protocol = PROTOCOLS[target.protocol]
|
||||
|
||||
# this is reused later in ActivityPub.send()
|
||||
# TODO: find a better way
|
||||
obj.orig_obj = orig_obj
|
||||
try:
|
||||
sent = protocol.send(obj, target.uri, log_data=log_data)
|
||||
sent = protocol.send(obj, target.uri, orig_obj=orig_obj,
|
||||
log_data=log_data)
|
||||
if sent:
|
||||
add(obj.delivered, target)
|
||||
obj.undelivered.remove(target)
|
||||
|
|
|
@ -947,7 +947,7 @@ class ProtocolReceiveTest(TestCase):
|
|||
}
|
||||
|
||||
sent = []
|
||||
def send(obj, url, log_data=True):
|
||||
def send(obj, url, orig_obj=None, log_data=True):
|
||||
self.assertEqual(create_as1, obj.as1)
|
||||
if not sent:
|
||||
self.assertEqual('target:1', url)
|
||||
|
|
|
@ -100,7 +100,7 @@ class Fake(User, protocol.Protocol):
|
|||
return url.startswith('fake:blocklisted')
|
||||
|
||||
@classmethod
|
||||
def send(cls, obj, url, log_data=True):
|
||||
def send(cls, obj, url, orig_obj=None, log_data=True):
|
||||
logger.info(f'Fake.send {url}')
|
||||
cls.sent.append((obj, url))
|
||||
return True
|
||||
|
|
2
web.py
2
web.py
|
@ -302,7 +302,7 @@ class Web(User, Protocol):
|
|||
return obj.key.id()
|
||||
|
||||
@classmethod
|
||||
def send(to_cls, obj, url, **kwargs):
|
||||
def send(to_cls, obj, url, orig_obj=None, **kwargs):
|
||||
"""Sends a webmention to a given target URL.
|
||||
|
||||
See :meth:`Protocol.send` for details.
|
||||
|
|
Ładowanie…
Reference in New Issue