kopia lustrzana https://github.com/snarfed/bridgy-fed
Protocol.receive follow: send accept for every followee, not just the last one
rodzic
fc21a710c5
commit
764494be16
40
protocol.py
40
protocol.py
|
@ -557,7 +557,6 @@ class Protocol:
|
|||
error(f'Follow activity requires object(s). Got: {obj.as1}')
|
||||
|
||||
# Store Followers
|
||||
to_user = None
|
||||
for to_as1 in to_as1s:
|
||||
to_id = to_as1.get('id')
|
||||
if not to_id or not from_id:
|
||||
|
@ -589,27 +588,24 @@ class Protocol:
|
|||
add(obj.users, to_key)
|
||||
add(obj.labels, 'notification')
|
||||
|
||||
if not to_user:
|
||||
return
|
||||
|
||||
# send accept. note that this is one accept for the whole follow, even
|
||||
# if it has multiple followees!
|
||||
id = common.host_url(to_user.user_page_path(
|
||||
f'followers#accept-{obj.key.id()}'))
|
||||
accept = Object.get_or_create(id, our_as1={
|
||||
'id': id,
|
||||
'objectType': 'activity',
|
||||
'verb': 'accept',
|
||||
'actor': to_id,
|
||||
'object': obj.as1,
|
||||
})
|
||||
sent = cls.send(accept, from_target)
|
||||
if sent:
|
||||
accept.populate(
|
||||
delivered=[Target(protocol=from_cls.LABEL, uri=from_target)],
|
||||
status='complete',
|
||||
)
|
||||
accept.put()
|
||||
# send accept. note that this is one accept for the whole follow, even
|
||||
# if it has multiple followees!
|
||||
id = common.host_url(to_user.user_page_path(
|
||||
f'followers#accept-{obj.key.id()}'))
|
||||
accept = Object.get_or_create(id, our_as1={
|
||||
'id': id,
|
||||
'objectType': 'activity',
|
||||
'verb': 'accept',
|
||||
'actor': to_id,
|
||||
'object': obj.as1,
|
||||
})
|
||||
sent = cls.send(accept, from_target)
|
||||
if sent:
|
||||
accept.populate(
|
||||
delivered=[Target(protocol=from_cls.LABEL, uri=from_target)],
|
||||
status='complete',
|
||||
)
|
||||
accept.put()
|
||||
|
||||
@classmethod
|
||||
def _handle_bare_object(cls, obj):
|
||||
|
|
|
@ -1092,10 +1092,13 @@ class ProtocolReceiveTest(TestCase):
|
|||
with self.assertRaises(NoContent):
|
||||
Fake.receive(follow_as1)
|
||||
|
||||
self.assertEqual(1, len(Fake.sent))
|
||||
obj, target = Fake.sent[0]
|
||||
self.assertEqual('accept', obj.type)
|
||||
self.assertEqual('http://x.com/alice:target', target)
|
||||
(bob_obj, bob_target), (eve_obj, eve_target) = Fake.sent
|
||||
self.assertEqual('http://localhost/fa/http://x.com/bob/followers#accept-http://x.com/follow',
|
||||
bob_obj.key.id())
|
||||
self.assertEqual('http://x.com/alice:target', bob_target)
|
||||
self.assertEqual('http://localhost/fa/http://x.com/eve/followers#accept-http://x.com/follow',
|
||||
eve_obj.key.id())
|
||||
self.assertEqual('http://x.com/alice:target', eve_target)
|
||||
|
||||
self.assert_object('http://x.com/follow',
|
||||
our_as1=follow_as1,
|
||||
|
|
Ładowanie…
Reference in New Issue