Preparation for "Featured" collection added

This commit is contained in:
Michael
2022-04-04 23:07:44 +00:00
parent e6caed7b5f
commit 61abc6377d
6 changed files with 88 additions and 6 deletions

View 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');

View 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
*

View 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 {