kopia lustrzana https://github.com/snarfed/bridgy-fed
Protocol.translate_ids bug fix: handle create/update user profile activities
rodzic
cada99e407
commit
fdc5b8e1e9
|
@ -494,6 +494,9 @@ class Protocol:
|
|||
Returns:
|
||||
dict: wrapped version of ``obj``
|
||||
"""
|
||||
if not obj:
|
||||
return obj
|
||||
|
||||
outer_obj = copy.deepcopy(obj)
|
||||
inner_obj = outer_obj['object'] = as1.get_object(outer_obj)
|
||||
|
||||
|
@ -514,9 +517,10 @@ class Protocol:
|
|||
translate_user_id if type in as1.ACTOR_TYPES
|
||||
else translate_object_id)
|
||||
|
||||
inner_is_actor = (as1.object_type(inner_obj) in as1.ACTOR_TYPES
|
||||
or type in ('follow', 'stop-following'))
|
||||
translate(inner_obj, 'id',
|
||||
translate_user_id if type in ('follow', 'stop-following')
|
||||
else translate_object_id)
|
||||
translate_user_id if inner_is_actor else translate_object_id)
|
||||
|
||||
for o in outer_obj, inner_obj:
|
||||
translate(o, 'inReplyTo', translate_object_id)
|
||||
|
|
|
@ -440,7 +440,7 @@ class ProtocolTest(TestCase):
|
|||
def test_translate_ids_reply(self):
|
||||
self.assert_equals({
|
||||
'objectType': 'activity',
|
||||
'verb': 'create',
|
||||
'verb': 'post',
|
||||
'object': {
|
||||
'id': 'other:o:fa:fake:reply',
|
||||
'objectType': 'note',
|
||||
|
@ -453,7 +453,7 @@ class ProtocolTest(TestCase):
|
|||
},
|
||||
}, OtherFake.translate_ids({
|
||||
'objectType': 'activity',
|
||||
'verb': 'create',
|
||||
'verb': 'post',
|
||||
'object': {
|
||||
'id': 'fake:reply',
|
||||
'objectType': 'note',
|
||||
|
@ -466,6 +466,25 @@ class ProtocolTest(TestCase):
|
|||
},
|
||||
}))
|
||||
|
||||
def test_translate_ids_update_profile(self):
|
||||
self.assert_equals({
|
||||
'objectType': 'activity',
|
||||
'verb': 'update',
|
||||
'actor': 'other:u:fake:alice',
|
||||
'object': {
|
||||
'objectType': 'person',
|
||||
'id': 'other:u:fake:alice',
|
||||
},
|
||||
}, OtherFake.translate_ids({
|
||||
'objectType': 'activity',
|
||||
'verb': 'update',
|
||||
'actor': 'fake:alice',
|
||||
'object': {
|
||||
'objectType': 'person',
|
||||
'id': 'fake:alice',
|
||||
},
|
||||
}))
|
||||
|
||||
def test_translate_ids_copies(self):
|
||||
self.store_object(id='fake:post',
|
||||
copies=[Target(uri='other:post', protocol='other')])
|
||||
|
@ -474,7 +493,7 @@ class ProtocolTest(TestCase):
|
|||
|
||||
self.assert_equals({
|
||||
'objectType': 'activity',
|
||||
'verb': 'create',
|
||||
'verb': 'post',
|
||||
'actor': 'other:user',
|
||||
'object': {
|
||||
'id': 'other:o:fa:fake:reply',
|
||||
|
@ -482,7 +501,7 @@ class ProtocolTest(TestCase):
|
|||
},
|
||||
}, OtherFake.translate_ids({
|
||||
'objectType': 'activity',
|
||||
'verb': 'create',
|
||||
'verb': 'post',
|
||||
'actor': 'fake:user',
|
||||
'object': {
|
||||
'id': 'fake:reply',
|
||||
|
|
Ładowanie…
Reference in New Issue