kopia lustrzana https://github.com/snarfed/bridgy-fed
AP: compact outgoing actor, author, and attributedTo fields to string ids
hope this improves compatibility with many other AP implementations that choke on objects instead of ids. fixes #658pull/672/head
rodzic
c01375a300
commit
15a325c928
|
@ -494,8 +494,8 @@ def postprocess_as2(activity, orig_obj=None, wrap=True):
|
|||
|
||||
Args:
|
||||
activity (dict): AS2 object or activity
|
||||
orig_obj (dict): AS2 object, optional. The target of activity's ``inReplyTo`` or
|
||||
``Like``/``Announce``/etc object, if any.
|
||||
orig_obj (dict): AS2 object, optional. The target of activity's
|
||||
``inReplyTo`` or ``Like``/``Announce``/etc object, if any.
|
||||
wrap (bool): whether to wrap ``id``, ``url``, ``object``, ``actor``, and
|
||||
``attributedTo``
|
||||
"""
|
||||
|
@ -524,12 +524,15 @@ def postprocess_as2(activity, orig_obj=None, wrap=True):
|
|||
})
|
||||
return activity
|
||||
|
||||
if wrap:
|
||||
for field in 'actor', 'attributedTo':
|
||||
activity[field] = [postprocess_as2_actor(actor, wrap=wrap)
|
||||
for actor in util.get_list(activity, field)]
|
||||
if len(activity[field]) == 1:
|
||||
activity[field] = activity[field][0]
|
||||
# actors. wrap in our domain if necessary, then compact to just string id
|
||||
# for compatibility, since many other AP implementations choke on objects.
|
||||
# https://github.com/snarfed/bridgy-fed/issues/658
|
||||
for field in 'actor', 'attributedTo', 'author':
|
||||
actors = as1.get_objects(activity, field)
|
||||
if wrap:
|
||||
actors = [postprocess_as2_actor(actor, wrap=wrap) for actor in actors]
|
||||
ids = [a['id'] for a in actors if a.get('id')]
|
||||
activity[field] = ids[0] if len(ids) == 1 else ids
|
||||
|
||||
# inReplyTo: singly valued, prefer id over url
|
||||
# TODO: ignore orig_obj, do for all inReplyTo
|
||||
|
|
|
@ -224,7 +224,10 @@ ACCEPT = {
|
|||
'id': 'http://localhost/user.com/followers#accept-https://mas.to/6d1a',
|
||||
'actor': 'http://localhost/user.com',
|
||||
'object': {
|
||||
**ACCEPT_FOLLOW,
|
||||
'type': 'Follow',
|
||||
'id': 'https://mas.to/6d1a',
|
||||
'object': 'http://localhost/user.com',
|
||||
'actor': 'https://mas.to/users/swentel',
|
||||
'url': 'https://mas.to/users/swentel#followed-https://user.com/',
|
||||
'to': ['https://www.w3.org/ns/activitystreams#Public'],
|
||||
},
|
||||
|
@ -1635,33 +1638,17 @@ class ActivityPubUtilsTest(TestCase):
|
|||
'image': [{'url': 'http://r/foo'}, {'url': 'http://r/bar'}],
|
||||
}))
|
||||
|
||||
def test_postprocess_as2_actor_attributedTo(self):
|
||||
def test_postprocess_as2_actor_attributedTo_author(self):
|
||||
g.user = Fake(id='site')
|
||||
self.assert_equals({
|
||||
'actor': {
|
||||
'id': 'baj',
|
||||
'preferredUsername': 'site',
|
||||
'url': 'http://localhost/r/site',
|
||||
'inbox': 'https://fa.brid.gy/ap/site/inbox',
|
||||
'outbox': 'https://fa.brid.gy/ap/site/outbox',
|
||||
},
|
||||
'attributedTo': [{
|
||||
'id': 'bar',
|
||||
'preferredUsername': 'site',
|
||||
'url': 'http://localhost/r/site',
|
||||
'inbox': 'https://fa.brid.gy/ap/site/inbox',
|
||||
'outbox': 'https://fa.brid.gy/ap/site/outbox',
|
||||
}, {
|
||||
'id': 'baz',
|
||||
'preferredUsername': 'site',
|
||||
'url': 'http://localhost/r/site',
|
||||
'inbox': 'https://fa.brid.gy/ap/site/inbox',
|
||||
'outbox': 'https://fa.brid.gy/ap/site/outbox',
|
||||
}],
|
||||
'actor': 'baj',
|
||||
'attributedTo': ['bar', 'baz'],
|
||||
'author': 'biff',
|
||||
'to': [as2.PUBLIC_AUDIENCE],
|
||||
}, postprocess_as2({
|
||||
'attributedTo': [{'id': 'bar'}, {'id': 'baz'}],
|
||||
'actor': {'id': 'baj'},
|
||||
'author': {'id': 'biff'},
|
||||
}))
|
||||
|
||||
def test_postprocess_as2_note(self):
|
||||
|
|
|
@ -23,7 +23,7 @@ from .test_web import (
|
|||
|
||||
REPOST_AS2 = {
|
||||
**REPOST_AS2,
|
||||
'actor': ACTOR_AS2,
|
||||
'actor': 'http://localhost/user.com',
|
||||
}
|
||||
del REPOST_AS2['cc']
|
||||
|
||||
|
|
|
@ -251,7 +251,7 @@ AS2_CREATE = {
|
|||
'https://mas.to/recipient',
|
||||
as2.PUBLIC_AUDIENCE,
|
||||
],
|
||||
'attributedTo': ACTOR_AS2,
|
||||
'attributedTo': 'http://localhost/user.com',
|
||||
'tag': [{
|
||||
'type': 'Mention',
|
||||
'href': 'https://mas.to/author',
|
||||
|
@ -344,7 +344,7 @@ NOTE_AS2 = {
|
|||
'type': 'Note',
|
||||
'id': 'http://localhost/r/https://user.com/post',
|
||||
'url': 'http://localhost/r/https://user.com/post',
|
||||
'attributedTo': ACTOR_AS2,
|
||||
'attributedTo': 'http://localhost/user.com',
|
||||
'name': 'hello i am a post',
|
||||
'content': 'hello i am a post',
|
||||
'to': [as2.PUBLIC_AUDIENCE],
|
||||
|
|
Ładowanie…
Reference in New Issue