From 8edd975b1109ff1bcda0d618da404a2f82e8c2a3 Mon Sep 17 00:00:00 2001 From: Diogo Peralta Cordeiro Date: Mon, 6 Dec 2021 20:58:15 +0000 Subject: [PATCH] [ActivityPub] Set Notice scope when storing activities --- .../lib/models/Activitypub_notice.php | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/plugins/ActivityPub/lib/models/Activitypub_notice.php b/plugins/ActivityPub/lib/models/Activitypub_notice.php index cf929a98cb..908b804ae0 100644 --- a/plugins/ActivityPub/lib/models/Activitypub_notice.php +++ b/plugins/ActivityPub/lib/models/Activitypub_notice.php @@ -167,12 +167,19 @@ class Activitypub_notice $act->time = time(); $act->actor = $actor_profile->asActivityObject(); $act->context = new ActivityContext(); - $options = ['source' => 'ActivityPub', + + [$note_type, $note_scope] = self::getNotePolicy($object, $actor_profile); + + $options = [ + 'source' => 'ActivityPub', 'uri' => $id, 'url' => $url, - 'is_local' => self::getNotePolicyType($object, $actor_profile)]; + 'is_local' => $note_type, + 'scope' => $note_scope, + ]; if ($directMessage) { + $options['is_local'] = Notice::GATEWAY; $options['scope'] = Notice::MESSAGE_SCOPE; } @@ -364,20 +371,17 @@ class Activitypub_notice * * @param array $note received Note * @param Profile $actor_profile Note author - * @return int Notice policy type + * @return [int NoteType, ?int NoteScope] Notice policy type * @author Bruno Casteleiro */ - public static function getNotePolicyType(array $note, Profile $actor_profile): int + public static function getNotePolicy(array $note, Profile $actor_profile): array { - $addressee = array_unique(array_merge($note['to'], $note['cc'])); - if (in_array('https://www.w3.org/ns/activitystreams#Public', $addressee)) { - return $actor_profile->isLocal() ? Notice::LOCAL_PUBLIC : Notice::REMOTE; - } else { - // either an unlisted or followers-only note, we'll handle - // both as a GATEWAY notice since this type is not visible - // from the public timelines, hence partially enough while - // we don't have subscription_policy working. - return Notice::GATEWAY; + if (in_array('https://www.w3.org/ns/activitystreams#Public', $note['to'])) { // Public: Visible for all, shown in public feeds + return [$actor_profile->isLocal() ? Notice::LOCAL_PUBLIC : Notice::REMOTE, null]; + } elseif (in_array('https://www.w3.org/ns/activitystreams#Public', $note['cc'])) { // Unlisted: Visible for all but not shown in public feeds + return [$actor_profile->isLocal() ? Notice::LOCAL_NONPUBLIC : Notice::GATEWAY, null]; + } else { // Either Followers-only or Direct (but this function isn't used for direct) + return [$actor_profile->isLocal() ? Notice::LOCAL_NONPUBLIC : Notice::REMOTE, Notice::FOLLOWER_SCOPE]; } } }