mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-02-02 20:32:20 +00:00
Always prefer shared inboxes when computing receipent lists
This avoids duplicate submissions to remote instances when mentioning followers (i.e., `POST /user/foo/inbox` followed by `POST /inbox`, which results in two separate `add_status` tasks, and might generate duplicates in the target instance).
This commit is contained in:
parent
193aeff4d2
commit
31babdfa51
2 changed files with 9 additions and 5 deletions
|
@ -153,7 +153,7 @@ class ActivitypubMixin:
|
||||||
mentions = self.recipients if hasattr(self, "recipients") else []
|
mentions = self.recipients if hasattr(self, "recipients") else []
|
||||||
|
|
||||||
# we always send activities to explicitly mentioned users' inboxes
|
# we always send activities to explicitly mentioned users' inboxes
|
||||||
recipients = [u.inbox for u in mentions or [] if not u.local]
|
recipients = [u.shared_inbox or u.inbox for u in mentions if not u.local]
|
||||||
|
|
||||||
# unless it's a dm, all the followers should receive the activity
|
# unless it's a dm, all the followers should receive the activity
|
||||||
if privacy != "direct":
|
if privacy != "direct":
|
||||||
|
|
|
@ -227,14 +227,18 @@ class ActivitypubMixins(TestCase):
|
||||||
shared_inbox="http://example.com/inbox",
|
shared_inbox="http://example.com/inbox",
|
||||||
outbox="https://example.com/users/nutria/outbox",
|
outbox="https://example.com/users/nutria/outbox",
|
||||||
)
|
)
|
||||||
MockSelf = namedtuple("Self", ("privacy", "user"))
|
MockSelf = namedtuple("Self", ("privacy", "user", "recipients"))
|
||||||
mock_self = MockSelf("public", self.local_user)
|
|
||||||
self.local_user.followers.add(self.remote_user)
|
self.local_user.followers.add(self.remote_user)
|
||||||
self.local_user.followers.add(another_remote_user)
|
self.local_user.followers.add(another_remote_user)
|
||||||
|
|
||||||
|
mock_self = MockSelf("public", self.local_user, [])
|
||||||
recipients = ActivitypubMixin.get_recipients(mock_self)
|
recipients = ActivitypubMixin.get_recipients(mock_self)
|
||||||
self.assertEqual(len(recipients), 1)
|
self.assertCountEqual(recipients, ["http://example.com/inbox"])
|
||||||
self.assertEqual(recipients[0], "http://example.com/inbox")
|
|
||||||
|
# should also work with recipient that is a follower
|
||||||
|
mock_self.recipients.append(another_remote_user)
|
||||||
|
recipients = ActivitypubMixin.get_recipients(mock_self)
|
||||||
|
self.assertCountEqual(recipients, ["http://example.com/inbox"])
|
||||||
|
|
||||||
def test_get_recipients_software(self, *_):
|
def test_get_recipients_software(self, *_):
|
||||||
"""should differentiate between bookwyrm and other remote users"""
|
"""should differentiate between bookwyrm and other remote users"""
|
||||||
|
|
Loading…
Reference in a new issue