From fa82306f6ff3058197af3653caa1891a843442c4 Mon Sep 17 00:00:00 2001 From: Diogo Peralta Cordeiro Date: Mon, 28 Mar 2022 21:04:24 +0100 Subject: [PATCH] [COMPONENT][Posting] Blog posts should be Articles by default --- components/Posting/Posting.php | 6 ++-- .../Test/Fixtures/ActivityPubFixtures.php | 8 ++--- ...eate_page.jsonld => create_article.jsonld} | 6 ++-- .../objects/{page.jsonld => article.jsonld} | 6 ++-- ...ctPageTest.php => GSObjectArticleTest.php} | 36 +++++++++---------- plugins/ActivityPub/Util/Model/Note.php | 13 +++---- plugins/Blog/Controller/Post.php | 2 +- plugins/Favourite/Favourite.php | 2 +- plugins/RepeatNote/RepeatNote.php | 2 +- 9 files changed, 41 insertions(+), 40 deletions(-) rename plugins/ActivityPub/Test/Fixtures/gnusocial/activities/{create_page.jsonld => create_article.jsonld} (90%) rename plugins/ActivityPub/Test/Fixtures/gnusocial/objects/{page.jsonld => article.jsonld} (87%) rename plugins/ActivityPub/Test/Objects/{GSObjectPageTest.php => GSObjectArticleTest.php} (59%) diff --git a/components/Posting/Posting.php b/components/Posting/Posting.php index 513f72f1b2..e50c7f7999 100644 --- a/components/Posting/Posting.php +++ b/components/Posting/Posting.php @@ -86,7 +86,7 @@ class Posting extends Component * @throws DuplicateFoundException * @throws ServerException */ - public static function storeLocalPage( + public static function storeLocalArticle( Actor $actor, ?string $content, string $content_type, @@ -117,7 +117,7 @@ class Posting extends Component rendered: $rendered, source: $source, ); - $note->setType('page'); + $note->setType('article'); $note->setTitle($title); if ($flush_and_notify) { @@ -127,7 +127,7 @@ class Posting extends Component $actor, $activity, $effective_attentions, - _m('Actor {actor_id} created page {note_id}.', [ + _m('Actor {actor_id} created article {note_id}.', [ '{actor_id}' => $actor->getId(), '{note_id}' => $activity->getObjectId(), ]), diff --git a/plugins/ActivityPub/Test/Fixtures/ActivityPubFixtures.php b/plugins/ActivityPub/Test/Fixtures/ActivityPubFixtures.php index 8666adc6e1..c567ff11f9 100644 --- a/plugins/ActivityPub/Test/Fixtures/ActivityPubFixtures.php +++ b/plugins/ActivityPub/Test/Fixtures/ActivityPubFixtures.php @@ -43,8 +43,8 @@ class ActivityPubFixtures extends Fixture $note_path = self::fixturesPath('objects/note.jsonld', $ontology); $note = Note::fromJson(fread(fopen($note_path, 'r'), filesize($note_path))); DB::flush(); - $page_path = self::fixturesPath('objects/page.jsonld', $ontology); - $page = Note::fromJson(fread(fopen($page_path, 'r'), filesize($page_path))); + $article_path = self::fixturesPath('objects/article.jsonld', $ontology); + $article = Note::fromJson(fread(fopen($article_path, 'r'), filesize($article_path))); DB::flush(); $reply_path = self::fixturesPath('objects/reply.jsonld', $ontology); $reply = Note::fromJson(fread(fopen($reply_path, 'r'), filesize($reply_path))); @@ -57,8 +57,8 @@ class ActivityPubFixtures extends Fixture $create_note_path = self::fixturesPath('activities/create_note.jsonld', $ontology); $create_note = Activity::fromJson(fread(fopen($create_note_path, 'r'), filesize($create_note_path))); DB::flush(); - $create_page_path = self::fixturesPath('activities/create_page.jsonld', $ontology); - $create_page = Activity::fromJson(fread(fopen($create_page_path, 'r'), filesize($create_page_path))); + $create_article_path = self::fixturesPath('activities/create_article.jsonld', $ontology); + $create_article = Activity::fromJson(fread(fopen($create_article_path, 'r'), filesize($create_article_path))); DB::flush(); $create_reply_path = self::fixturesPath('activities/create_reply.jsonld', $ontology); $create_reply = Activity::fromJson(fread(fopen($create_reply_path, 'r'), filesize($create_reply_path))); diff --git a/plugins/ActivityPub/Test/Fixtures/gnusocial/activities/create_page.jsonld b/plugins/ActivityPub/Test/Fixtures/gnusocial/activities/create_article.jsonld similarity index 90% rename from plugins/ActivityPub/Test/Fixtures/gnusocial/activities/create_page.jsonld rename to plugins/ActivityPub/Test/Fixtures/gnusocial/activities/create_article.jsonld index 2ce600cf7b..a2643feaef 100755 --- a/plugins/ActivityPub/Test/Fixtures/gnusocial/activities/create_page.jsonld +++ b/plugins/ActivityPub/Test/Fixtures/gnusocial/activities/create_article.jsonld @@ -29,15 +29,15 @@ "https://instance.gnusocial.test/actor/21" ], "object": { - "type": "Page", + "type": "Article", "id": "https://instance.gnusocial.test/object/note/1338", "published": "2022-03-17T23:30:26+00:00", "attributedTo": "https://instance.gnusocial.test/actor/42", "name": "hello, world.", - "content": "

This is an interesting page.

", + "content": "

This is an interesting article.

", "mediaType": "text/html", "source": { - "content": "This is an interesting page.", + "content": "This is an interesting article.", "mediaType": "text/markdown" }, "attachment": [], diff --git a/plugins/ActivityPub/Test/Fixtures/gnusocial/objects/page.jsonld b/plugins/ActivityPub/Test/Fixtures/gnusocial/objects/article.jsonld similarity index 87% rename from plugins/ActivityPub/Test/Fixtures/gnusocial/objects/page.jsonld rename to plugins/ActivityPub/Test/Fixtures/gnusocial/objects/article.jsonld index c82325d077..4eac04613d 100755 --- a/plugins/ActivityPub/Test/Fixtures/gnusocial/objects/page.jsonld +++ b/plugins/ActivityPub/Test/Fixtures/gnusocial/objects/article.jsonld @@ -1,5 +1,5 @@ { - "type": "Page", + "type": "Article", "@context": [ "https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1", @@ -23,10 +23,10 @@ "published": "2022-03-17T23:30:26+00:00", "attributedTo": "https://instance.gnusocial.test/actor/42", "name": "hello, world.", - "content": "

This is an interesting page.

", + "content": "

This is an interesting article.

", "mediaType": "text/html", "source": { - "content": "This is an interesting page.", + "content": "This is an interesting article.", "mediaType": "text/markdown" }, "attachment": [], diff --git a/plugins/ActivityPub/Test/Objects/GSObjectPageTest.php b/plugins/ActivityPub/Test/Objects/GSObjectArticleTest.php similarity index 59% rename from plugins/ActivityPub/Test/Objects/GSObjectPageTest.php rename to plugins/ActivityPub/Test/Objects/GSObjectArticleTest.php index 1555228998..baf4696cb5 100644 --- a/plugins/ActivityPub/Test/Objects/GSObjectPageTest.php +++ b/plugins/ActivityPub/Test/Objects/GSObjectArticleTest.php @@ -30,7 +30,7 @@ use Plugin\ActivityPub\ActivityPub; use Plugin\ActivityPub\Entity\ActivitypubObject; use Plugin\ActivityPub\Util\Explorer; -class GSObjectPageTest extends GNUsocialTestCase +class GSObjectArticleTest extends GNUsocialTestCase { public function testNoteFromJson() { @@ -39,29 +39,29 @@ class GSObjectPageTest extends GNUsocialTestCase $actor_uri = 'https://instance.gnusocial.test/actor/42'; $object_uri = 'https://instance.gnusocial.test/object/note/1338'; $group_uri = 'https://instance.gnusocial.test/actor/21'; - $page = ActivityPub::getObjectByUri($object_uri, try_online: false); - static::assertInstanceOf(Note::class, $page); + $article = ActivityPub::getObjectByUri($object_uri, try_online: false); + static::assertInstanceOf(Note::class, $article); - static::assertSame(Explorer::getOneFromUri($actor_uri)->getId(), $page->getActorId()); - static::assertSame('text/markdown', $page->getContentType()); - static::assertSame('This is an interesting page.', $page->getContent()); - static::assertSame('

This is an interesting page.

', $page->getRendered()); - static::assertSame('ActivityPub', $page->getSource()); - static::assertNull($page->getReplyTo()); - static::assertFalse($page->getIsLocal()); - static::assertSame(VisibilityScope::EVERYWHERE, $page->getScope()); - static::assertSame($object_uri, $page->getUrl()); - static::assertNull($page->getLanguageLocale()); - static::assertSame('page', $page->getType()); - static::assertSame('hello, world.', $page->getTitle()); + static::assertSame(Explorer::getOneFromUri($actor_uri)->getId(), $article->getActorId()); + static::assertSame('text/markdown', $article->getContentType()); + static::assertSame('This is an interesting article.', $article->getContent()); + static::assertSame('

This is an interesting article.

', $article->getRendered()); + static::assertSame('ActivityPub', $article->getSource()); + static::assertNull($article->getReplyTo()); + static::assertFalse($article->getIsLocal()); + static::assertSame(VisibilityScope::EVERYWHERE, $article->getScope()); + static::assertSame($object_uri, $article->getUrl()); + static::assertNull($article->getLanguageLocale()); + static::assertSame('article', $article->getType()); + static::assertSame('hello, world.', $article->getTitle()); $ap_object = ActivitypubObject::getByPK(['object_uri' => $object_uri]); static::assertSame(Note::schemaName(), $ap_object->getObjectType()); static::assertSame($object_uri, $ap_object->getObjectUri()); - static::assertSame($page->getId(), $ap_object->getObjectId()); + static::assertSame($article->getId(), $ap_object->getObjectId()); - static::assertCount(1, $attT = $page->getAttentionTargets()); + static::assertCount(1, $attT = $article->getAttentionTargets()); static::assertObjectEquals(Explorer::getOneFromUri($group_uri, try_online: false), $attT[0]); - static::assertSame([], $page->getMentionTargets()); + static::assertSame([], $article->getMentionTargets()); } } diff --git a/plugins/ActivityPub/Util/Model/Note.php b/plugins/ActivityPub/Util/Model/Note.php index 5a770fe578..74a3e7e198 100644 --- a/plugins/ActivityPub/Util/Model/Note.php +++ b/plugins/ActivityPub/Util/Model/Note.php @@ -168,7 +168,7 @@ class Note extends Model 'type' => match ($type_note->get('type')) { 'Article' => 'article', 'Page' => 'page', - default => 'note' + default => 'note' // graceful degradation }, 'source' => $source, ]; @@ -369,11 +369,12 @@ class Note extends Model } $attr = [ - '@context' => ActivityPub::$activity_streams_two_context, - 'type' => $object->getScope() === VisibilityScope::MESSAGE ? 'ChatMessage' : (match ($object->getType()) { - 'note' => 'Note', - 'page' => 'Page', - default => throw new Exception('Unsupported note type.') + '@context' => ActivityPub::$activity_streams_two_context, + 'type' => $object->getScope() === VisibilityScope::MESSAGE ? 'ChatMessage' : (match ($object->getType()) { + 'note' => 'Note', + 'article' => 'Article', + 'page' => 'Page', + default => throw new Exception('Unsupported note type.') }), 'id' => $object->getUrl(), 'url' => $object->getUrl(), diff --git a/plugins/Blog/Controller/Post.php b/plugins/Blog/Controller/Post.php index 3575e741a9..47b80b5703 100644 --- a/plugins/Blog/Controller/Post.php +++ b/plugins/Blog/Controller/Post.php @@ -139,7 +139,7 @@ class Post extends Controller $extra_args = []; Event::handle('AddExtraArgsToNoteContent', [$request, $actor, $data, &$extra_args, $form_params, $form]); - [,$note,] = Posting::storeLocalPage( + [,$note,] = Posting::storeLocalArticle( actor: $actor, content: $data['content'], content_type: $content_type, diff --git a/plugins/Favourite/Favourite.php b/plugins/Favourite/Favourite.php index ed24f59ea1..60c924e439 100644 --- a/plugins/Favourite/Favourite.php +++ b/plugins/Favourite/Favourite.php @@ -281,7 +281,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' || $type_object->get('type') === 'ChatMessage' || $type_object->get('type') === 'Page') { + if (\in_array($type_object->get('type'), ['Note', 'ChatMessage', 'Article', 'Page'])) { $note = \Plugin\ActivityPub\Util\Model\Note::fromJson($type_object); $note_id = $note->getId(); } else { diff --git a/plugins/RepeatNote/RepeatNote.php b/plugins/RepeatNote/RepeatNote.php index 4e6b6c52b6..1cdffcb8df 100644 --- a/plugins/RepeatNote/RepeatNote.php +++ b/plugins/RepeatNote/RepeatNote.php @@ -378,7 +378,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' || $type_object->get('type') === 'ChatMessage' || $type_object->get('type') === 'Article' || $type_object->get('type') === 'Page') { + if (\in_array($type_object->get('type'), ['Note', 'ChatMessage', 'Article', 'Page'])) { $note = \Plugin\ActivityPub\Util\Model\Note::fromJson($type_object); $note_id = $note->getId(); } else {