]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/ActivityPub/Processor.php
Set the owner for group posts
[friendica.git] / src / Protocol / ActivityPub / Processor.php
index 86394bd91c8166d047cc195cdfdc38eab137d65c..2db9f925a945c34d9f730ba1810c93b69f9f63b9 100644 (file)
@@ -415,7 +415,7 @@ class Processor
                        $item['post-type'] = Item::PT_NOTE;
                }
 
-               $item['isForum'] = false;
+               $item['isGroup'] = false;
 
                if (!empty($activity['thread-completion'])) {
                        if ($activity['thread-completion'] != $item['owner-id']) {
@@ -434,7 +434,19 @@ class Processor
                        $item['owner-id'] = $item['author-id'];
                } else {
                        $actor = APContact::getByURL($item['owner-link'], false);
-                       $item['isForum'] = ($actor['type'] ?? 'Person') == 'Group';
+                       $item['isGroup'] = ($actor['type'] ?? 'Person') == 'Group';
+               }
+
+               if (!$item['isGroup'] && !empty($activity['receiver_urls']['as:audience'])) {
+                       foreach ($activity['receiver_urls']['as:audience'] as $audience) {
+                               $actor = APContact::getByURL($audience, false);
+                               if (($actor['type'] ?? 'Person') == 'Group') {
+                                       Logger::debug('Set owner to audience', ['audience' => $audience, 'actor' => $activity['actor'], 'author' => $activity['author']]);
+                                       $item['isGroup']    = true;
+                                       $item['owner-link'] = $audience;
+                                       $item['owner-id']   = Contact::getIdForURL($audience);
+                               }
+                       }
                }
 
                $item['uri'] = $activity['id'];
@@ -1026,6 +1038,9 @@ class Processor
                                case Receiver::TARGET_BCC:
                                        $item['post-reason'] = Item::PR_BCC;
                                        break;
+                               case Receiver::TARGET_AUDIENCE:
+                                       $item['post-reason'] = Item::PR_AUDIENCE;
+                                       break;
                                case Receiver::TARGET_FOLLOWER:
                                        $item['post-reason'] = Item::PR_FOLLOWER;
                                        break;
@@ -1056,10 +1071,10 @@ class Processor
                                $item['causer-id'] = ($item['gravity'] == Item::GRAVITY_PARENT) ? $item['owner-id'] : $item['author-id'];
                        }
 
-                       if ($item['isForum'] ?? false) {
-                               $item['contact-id'] = Contact::getIdForURL($activity['actor'], $receiver);
+                       if ($item['isGroup'] ?? false) {
+                               $item['contact-id'] = Contact::getIdForURL($item['owner-link'], $receiver);
                        } else {
-                               $item['contact-id'] = Contact::getIdForURL($activity['author'], $receiver);
+                               $item['contact-id'] = Contact::getIdForURL($item['author-link'], $receiver);
                        }
 
                        if (($receiver != 0) && empty($item['contact-id'])) {
@@ -1071,8 +1086,8 @@ class Processor
                                continue;
                        }
 
-                       if (($receiver != 0) && ($item['gravity'] == Item::GRAVITY_PARENT) && !in_array($item['post-reason'], [Item::PR_FOLLOWER, Item::PR_TAG, item::PR_TO, Item::PR_CC])) {
-                               if (!($item['isForum'] ?? false)) {
+                       if (($receiver != 0) && ($item['gravity'] == Item::GRAVITY_PARENT) && !in_array($item['post-reason'], [Item::PR_FOLLOWER, Item::PR_TAG, item::PR_TO, Item::PR_CC, Item::PR_AUDIENCE])) {
+                               if (!($item['isGroup'] ?? false)) {
                                        if ($item['post-reason'] == Item::PR_BCC) {
                                                Logger::info('Top level post via BCC from a non sharer, ignoring', ['uid' => $receiver, 'contact' => $item['contact-id'], 'url' => $item['uri']]);
                                                continue;
@@ -1086,16 +1101,16 @@ class Processor
                                        }
                                }
 
-                               $is_forum = false;
+                               $isGroup = false;
                                $user = User::getById($receiver, ['account-type']);
                                if (!empty($user['account-type'])) {
-                                       $is_forum = ($user['account-type'] == User::ACCOUNT_TYPE_COMMUNITY);
+                                       $isGroup = ($user['account-type'] == User::ACCOUNT_TYPE_COMMUNITY);
                                }
 
                                if ((DI::pConfig()->get($receiver, 'system', 'accept_only_sharer') == Item::COMPLETION_NONE)
-                                       && ((!$is_forum && !($item['isForum'] ?? false) && ($activity['type'] != 'as:Announce'))
+                                       && ((!$isGroup && !($item['isGroup'] ?? false) && ($activity['type'] != 'as:Announce'))
                                        || !Contact::isSharingByURL($activity['actor'], $receiver))) {
-                                       Logger::info('Actor is a non sharer, is no forum or it is no announce', ['uid' => $receiver, 'actor' => $activity['actor'], 'url' => $item['uri'], 'type' => $activity['type']]);
+                                       Logger::info('Actor is a non sharer, is no group or it is no announce', ['uid' => $receiver, 'actor' => $activity['actor'], 'url' => $item['uri'], 'type' => $activity['type']]);
                                        continue;
                                }
 
@@ -1138,7 +1153,7 @@ class Processor
                // Store send a follow request for every reshare - but only when the item had been stored
                if ($stored && ($item['private'] != Item::PRIVATE) && ($item['gravity'] == Item::GRAVITY_PARENT) && !empty($item['author-link']) && ($item['author-link'] != $item['owner-link'])) {
                        $author = APContact::getByURL($item['owner-link'], false);
-                       // We send automatic follow requests for reshared messages. (We don't need though for forum posts)
+                       // We send automatic follow requests for reshared messages. (We don't need though for group posts)
                        if ($author['type'] != 'Group') {
                                Logger::info('Send follow request', ['uri' => $item['uri'], 'stored' => $stored, 'to' => $item['author-link']]);
                                ActivityPub\Transmitter::sendFollowObject($item['uri'], $item['author-link']);
@@ -1274,7 +1289,7 @@ class Processor
 
        public static function storeReceivers(int $uriid, array $receivers)
        {
-               foreach (['as:to' => Tag::TO, 'as:cc' => Tag::CC, 'as:bto' => Tag::BTO, 'as:bcc' => Tag::BCC] as $element => $type) {
+               foreach (['as:to' => Tag::TO, 'as:cc' => Tag::CC, 'as:bto' => Tag::BTO, 'as:bcc' => Tag::BCC, 'as:audience' => Tag::AUDIENCE, 'as:attributedTo' => Tag::ATTRIBUTED] as $element => $type) {
                        if (!empty($receivers[$element])) {
                                foreach ($receivers[$element] as $receiver) {
                                        if ($receiver == ActivityPub::PUBLIC_COLLECTION) {
@@ -1530,6 +1545,7 @@ class Processor
                $activity['id'] = $object['id'];
                $activity['to'] = $object['to'] ?? [];
                $activity['cc'] = $object['cc'] ?? [];
+               $activity['audience'] = $object['audience'] ?? [];
                $activity['actor'] = $actor;
                $activity['object'] = $object;
                $activity['published'] = $published;