[PLUGIN][ActivityPub][Model][Note] Add support to Pages

This commit is contained in:
Diogo Peralta Cordeiro 2022-02-19 04:45:02 +00:00
parent 75837af412
commit 8cf60275e6
No known key found for this signature in database
GPG Key ID: 18D2D35001FBFAB0
5 changed files with 8 additions and 6 deletions

View File

@ -163,7 +163,7 @@ class Activity extends Model
$attr = [
'type' => $gs_verb_to_activity_streams_two_verb,
'@context' => 'https://www.w3.org/ns/activitystreams',
'@context' => ['https://www.w3.org/ns/activitystreams'],
'id' => Router::url('activity_view', ['id' => $object->getId()], Router::ABSOLUTE_URL),
'published' => $object->getCreated()->format(DateTimeInterface::RFC3339),
'actor' => $object->getActor()->getUri(Router::ABSOLUTE_URL),
@ -188,7 +188,7 @@ class Activity extends Model
// If embedded non tombstone Object
if (!\is_string($attr['object']) && $attr['object']->get('type') !== 'Tombstone') {
// Little special case
if ($attr['type'] === 'Create' && $attr['object']->get('type') === 'Note') {
if ($attr['type'] === 'Create' && ($attr['object']->get('type') === 'Note' || $attr['object']->get('type') === 'Page')) {
$attr['to'] = $attr['object']->get('to') ?? [];
$attr['cc'] = $attr['object']->get('cc') ?? [];
}

View File

@ -52,7 +52,7 @@ class ActivityCreate extends Activity
protected static function handle_core_activity(\App\Entity\Actor $actor, AbstractObject $type_activity, mixed $type_object, ?ActivitypubActivity &$ap_act): ActivitypubActivity
{
if ($type_object instanceof AbstractObject) {
if ($type_object->get('type') === 'Note') {
if ($type_object->get('type') === 'Note' || $type_object->get('type') === 'Page') {
$actual_to = array_flip(is_string($type_object->get('to')) ? [$type_object->get('to')] : $type_object->get('to'));
$actual_cc = array_flip(is_string($type_object->get('cc')) ? [$type_object->get('cc')] : $type_object->get('cc'));
foreach (is_string($type_activity->get('to')) ? [$type_activity->get('to')] : $type_activity->get('to') as $to) {

View File

@ -39,6 +39,7 @@ use App\Core\DB\DB;
use App\Core\Event;
use App\Core\GSFile;
use App\Core\HTTPClient;
use App\Entity\NoteType;
use function App\Core\I18n\_m;
use App\Core\Log;
use App\Core\Router\Router;
@ -151,6 +152,7 @@ class Note extends Model
'actor_id' => $actor_id,
'reply_to' => $reply_to = $handleInReplyTo($type_note),
'modified' => new DateTime(),
'type' => match ($type_note->get('type')) {'Page' => NoteType::PAGE, default => NoteType::NOTE},
'source' => $source,
];
@ -329,7 +331,7 @@ class Note extends Model
$attr = [
'@context' => 'https://www.w3.org/ns/activitystreams',
'type' => 'Note',
'type' => match($object->getType()) {NoteType::NOTE => 'Note', NoteType::PAGE => 'Page'},
'id' => $object->getUrl(),
'published' => $object->getCreated()->format(DateTimeInterface::RFC3339),
'attributedTo' => $object->getActor()->getUri(Router::ABSOLUTE_URL),

View File

@ -286,7 +286,7 @@ class Favourite extends NoteHandlerPlugin
}
if ($type_activity->get('type') === 'Like') { // Favourite
if ($type_object instanceof \ActivityPhp\Type\AbstractObject) {
if ($type_object->get('type') === 'Note') {
if ($type_object->get('type') === 'Note' || $type_object->get('type') === 'Page') {
$note_id = \Plugin\ActivityPub\Util\Model\Note::fromJson($type_object)->getId();
} else {
return Event::next;

View File

@ -364,7 +364,7 @@ class RepeatNote extends NoteHandlerPlugin
}
if ($type_activity->get('type') === 'Announce') { // Repeat
if ($type_object instanceof \ActivityPhp\Type\AbstractObject) {
if ($type_object->get('type') === 'Note') {
if ($type_object->get('type') === 'Note' || $type_object->get('type') === 'Page') {
$note = \Plugin\ActivityPub\Util\Model\Note::fromJson($type_object);
$note_id = $note->getId();
} else {