[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 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(),
|
||||
]),
|
||||
|
@ -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)));
|
||||
|
@ -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": "<p>This is an interesting page.</p>",
|
||||
"content": "<p>This is an interesting article.</p>",
|
||||
"mediaType": "text/html",
|
||||
"source": {
|
||||
"content": "This is an interesting page.",
|
||||
"content": "This is an interesting article.",
|
||||
"mediaType": "text/markdown"
|
||||
},
|
||||
"attachment": [],
|
@ -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": "<p>This is an interesting page.</p>",
|
||||
"content": "<p>This is an interesting article.</p>",
|
||||
"mediaType": "text/html",
|
||||
"source": {
|
||||
"content": "This is an interesting page.",
|
||||
"content": "This is an interesting article.",
|
||||
"mediaType": "text/markdown"
|
||||
},
|
||||
"attachment": [],
|
@ -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('<p>This is an interesting page.</p>', $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('<p>This is an interesting article.</p>', $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());
|
||||
}
|
||||
}
|
@ -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(),
|
||||
|
@ -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,
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user