refactor: eagerly use a set in recipients, get_recipients
This commit is contained in:
parent
31babdfa51
commit
8ac873419f
2 changed files with 16 additions and 15 deletions
|
@ -152,8 +152,9 @@ class ActivitypubMixin:
|
||||||
# find anyone who's tagged in a status, for example
|
# find anyone who's tagged in a status, for example
|
||||||
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 (using shared inboxes
|
||||||
recipients = [u.shared_inbox or u.inbox for u in mentions if not u.local]
|
# where available to avoid duplicate submissions to a given instance)
|
||||||
|
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":
|
||||||
|
@ -173,18 +174,18 @@ class ActivitypubMixin:
|
||||||
if user:
|
if user:
|
||||||
queryset = queryset.filter(following=user)
|
queryset = queryset.filter(following=user)
|
||||||
|
|
||||||
# ideally, we will send to shared inboxes for efficiency
|
# as above, we prefer shared inboxes if available
|
||||||
shared_inboxes = (
|
recipients.update(
|
||||||
queryset.filter(shared_inbox__isnull=False)
|
queryset.filter(shared_inbox__isnull=False).values_list(
|
||||||
.values_list("shared_inbox", flat=True)
|
"shared_inbox", flat=True
|
||||||
.distinct()
|
)
|
||||||
)
|
)
|
||||||
# but not everyone has a shared inbox
|
recipients.update(
|
||||||
inboxes = queryset.filter(shared_inbox__isnull=True).values_list(
|
queryset.filter(shared_inbox__isnull=True).values_list(
|
||||||
"inbox", flat=True
|
"inbox", flat=True
|
||||||
|
)
|
||||||
)
|
)
|
||||||
recipients += list(shared_inboxes) + list(inboxes)
|
return list(recipients)
|
||||||
return list(set(recipients))
|
|
||||||
|
|
||||||
def to_activity_dataclass(self):
|
def to_activity_dataclass(self):
|
||||||
"""convert from a model to an activity"""
|
"""convert from a model to an activity"""
|
||||||
|
|
|
@ -107,14 +107,14 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
||||||
@property
|
@property
|
||||||
def recipients(self):
|
def recipients(self):
|
||||||
"""tagged users who definitely need to get this status in broadcast"""
|
"""tagged users who definitely need to get this status in broadcast"""
|
||||||
mentions = [u for u in self.mention_users.all() if not u.local]
|
mentions = {u for u in self.mention_users.all() if not u.local}
|
||||||
if (
|
if (
|
||||||
hasattr(self, "reply_parent")
|
hasattr(self, "reply_parent")
|
||||||
and self.reply_parent
|
and self.reply_parent
|
||||||
and not self.reply_parent.user.local
|
and not self.reply_parent.user.local
|
||||||
):
|
):
|
||||||
mentions.append(self.reply_parent.user)
|
mentions.add(self.reply_parent.user)
|
||||||
return list(set(mentions))
|
return list(mentions)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def ignore_activity(
|
def ignore_activity(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue