]> git.mxchange.org Git - friendica.git/commitdiff
Extract hasRestrictions() into ItemInserter
authorArt4 <art4@wlabs.de>
Thu, 23 Jan 2025 09:50:27 +0000 (09:50 +0000)
committerArt4 <art4@wlabs.de>
Thu, 23 Jan 2025 09:50:27 +0000 (09:50 +0000)
src/Model/Item.php
src/Model/ItemInserter.php

index f9ab920bf088848d399f8b90c4330073302f11cb..556a8b49445972342193219c3273e656cc096ee2 100644 (file)
@@ -757,7 +757,7 @@ class Item
         * @return array item array with parent data
         * @throws \Exception
         */
-       private static function getTopLevelParent(array $item): array
+       private static function getTopLevelParent(array $item, ItemInserter $itemInserter): array
        {
                $fields = [
                        'uid', 'uri', 'parent-uri', 'id', 'deleted',
@@ -785,7 +785,7 @@ class Item
                        return [];
                }
 
-               if (self::hasRestrictions($item, $parent['author-id'], $parent['restrictions'])) {
+               if ($itemInserter->hasRestrictions($item, $parent['author-id'], $parent['restrictions'])) {
                        DI::logger()->notice('Restrictions apply - ignoring item', ['restrictions' => $parent['restrictions'], 'verb' => $parent['verb'], 'uri-id' => $item['uri-id'], 'thr-parent-id' => $item['thr-parent-id'], 'uid' => $item['uid']]);
                        return [];
                }
@@ -916,7 +916,7 @@ class Item
                }
 
                if ($item['gravity'] !== self::GRAVITY_PARENT) {
-                       $toplevel_parent = self::getTopLevelParent($item);
+                       $toplevel_parent = self::getTopLevelParent($item, $itemInserter);
                        if (empty($toplevel_parent)) {
                                return 0;
                        }
@@ -1390,33 +1390,6 @@ class Item
                return $item;
        }
 
-       private static function hasRestrictions(array $item, int $author_id, int $restrictions = null): bool
-       {
-               if (empty($restrictions) || ($author_id == $item['author-id'])) {
-                       return false;
-               }
-
-               // We only have to apply restrictions if the post originates from our server or is federated.
-               // Every other time we can trust the remote system.
-               if (!in_array($item['network'], Protocol::FEDERATED) && !$item['origin']) {
-                       return false;
-               }
-
-               if (($restrictions & self::CANT_REPLY) && ($item['verb'] == Activity::POST)) {
-                       return true;
-               }
-
-               if (($restrictions & self::CANT_ANNOUNCE) && ($item['verb'] == Activity::ANNOUNCE)) {
-                       return true;
-               }
-
-               if (($restrictions & self::CANT_LIKE) && in_array($item['verb'], [Activity::LIKE, Activity::DISLIKE, Activity::ATTEND, Activity::ATTENDMAYBE, Activity::ATTENDNO])) {
-                       return true;
-               }
-
-               return false;
-       }
-
        private static function reshareChannelPost(int $uri_id, int $reshare_id = 0)
        {
                if (!DI::config()->get('system', 'allow_relay_channels')) {
index 77e58ee1549330dc436afcbbab233157dd0d817c..85b33e6dfc49200d5b1c367eb1cd634946a5a2d1 100644 (file)
@@ -9,6 +9,7 @@ namespace Friendica\Model;
 
 use Friendica\App\BaseURL;
 use Friendica\Content\Item as ItemContent;
+use Friendica\Core\Protocol;
 use Friendica\Protocol\Activity;
 use Friendica\Util\DateTimeFormat;
 use Psr\Log\LoggerInterface;
@@ -147,6 +148,33 @@ final class ItemInserter
                return $item;
        }
 
+       public function hasRestrictions(array $item, int $author_id, int $restrictions = null): bool
+       {
+               if (empty($restrictions) || ($author_id == $item['author-id'])) {
+                       return false;
+               }
+
+               // We only have to apply restrictions if the post originates from our server or is federated.
+               // Every other time we can trust the remote system.
+               if (!in_array($item['network'], Protocol::FEDERATED) && !$item['origin']) {
+                       return false;
+               }
+
+               if (($restrictions & Item::CANT_REPLY) && ($item['verb'] == Activity::POST)) {
+                       return true;
+               }
+
+               if (($restrictions & Item::CANT_ANNOUNCE) && ($item['verb'] == Activity::ANNOUNCE)) {
+                       return true;
+               }
+
+               if (($restrictions & Item::CANT_LIKE) && in_array($item['verb'], [Activity::LIKE, Activity::DISLIKE, Activity::ATTEND, Activity::ATTENDMAYBE, Activity::ATTENDNO])) {
+                       return true;
+               }
+
+               return false;
+       }
+
        /**
         * Get the gravity for the given item array
         *