From 53d9ff87d90ef783de7d9b777b2822d6e9b6d65e Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 28 Aug 2021 10:40:52 -0700 Subject: [PATCH] Look up followers url to determine post privacy --- bookwyrm/activitypub/base_activity.py | 2 ++ bookwyrm/models/fields.py | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/bookwyrm/activitypub/base_activity.py b/bookwyrm/activitypub/base_activity.py index d20e7e94..52b1b1f2 100644 --- a/bookwyrm/activitypub/base_activity.py +++ b/bookwyrm/activitypub/base_activity.py @@ -275,6 +275,8 @@ def resolve_remote_id( ): """take a remote_id and return an instance, creating if necessary""" if model: # a bonus check we can do if we already know the model + if isinstance(model, str): + model = apps.get_model(f"bookwyrm.{model}", require_ready=True) result = model.find_existing_by_remote_id(remote_id) if result and not refresh: return result if not get_activity else result.to_activity_dataclass() diff --git a/bookwyrm/models/fields.py b/bookwyrm/models/fields.py index 6ed5aa5e..8f4fd28e 100644 --- a/bookwyrm/models/fields.py +++ b/bookwyrm/models/fields.py @@ -224,8 +224,14 @@ class PrivacyField(ActivitypubFieldMixin, models.CharField): original = getattr(instance, self.name) to = data.to cc = data.cc + + # we need to figure out who this is to get their followers link + user = activitypub.resolve_remote_id(self.attributedTo, model="User") + if to == [self.public]: setattr(instance, self.name, "public") + elif to == [user.followers_url]: + setattr(instance, self.name, "followers") elif cc == []: setattr(instance, self.name, "direct") elif self.public in cc: