deliver self-replies to all followers

fixes #639
pull/650/head
Ryan Barrett 2023-10-06 14:57:36 -07:00
rodzic 62302b9105
commit 4909c0814e
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
3 zmienionych plików z 51 dodań i 9 usunięć

Wyświetl plik

@ -885,6 +885,9 @@ class Protocol:
orig_obj = None
targets = {} # maps Target to Object or None
in_reply_to = as1.get_object(obj.as1).get('inReplyTo')
is_self_reply = False
owner = as1.get_owner(obj.as1)
for id in sorted(target_uris):
protocol = Protocol.for_id(id)
@ -903,6 +906,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 all followers')
target = protocol.target_for(orig_obj)
if not target:
# TODO: surface errors like this somehow?
@ -924,9 +933,9 @@ class Protocol:
logger.info("Can't tell who this is from! Skipping followers.")
return targets
is_reply = obj.type == 'comment' or in_reply_to
if (obj.type in ('post', 'update', 'delete', 'share')
and not (obj.type == 'comment'
or as1.get_object(obj.as1).get('inReplyTo'))):
and (is_self_reply or not is_reply)):
logger.info(f'Delivering to followers of {user_key}')
followers = Follower.query(Follower.to == user_key,
Follower.status == 'active'

Wyświetl plik

@ -654,6 +654,36 @@ class ProtocolReceiveTest(TestCase):
self.assertEqual([(obj, 'fake:post:target')], Fake.sent)
def test_create_reply_to_self_delivers_to_followers(self):
self.make_followers()
eve = self.make_user('other:eve', cls=OtherFake, obj_id='other:eve')
Follower.get_or_create(to=self.user, from_=eve)
reply_as1 = {
'id': 'fake:reply',
'objectType': 'note',
'inReplyTo': 'fake:post',
'author': 'fake:user',
}
Fake.fetchable['fake:post'] = {
'objectType': 'note',
'id': 'fake:post',
'author': 'fake:user',
}
self.assertEqual('OK', Fake.receive_as1(reply_as1))
self.assert_object('fake:reply', our_as1=reply_as1, type='note',
feed=[self.alice.key, self.bob.key, eve.key])
obj = Object.get_by_id(id='fake:reply#bridgy-fed-create')
self.assertEqual([
(obj, 'fake:post:target'),
(obj, 'shared:target'),
], Fake.sent)
self.assertEqual([
(obj, 'other:eve:target'),
], OtherFake.sent)
def test_update_reply(self):
self.make_followers()

Wyświetl plik

@ -140,10 +140,7 @@ class Fake(User, protocol.Protocol):
class OtherFake(Fake):
"""Different class because the same-protocol check special cases Fake.
Used in ProtocolTest.test_skip_same_protocol
"""
"""Different class because the same-protocol check special cases Fake."""
ABBREV = 'other'
fetchable = {}
@ -154,6 +151,11 @@ class OtherFake(Fake):
def owns_id(cls, id):
return id.startswith('other:')
@classmethod
def target_for(cls, obj, shared=False):
"""No shared target."""
return f'{obj.key.id()}:target'
# used in TestCase.make_user() to reuse keys across Users since they're
# expensive to generate
@ -187,9 +189,10 @@ class TestCase(unittest.TestCase, testutil.Asserts):
protocol.objects_cache.clear()
common.webmention_discover.cache.clear()
Fake.fetchable = {}
Fake.sent = []
Fake.fetched = []
for cls in Fake, OtherFake:
cls.fetchable = {}
cls.sent = []
cls.fetched = []
common.OTHER_DOMAINS += ('fake.brid.gy',)
common.DOMAINS += ('fake.brid.gy',)