]> git.mxchange.org Git - friendica.git/commitdiff
Preparation for "Featured" collection added
authorMichael <heluecht@pirati.ca>
Mon, 4 Apr 2022 23:07:44 +0000 (23:07 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 4 Apr 2022 23:07:44 +0000 (23:07 +0000)
database.sql
doc/database/db_apcontact.md
src/Model/APContact.php
src/Protocol/ActivityPub/Processor.php
src/Protocol/ActivityPub/Receiver.php
static/dbstructure.config.php

index ffe020203319fba875772d6cae57ea771e6c060c..b986cc409f9df08edc702acd2d22a845796f0b61 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 2022.05-dev (Siberian Iris)
--- DB_UPDATE_VERSION 1453
+-- DB_UPDATE_VERSION 1454
 -- ------------------------------------------
 
 
@@ -332,6 +332,8 @@ CREATE TABLE IF NOT EXISTS `apcontact` (
        `inbox` varchar(255) NOT NULL COMMENT '',
        `outbox` varchar(255) COMMENT '',
        `sharedinbox` varchar(255) COMMENT '',
+       `featured` varchar(255) COMMENT 'Address for the collection of featured posts',
+       `featured-tags` varchar(255) COMMENT 'Address for the collection of featured tags',
        `manually-approve` boolean COMMENT '',
        `discoverable` boolean COMMENT 'Mastodon extension: true if profile is published in their directory',
        `nick` varchar(255) NOT NULL DEFAULT '' COMMENT '',
index ee95d994f9b018407053334837a85ae5b55f169f..34cf4ec18bb1077621f458974fe1819ed849c1a2 100644 (file)
@@ -17,6 +17,8 @@ Fields
 | inbox            |                                                                     | varchar(255)   | NO   |     | NULL                |       |
 | outbox           |                                                                     | varchar(255)   | YES  |     | NULL                |       |
 | sharedinbox      |                                                                     | varchar(255)   | YES  |     | NULL                |       |
+| featured         | Address for the collection of featured posts                        | varchar(255)   | YES  |     | NULL                |       |
+| featured-tags    | Address for the collection of featured tags                         | varchar(255)   | YES  |     | NULL                |       |
 | manually-approve |                                                                     | boolean        | YES  |     | NULL                |       |
 | discoverable     | Mastodon extension: true if profile is published in their directory | boolean        | YES  |     | NULL                |       |
 | nick             |                                                                     | varchar(255)   | NO   |     |                     |       |
index 9759876fab5b22a9b7027bba2ba1a1a48e9687b3..deed6299de8613f8c3c6fe78a15e0768651a81c0 100644 (file)
@@ -232,6 +232,9 @@ class APContact
                        self::unarchiveInbox($apcontact['sharedinbox'], true);
                }
 
+               $apcontact['featured']      = JsonLD::fetchElement($compacted, 'toot:featured', '@id');
+               $apcontact['featured-tags'] = JsonLD::fetchElement($compacted, 'toot:featuredTags', '@id');
+
                $apcontact['nick'] = JsonLD::fetchElement($compacted, 'as:preferredUsername', '@value') ?? '';
                $apcontact['name'] = JsonLD::fetchElement($compacted, 'as:name', '@value');
 
index 533d3a29b10a11767fcfc7634f7182184135692c..647357811ed987ed9f84e51c742693ad7fa838ca 100644 (file)
@@ -21,6 +21,7 @@
 
 namespace Friendica\Protocol\ActivityPub;
 
+use Exception;
 use Friendica\Content\Text\BBCode;
 use Friendica\Content\Text\HTML;
 use Friendica\Content\Text\Markdown;
@@ -40,6 +41,7 @@ use Friendica\Model\Mail;
 use Friendica\Model\Tag;
 use Friendica\Model\User;
 use Friendica\Model\Post;
+use Friendica\Network\HTTPException\InternalServerErrorException;
 use Friendica\Protocol\Activity;
 use Friendica\Protocol\ActivityPub;
 use Friendica\Protocol\Relay;
@@ -439,6 +441,79 @@ class Processor
                self::postItem($activity, $item);
        }
 
