]> git.mxchange.org Git - friendica.git/commitdiff
AP: We can now store received reports
authorMichael <heluecht@pirati.ca>
Fri, 23 Dec 2022 22:11:50 +0000 (22:11 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 23 Dec 2022 22:11:50 +0000 (22:11 +0000)
src/DI.php
src/Protocol/ActivityPub/Processor.php
src/Protocol/ActivityPub/Receiver.php

index 59f48fcb5f1205d3a9d4087a18aa15535c24ca54..bf2b5a2371cfb9dc26d9b769888952bcc583e534 100644 (file)
@@ -532,6 +532,16 @@ abstract class DI
                return self::$dice->create(Contact\Introduction\Factory\Introduction::class);
        }
 
+       public static function report(): Moderation\Repository\Report
+       {
+               return self::$dice->create(Moderation\Repository\Report::class);
+       }
+
+       public static function reportFactory(): Moderation\Factory\Report
+       {
+               return self::$dice->create(Moderation\Factory\Report::class);
+       }
+
        public static function localRelationship(): Contact\LocalRelationship\Repository\LocalRelationship
        {
                return self::$dice->create(Contact\LocalRelationship\Repository\LocalRelationship::class);
index d689ba72a506099700b29364a8dfb33c76fd18be..a4333217de9bf30d791f47b1b726391f7b429d50 100644 (file)
@@ -1821,6 +1821,39 @@ class Processor
                Queue::remove($activity);
        }
 
+       /**
+        * Report a user
+        *
+        * @param array $activity
+        * @return void
+        * @throws \Exception
+        */
+       public static function ReportAccount(array $activity)
+       {
+               $account_id = Contact::getIdForURL($activity['object_id']);
+               if (empty($account_id)) {
+                       Logger::info('Unknown account', ['activity' => $activity]);
+                       Queue::remove($activity);
+                       return;
+               }
+
+               $status_ids = $activity['object_ids'];
+               array_shift($status_ids);
+
+               $uri_ids = [];
+               foreach ($status_ids as $status_id) {
+                       $post = Post::selectFirst(['uri-id'], ['uri' => $status_id]);
+                       if (!empty($post['uri-id'])) {
+                               $uri_ids[] = $post['uri-id'];
+                       }
+               }
+
+               $report = DI::reportFactory()->createFromReportsRequest(0, $account_id, $activity['content'], false, $uri_ids);
+               DI::report()->save($report);
+
+               Logger::info('Stored report', ['account_id' => $account_id, 'comment' => $activity['content'], 'status_ids' => $status_ids]);
+       }
+
        /**
         * Accept a follow request
         *
index cb76ca7e182d477e47ca16d35dbdd4f3e9a54aee..85965d71291198ea9e2eca8e4e5fe24532084f2e 100644 (file)
@@ -406,7 +406,14 @@ class Receiver
                }
 
                // Any activities on account types must not be altered
-               if (in_array($object_type, self::ACCOUNT_TYPES)) {
+               if (in_array($type, ['as:Flag'])) {
+                       $object_data = [];
+                       $object_data['id'] = JsonLD::fetchElement($activity, '@id');
+                       $object_data['object_id'] = JsonLD::fetchElement($activity, 'as:object', '@id');
+                       $object_data['object_ids'] = JsonLD::fetchElementArray($activity, 'as:object', '@id');
+                       $object_data['content'] = JsonLD::fetchElement($activity, 'as:content', '@type');
+                       $object_data['push'] = $push;
+               } elseif (in_array($object_type, self::ACCOUNT_TYPES)) {
                        $object_data = [];
                        $object_data['id'] = JsonLD::fetchElement($activity, '@id');
                        $object_data['object_id'] = JsonLD::fetchElement($activity, 'as:object', '@id');
@@ -843,6 +850,14 @@ class Receiver
                                }
                                break;
 
+                       case 'as:Flag':
+                               if (in_array($object_data['object_type'], self::ACCOUNT_TYPES)) {
+                                       ActivityPub\Processor::ReportAccount($object_data);
+                               } else {
+                                       return false;
+                               }
+                               break;
+       
                        case 'as:Remove':
                                if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
                                        ActivityPub\Processor::removeFromFeaturedCollection($object_data);