bring back self replies check, only send self replies to followers

revises 073ce475e5, #981, #950, #949
pull/1020/head
Ryan Barrett 2024-05-02 13:38:43 -07:00
rodzic 3094b45bd2
commit 91638ef8bb
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
3 zmienionych plików z 19 dodań i 14 usunięć

Wyświetl plik

@ -1083,6 +1083,7 @@ class Protocol:
in_reply_to_owners.append(reply_owner)
is_reply = obj.type == 'comment' or in_reply_tos
is_self_reply = False
if is_reply:
logger.info(f"It's a reply...")
if in_reply_to_protocols:
@ -1105,6 +1106,12 @@ class Protocol:
logger.info(f"Couldn't load {id}")
continue
# deliver self-replies to followers
# https://github.com/snarfed/bridgy-fed/issues/639
if owner == as1.get_owner(orig_obj.as1):
is_self_reply = True
logger.info(f'Looks like a self reply! Delivering to followers')
if protocol == cls and cls.LABEL != 'fake':
logger.info(f'Skipping same-protocol target {id}')
continue
@ -1134,7 +1141,7 @@ class Protocol:
return targets
if (obj.type in ('post', 'update', 'delete', 'share')
and (not is_reply or in_reply_to_protocols)):
and (not is_reply or (is_self_reply and in_reply_to_protocols))):
logger.info(f'Delivering to followers of {user_key}')
followers = Follower.query(Follower.to == user_key,
Follower.status == 'active'

Wyświetl plik

@ -801,6 +801,9 @@ class ProtocolReceiveTest(TestCase):
def test_create_reply(self):
eve = self.make_user('other:eve', cls=OtherFake, obj_id='other:eve')
frank = self.make_user('other:frank', cls=OtherFake, obj_id='other:frank')
Follower.get_or_create(to=self.alice, from_=frank)
OtherFake.fetchable['other:post'] = {
'objectType': 'note',
'author': 'other:eve',
@ -834,6 +837,7 @@ class ProtocolReceiveTest(TestCase):
notify=[eve.key],
)
# not a self reply, shouldn't deliver to follower frank
self.assertEqual([(obj.key.id(), 'other:post:target')], OtherFake.sent)
def test_create_reply_bare_object(self):

Wyświetl plik

@ -195,8 +195,8 @@ REPLY_HTML = """\
<div class="h-entry">
<a class="u-url" href="https://user.com/reply"></a>
<p class="e-content p-name">
<a class="u-in-reply-to" href="https://mas.to/toot">foo bar</a>
<a class="u-in-reply-to" href="http://no.t/fediverse"></a>
<a class="u-in-reply-to" href="https://mas.to/toot">foo bar</a>
<a href="http://localhost/"></a>
</p>
<a class="p-author h-card" href="https://user.com/">Ms. Baz</a>
@ -252,13 +252,13 @@ AS2_CREATE = {
'url': 'http://localhost/r/https://user.com/reply',
'name': 'foo ☕ bar',
'content': """\
<a class="u-in-reply-to" href="https://mas.to/toot">foo bar</a>
<a class="u-in-reply-to" href="http://no.t/fediverse"></a>
<a class="u-in-reply-to" href="https://mas.to/toot">foo bar</a>
<a href="http://localhost/"></a>""",
'contentMap': {
'en': """\
<a class="u-in-reply-to" href="https://mas.to/toot">foo bar</a>
<a class="u-in-reply-to" href="http://no.t/fediverse"></a>
<a class="u-in-reply-to" href="https://mas.to/toot">foo bar</a>
<a href="http://localhost/"></a>""",
},
'inReplyTo': 'https://mas.to/toot/id',
@ -794,16 +794,10 @@ class WebTest(TestCase):
})
self.assertEqual(202, got.status_code)
self.assertEqual(['https://inbox/', 'https://mas.to/inbox',
'https://public/inbox', 'https://shared/inbox'],
[args[0] for args, _ in mock_post.call_args_list])
for args, kwargs in mock_post.call_args_list:
expected = copy.deepcopy(AS2_UPDATE)
if args[0] != 'https://mas.to/inbox':
del expected['object']['tag'] # Mention
expected['object']['inReplyTo'] = 'https://mas.to/toot'
self.assert_equals(expected, json_loads(kwargs['data']), ignore=['cc'])
self.assertEqual(1, mock_post.call_count)
args, kwargs = mock_post.call_args
self.assertEqual(('https://mas.to/inbox',), args)
self.assert_equals(AS2_UPDATE, json_loads(kwargs['data']))
def test_redo_repost_isnt_update(self, mock_get, mock_post):
"""Like and Announce shouldn't use Update, they should just resend as is."""