+       /**
+        * Fetch the Uri-Id of a post for the "featured" collection
+        *
+        * @param array $activity 
+        * @return null|int 
+        */
+       private static function getUriIdForFeaturedCollection(array $activity)
+       {
+               $actor = APContact::getByURL($activity['actor']);
+               if (empty($actor)) {
+                       return null;
+               }
+
+               // Refetch the account when the "featured" collection is missing.
+               // This can be removed in a future version (end of 2022 should be good).
+               if (empty($actor['featured'])) {
+                       $actor = APContact::getByURL($activity['actor'], true);
+                       if (empty($actor)) {
+                               return null;
+                       }
+               }
+
+               if ($activity['target_id'] != $actor['featured']) {
+                       return null;
+               }
+
+               $id = Contact::getIdForURL($activity['actor']);
+               if (empty($id)) {
+                       return null;
+               }
+
+               $parent = Post::selectFirst(['uri-id'], ['uri' => $activity['object_id'], 'author-id' => $id]);
+               if (!empty($parent['uri-id'])) {
+                       return $parent['uri-id'];
+               }
+
+               return null;
+       }
+
+       /**
+        * Add a post to the "Featured" collection
+        *
+        * @param array $activity 
+        */
+       public static function addToFeaturedCollection(array $activity)
+       {
+               $uriid = self::getUriIdForFeaturedCollection($activity);
+               if (empty($uriid)) {
+                       return;
+               }
+
+               Logger::debug('Add post to featured collection', ['uri-id' => $uriid]);
+
+               // @todo Add functionality
+       }
+
+       /**
+        * Remove a post to the "Featured" collection
+        *
+        * @param array $activity 
+        */
+       public static function removeFromFeaturedCollection(array $activity)
+       {
+               $uriid = self::getUriIdForFeaturedCollection($activity);
+               if (empty($uriid)) {
+                       return;
+               }
+
+               Logger::debug('Remove post from featured collection', ['uri-id' => $uriid]);
+
+               // @todo Add functionality
+       }
+
        /**
         * Create an event
         *
index b14780b19686ce42fd7768787ad49ea0be5a43cb..0894ffc453c1b2e0bc70b25ac09d9cd762425b4c 100644 (file)
@@ -578,8 +578,7 @@ class Receiver
                                if ($object_data['object_type'] == 'as:tag') {
                                        ActivityPub\Processor::addTag($object_data);
                                } elseif (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
-                                       // Seems to be used by Mastodon to announce that a post is pinned
-                                       self::storeUnhandledActivity(false, $type, $object_data, $activity, $body, $uid, $trust_source, $push, $signer);
+                                       ActivityPub\Processor::addToFeaturedCollection($object_data);
                                } elseif ($object_data['object_type'] == '') {
                                        // The object type couldn't be determined. We don't have it and we can't fetch it. We ignore this activity.
                                } else {
@@ -680,8 +679,7 @@ class Receiver
 
                        case 'as:Remove':
                                if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
-                                       // Seems to be used by Mastodon to remove the pinned status of a post
-                                       self::storeUnhandledActivity(false, $type, $object_data, $activity, $body, $uid, $trust_source, $push, $signer);
+                                       ActivityPub\Processor::removeFromFeaturedCollection($object_data);                                      
                                } elseif ($object_data['object_type'] == '') {
                                        // The object type couldn't be determined. We don't have it and we can't fetch it. We ignore this activity.
                                } else {
index fd1e39cc2e124e67a9ea273e6512e888d31916be..36c9ca3e0a3767afcdccf57baf50e32410c8468c 100644 (file)
@@ -55,7 +55,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1453);
+       define('DB_UPDATE_VERSION', 1454);
 }
 
 return [
@@ -394,6 +394,8 @@ return [
                        "inbox" => ["type" => "varchar(255)", "not null" => "1", "comment" => ""],
                        "outbox" => ["type" => "varchar(255)", "comment" => ""],
                        "sharedinbox" => ["type" => "varchar(255)", "comment" => ""],
+                       "featured" => ["type" => "varchar(255)", "comment" => "Address for the collection of featured posts"],
+                       "featured-tags" => ["type" => "varchar(255)", "comment" => "Address for the collection of featured tags"],
                        "manually-approve" => ["type" => "boolean", "comment" => ""],
                        "discoverable" => ["type" => "boolean", "comment" => "Mastodon extension: true if profile is published in their directory"],
                        "nick" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],