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

@ -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 '',

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

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 {

View 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" => ""],