merging receive: implement mentions, deliver to mentioned users

for #529
pull/582/head
Ryan Barrett 2023-07-10 15:53:32 -07:00
rodzic 605742a82c
commit 174c55ae6e
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 43 dodań i 57 usunięć

Wyświetl plik

@ -744,7 +744,10 @@ class Protocol:
#
# sort so order is deterministic for tests.
orig_ids = sorted(as1.get_ids(obj.as1, 'inReplyTo') +
as1.get_ids(inner_obj_as1, 'inReplyTo'))
as1.get_ids(inner_obj_as1, 'inReplyTo') +
# TODO: tagged users don't currently get populated
# into Object.users. fix that!
as1.get_ids(inner_obj_as1, 'tags'))
verb = obj.as1.get('verb')
if orig_ids:
logger.info(f'original object ids from inReplyTo: {orig_ids}')

Wyświetl plik

@ -854,66 +854,49 @@ class ProtocolReceiveTest(TestCase):
self.assertEqual([(update_obj, 'shared:target')], Fake.sent)
def test_mention_object(self, *mocks):
self._test_mention(
MENTION_OBJECT,
{
'type': 'note', # not mention (?)
'labels': ['notification'],
},
*mocks,
)
self.alice.obj.our_as1 = {'foo': 'bar'}
self.alice.obj.put()
self.bob.obj.our_as1 = {'foo': 'baz'}
self.bob.obj.put()
def test_mention_create_activity(self, *mocks):
self._test_mention(
MENTION,
{
'type': 'post', # not mention (?)
'object_ids': [MENTION_OBJECT['id']],
'labels': ['notification', 'activity'],
},
*mocks,
)
mention_as1 = {
'objectType': 'note',
'id': 'fake:mention',
'author': 'fake:user',
'content': 'something',
'tags': [{
'objectType': 'mention',
'url': 'fake:alice',
}, {
'objectType': 'mention',
'url': 'fake:bob',
}],
}
self.assertEqual('OK', Fake.receive(mention_as1))
# redirect unwrap
expected_as2 = copy.deepcopy(MENTION_OBJECT)
expected_as2['tag'][1]['href'] = 'https://tar.get/'
self.assert_object(MENTION_OBJECT['id'],
as2=expected_as2,
type='note')
self.assert_object('fake:mention',
our_as1=mention_as1,
type='note',
)
def _test_mention(self, mention, expected_props):
self.make_user('tar.get')
obj = self.assert_object('fake:mention#bridgy-fed-create',
status='complete',
our_as1={
'objectType': 'activity',
'verb': 'post',
'id': 'fake:mention#bridgy-fed-create',
'actor': 'fake:user',
'object': mention_as1,
'published': '2022-01-02T03:04:05+00:00',
},
delivered=['fake:alice:target', 'fake:bob:target'],
type='post',
labels=['user', 'activity', 'feed'],
users=[g.user.key],
)
mock_get.side_effect = [
self.as2_resp(ACTOR),
requests_response(test_web.NOTE_HTML),
requests_response(test_web.NOTE_HTML),
WEBMENTION_DISCOVERY,
]
mock_post.return_value = requests_response()
got = self.post('/user.com/inbox', json=mention)
self.assertEqual(200, got.status_code, got.get_data(as_text=True))
self.assert_req(mock_get, 'https://tar.get/')
convert_id = mention['id'].replace('://', ':/')
self.assert_req(
mock_post,
'https://tar.get/webmention',
headers={'Accept': '*/*'},
allow_redirects=False,
data={
'source': f'http://localhost/convert/activitypub/web/{convert_id}',
'target': 'https://tar.get/',
},
)
expected_as2 = common.redirect_unwrap(mention)
self.assert_object(mention['id'],
users=[Web(id='tar.get').key],
status='complete',
as2=expected_as2,
delivered=['https://tar.get/'],
**expected_props)
self.assertEqual([(obj, 'fake:alice:target'), (obj, 'fake:bob:target')],
Fake.sent)
def test_follow(self):
self._test_follow()