From 8cf60275e6982af51133950f06843b7cc18e378b Mon Sep 17 00:00:00 2001 From: Diogo Peralta Cordeiro Date: Sat, 19 Feb 2022 04:45:02 +0000 Subject: [PATCH] [PLUGIN][ActivityPub][Model][Note] Add support to Pages --- plugins/ActivityPub/Util/Model/Activity.php | 4 ++-- plugins/ActivityPub/Util/Model/ActivityCreate.php | 2 +- plugins/ActivityPub/Util/Model/Note.php | 4 +++- plugins/Favourite/Favourite.php | 2 +- plugins/RepeatNote/RepeatNote.php | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/plugins/ActivityPub/Util/Model/Activity.php b/plugins/ActivityPub/Util/Model/Activity.php index 6df72542d2..3dcac6eab2 100644 --- a/plugins/ActivityPub/Util/Model/Activity.php +++ b/plugins/ActivityPub/Util/Model/Activity.php @@ -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') ?? []; } diff --git a/plugins/ActivityPub/Util/Model/ActivityCreate.php b/plugins/ActivityPub/Util/Model/ActivityCreate.php index 4e5234fc0b..abc934b410 100644 --- a/plugins/ActivityPub/Util/Model/ActivityCreate.php +++ b/plugins/ActivityPub/Util/Model/ActivityCreate.php @@ -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) { diff --git a/plugins/ActivityPub/Util/Model/Note.php b/plugins/ActivityPub/Util/Model/Note.php index 7b518c958f..c4287936cd 100644 --- a/plugins/ActivityPub/Util/Model/Note.php +++ b/plugins/ActivityPub/Util/Model/Note.php @@ -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), diff --git a/plugins/Favourite/Favourite.php b/plugins/Favourite/Favourite.php index dfd9ea993d..a456850f55 100644 --- a/plugins/Favourite/Favourite.php +++ b/plugins/Favourite/Favourite.php @@ -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; diff --git a/plugins/RepeatNote/RepeatNote.php b/plugins/RepeatNote/RepeatNote.php index 522677ab1d..01aa25785b 100644 --- a/plugins/RepeatNote/RepeatNote.php +++ b/plugins/RepeatNote/RepeatNote.php @@ -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 {