-- ------------------------------------------
-- Friendica 2022.05-dev (Siberian Iris)
--- DB_UPDATE_VERSION 1453
+-- DB_UPDATE_VERSION 1454
-- ------------------------------------------
`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 '',
| 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 | | | |
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');
namespace Friendica\Protocol\ActivityPub;
+use Exception;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
use Friendica\Content\Text\Markdown;
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;
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
*
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 {
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 {
use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) {
- define('DB_UPDATE_VERSION', 1453);
+ define('DB_UPDATE_VERSION', 1454);
}
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" => ""],