[COMPONENT][Posting] Blog posts should be Articles by default
This commit is contained in:
parent
10f71e9fed
commit
fa82306f6f
|
@ -86,7 +86,7 @@ class Posting extends Component
|
||||||
* @throws DuplicateFoundException
|
* @throws DuplicateFoundException
|
||||||
* @throws ServerException
|
* @throws ServerException
|
||||||
*/
|
*/
|
||||||
public static function storeLocalPage(
|
public static function storeLocalArticle(
|
||||||
Actor $actor,
|
Actor $actor,
|
||||||
?string $content,
|
?string $content,
|
||||||
string $content_type,
|
string $content_type,
|
||||||
|
@ -117,7 +117,7 @@ class Posting extends Component
|
||||||
rendered: $rendered,
|
rendered: $rendered,
|
||||||
source: $source,
|
source: $source,
|
||||||
);
|
);
|
||||||
$note->setType('page');
|
$note->setType('article');
|
||||||
$note->setTitle($title);
|
$note->setTitle($title);
|
||||||
|
|
||||||
if ($flush_and_notify) {
|
if ($flush_and_notify) {
|
||||||
|
@ -127,7 +127,7 @@ class Posting extends Component
|
||||||
$actor,
|
$actor,
|
||||||
$activity,
|
$activity,
|
||||||
$effective_attentions,
|
$effective_attentions,
|
||||||
_m('Actor {actor_id} created page {note_id}.', [
|
_m('Actor {actor_id} created article {note_id}.', [
|
||||||
'{actor_id}' => $actor->getId(),
|
'{actor_id}' => $actor->getId(),
|
||||||
'{note_id}' => $activity->getObjectId(),
|
'{note_id}' => $activity->getObjectId(),
|
||||||
]),
|
]),
|
||||||
|
|
|
@ -43,8 +43,8 @@ class ActivityPubFixtures extends Fixture
|
||||||
$note_path = self::fixturesPath('objects/note.jsonld', $ontology);
|
$note_path = self::fixturesPath('objects/note.jsonld', $ontology);
|
||||||
$note = Note::fromJson(fread(fopen($note_path, 'r'), filesize($note_path)));
|
$note = Note::fromJson(fread(fopen($note_path, 'r'), filesize($note_path)));
|
||||||
DB::flush();
|
DB::flush();
|
||||||
$page_path = self::fixturesPath('objects/page.jsonld', $ontology);
|
$article_path = self::fixturesPath('objects/article.jsonld', $ontology);
|
||||||
$page = Note::fromJson(fread(fopen($page_path, 'r'), filesize($page_path)));
|
$article = Note::fromJson(fread(fopen($article_path, 'r'), filesize($article_path)));
|
||||||
DB::flush();
|
DB::flush();
|
||||||
$reply_path = self::fixturesPath('objects/reply.jsonld', $ontology);
|
$reply_path = self::fixturesPath('objects/reply.jsonld', $ontology);
|
||||||
$reply = Note::fromJson(fread(fopen($reply_path, 'r'), filesize($reply_path)));
|
$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_path = self::fixturesPath('activities/create_note.jsonld', $ontology);
|
||||||
$create_note = Activity::fromJson(fread(fopen($create_note_path, 'r'), filesize($create_note_path)));
|
$create_note = Activity::fromJson(fread(fopen($create_note_path, 'r'), filesize($create_note_path)));
|
||||||
DB::flush();
|
DB::flush();
|
||||||
$create_page_path = self::fixturesPath('activities/create_page.jsonld', $ontology);
|
$create_article_path = self::fixturesPath('activities/create_article.jsonld', $ontology);
|
||||||
$create_page = Activity::fromJson(fread(fopen($create_page_path, 'r'), filesize($create_page_path)));
|
$create_article = Activity::fromJson(fread(fopen($create_article_path, 'r'), filesize($create_article_path)));
|
||||||
DB::flush();
|
DB::flush();
|
||||||
$create_reply_path = self::fixturesPath('activities/create_reply.jsonld', $ontology);
|
$create_reply_path = self::fixturesPath('activities/create_reply.jsonld', $ontology);
|
||||||
$create_reply = Activity::fromJson(fread(fopen($create_reply_path, 'r'), filesize($create_reply_path)));
|
$create_reply = Activity::fromJson(fread(fopen($create_reply_path, 'r'), filesize($create_reply_path)));
|
||||||
|
|
|
@ -29,15 +29,15 @@
|
||||||
"https://instance.gnusocial.test/actor/21"
|
"https://instance.gnusocial.test/actor/21"
|
||||||
],
|
],
|
||||||
"object": {
|
"object": {
|
||||||
"type": "Page",
|
"type": "Article",
|
||||||
"id": "https://instance.gnusocial.test/object/note/1338",
|
"id": "https://instance.gnusocial.test/object/note/1338",
|
||||||
"published": "2022-03-17T23:30:26+00:00",
|
"published": "2022-03-17T23:30:26+00:00",
|
||||||
"attributedTo": "https://instance.gnusocial.test/actor/42",
|
"attributedTo": "https://instance.gnusocial.test/actor/42",
|
||||||
"name": "hello, world.",
|
"name": "hello, world.",
|
||||||
"content": "<p>This is an interesting page.</p>",
|
"content": "<p>This is an interesting article.</p>",
|
||||||
"mediaType": "text/html",
|
"mediaType": "text/html",
|
||||||
"source": {
|
"source": {
|
||||||
"content": "This is an interesting page.",
|
"content": "This is an interesting article.",
|
||||||
"mediaType": "text/markdown"
|
"mediaType": "text/markdown"
|
||||||
},
|
},
|
||||||
"attachment": [],
|
"attachment": [],
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"type": "Page",
|
"type": "Article",
|
||||||
"@context": [
|
"@context": [
|
||||||
"https://www.w3.org/ns/activitystreams",
|
"https://www.w3.org/ns/activitystreams",
|
||||||
"https://w3id.org/security/v1",
|
"https://w3id.org/security/v1",
|
||||||
|
@ -23,10 +23,10 @@
|
||||||
"published": "2022-03-17T23:30:26+00:00",
|
"published": "2022-03-17T23:30:26+00:00",
|
||||||
"attributedTo": "https://instance.gnusocial.test/actor/42",
|
"attributedTo": "https://instance.gnusocial.test/actor/42",
|
||||||
"name": "hello, world.",
|
"name": "hello, world.",
|
||||||
"content": "<p>This is an interesting page.</p>",
|
"content": "<p>This is an interesting article.</p>",
|
||||||
"mediaType": "text/html",
|
"mediaType": "text/html",
|
||||||
"source": {
|
"source": {
|
||||||
"content": "This is an interesting page.",
|
"content": "This is an interesting article.",
|
||||||
"mediaType": "text/markdown"
|
"mediaType": "text/markdown"
|
||||||
},
|
},
|
||||||
"attachment": [],
|
"attachment": [],
|
|
@ -30,7 +30,7 @@ use Plugin\ActivityPub\ActivityPub;
|
||||||
use Plugin\ActivityPub\Entity\ActivitypubObject;
|
use Plugin\ActivityPub\Entity\ActivitypubObject;
|
||||||
use Plugin\ActivityPub\Util\Explorer;
|
use Plugin\ActivityPub\Util\Explorer;
|
||||||
|
|
||||||
class GSObjectPageTest extends GNUsocialTestCase
|
class GSObjectArticleTest extends GNUsocialTestCase
|
||||||
{
|
{
|
||||||
public function testNoteFromJson()
|
public function testNoteFromJson()
|
||||||
{
|
{
|
||||||
|
@ -39,29 +39,29 @@ class GSObjectPageTest extends GNUsocialTestCase
|
||||||
$actor_uri = 'https://instance.gnusocial.test/actor/42';
|
$actor_uri = 'https://instance.gnusocial.test/actor/42';
|
||||||
$object_uri = 'https://instance.gnusocial.test/object/note/1338';
|
$object_uri = 'https://instance.gnusocial.test/object/note/1338';
|
||||||
$group_uri = 'https://instance.gnusocial.test/actor/21';
|
$group_uri = 'https://instance.gnusocial.test/actor/21';
|
||||||
$page = ActivityPub::getObjectByUri($object_uri, try_online: false);
|
$article = ActivityPub::getObjectByUri($object_uri, try_online: false);
|
||||||
static::assertInstanceOf(Note::class, $page);
|
static::assertInstanceOf(Note::class, $article);
|
||||||
|
|
||||||
static::assertSame(Explorer::getOneFromUri($actor_uri)->getId(), $page->getActorId());
|
static::assertSame(Explorer::getOneFromUri($actor_uri)->getId(), $article->getActorId());
|
||||||
static::assertSame('text/markdown', $page->getContentType());
|
static::assertSame('text/markdown', $article->getContentType());
|
||||||
static::assertSame('This is an interesting page.', $page->getContent());
|
static::assertSame('This is an interesting article.', $article->getContent());
|
||||||
static::assertSame('<p>This is an interesting page.</p>', $page->getRendered());
|
static::assertSame('<p>This is an interesting article.</p>', $article->getRendered());
|
||||||
static::assertSame('ActivityPub', $page->getSource());
|
static::assertSame('ActivityPub', $article->getSource());
|
||||||
static::assertNull($page->getReplyTo());
|
static::assertNull($article->getReplyTo());
|
||||||
static::assertFalse($page->getIsLocal());
|
static::assertFalse($article->getIsLocal());
|
||||||
static::assertSame(VisibilityScope::EVERYWHERE, $page->getScope());
|
static::assertSame(VisibilityScope::EVERYWHERE, $article->getScope());
|
||||||
static::assertSame($object_uri, $page->getUrl());
|
static::assertSame($object_uri, $article->getUrl());
|
||||||
static::assertNull($page->getLanguageLocale());
|
static::assertNull($article->getLanguageLocale());
|
||||||
static::assertSame('page', $page->getType());
|
static::assertSame('article', $article->getType());
|
||||||
static::assertSame('hello, world.', $page->getTitle());
|
static::assertSame('hello, world.', $article->getTitle());
|
||||||
|
|
||||||
$ap_object = ActivitypubObject::getByPK(['object_uri' => $object_uri]);
|
$ap_object = ActivitypubObject::getByPK(['object_uri' => $object_uri]);
|
||||||
static::assertSame(Note::schemaName(), $ap_object->getObjectType());
|
static::assertSame(Note::schemaName(), $ap_object->getObjectType());
|
||||||
static::assertSame($object_uri, $ap_object->getObjectUri());
|
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::assertObjectEquals(Explorer::getOneFromUri($group_uri, try_online: false), $attT[0]);
|
||||||
static::assertSame([], $page->getMentionTargets());
|
static::assertSame([], $article->getMentionTargets());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -168,7 +168,7 @@ class Note extends Model
|
||||||
'type' => match ($type_note->get('type')) {
|
'type' => match ($type_note->get('type')) {
|
||||||
'Article' => 'article',
|
'Article' => 'article',
|
||||||
'Page' => 'page',
|
'Page' => 'page',
|
||||||
default => 'note'
|
default => 'note' // graceful degradation
|
||||||
},
|
},
|
||||||
'source' => $source,
|
'source' => $source,
|
||||||
];
|
];
|
||||||
|
@ -372,6 +372,7 @@ class Note extends Model
|
||||||
'@context' => ActivityPub::$activity_streams_two_context,
|
'@context' => ActivityPub::$activity_streams_two_context,
|
||||||
'type' => $object->getScope() === VisibilityScope::MESSAGE ? 'ChatMessage' : (match ($object->getType()) {
|
'type' => $object->getScope() === VisibilityScope::MESSAGE ? 'ChatMessage' : (match ($object->getType()) {
|
||||||
'note' => 'Note',
|
'note' => 'Note',
|
||||||
|
'article' => 'Article',
|
||||||
'page' => 'Page',
|
'page' => 'Page',
|
||||||
default => throw new Exception('Unsupported note type.')
|
default => throw new Exception('Unsupported note type.')
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -139,7 +139,7 @@ class Post extends Controller
|
||||||
$extra_args = [];
|
$extra_args = [];
|
||||||
Event::handle('AddExtraArgsToNoteContent', [$request, $actor, $data, &$extra_args, $form_params, $form]);
|
Event::handle('AddExtraArgsToNoteContent', [$request, $actor, $data, &$extra_args, $form_params, $form]);
|
||||||
|
|
||||||
[,$note,] = Posting::storeLocalPage(
|
[,$note,] = Posting::storeLocalArticle(
|
||||||
actor: $actor,
|
actor: $actor,
|
||||||
content: $data['content'],
|
content: $data['content'],
|
||||||
content_type: $content_type,
|
content_type: $content_type,
|
||||||
|
|
|
@ -281,7 +281,7 @@ class Favourite extends NoteHandlerPlugin
|
||||||
|
|
||||||
if ($type_activity->get('type') === 'Like') { // Favourite
|
if ($type_activity->get('type') === 'Like') { // Favourite
|
||||||
if ($type_object instanceof \ActivityPhp\Type\AbstractObject) {
|
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 = \Plugin\ActivityPub\Util\Model\Note::fromJson($type_object);
|
||||||
$note_id = $note->getId();
|
$note_id = $note->getId();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -378,7 +378,7 @@ class RepeatNote extends NoteHandlerPlugin
|
||||||
}
|
}
|
||||||
if ($type_activity->get('type') === 'Announce') { // Repeat
|
if ($type_activity->get('type') === 'Announce') { // Repeat
|
||||||
if ($type_object instanceof \ActivityPhp\Type\AbstractObject) {
|
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 = \Plugin\ActivityPub\Util\Model\Note::fromJson($type_object);
|
||||||
$note_id = $note->getId();
|
$note_id = $note->getId();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user