[PLUGIN][ActivityPub][Model][Note] fromJson: Respect source attribute and @language from context
This commit is contained in:
parent
27706d63f4
commit
dd62825169
@ -141,25 +141,33 @@ class Note extends Model
|
||||
$actor = Explorer::getOneFromUri($type_note->get('attributedTo'));
|
||||
$actor_id = $actor->getId();
|
||||
}
|
||||
|
||||
// Figure the locale of the note when possible
|
||||
$locale = null;
|
||||
if (\array_key_exists('@language', $type_note->get('@context'))) {
|
||||
$locale = $type_note->get('@context')['@language'];
|
||||
if ($locale === 'und') {
|
||||
$locale = null;
|
||||
}
|
||||
}
|
||||
|
||||
$map = [
|
||||
'is_local' => false,
|
||||
'created' => new DateTime($type_note->get('published') ?? 'now'),
|
||||
'content' => $type_note->get('content') ?? null,
|
||||
'rendered' => \is_null($type_note->get('content')) ? null : HTML::sanitize($type_note->get('content')),
|
||||
'title' => $type_note->get('name') ?? null,
|
||||
'content_type' => 'text/html',
|
||||
'language_id' => $type_note->get('contentLang') ?? null,
|
||||
'url' => $type_note->get('url') ?? $type_note->get('id'),
|
||||
'actor_id' => $actor_id,
|
||||
'reply_to' => $reply_to = $handleInReplyTo($type_note),
|
||||
'modified' => new DateTime(),
|
||||
'type' => match ($type_note->get('type')) {
|
||||
'Page' => 'page',
|
||||
default => 'note'
|
||||
'is_local' => false,
|
||||
'created' => new DateTime($type_note->get('published') ?? 'now'),
|
||||
'title' => $type_note->get('name') ?? null,
|
||||
'language_id' => $type_note->get('contentLang') ?? null,
|
||||
'url' => $type_note->get('url') ?? $type_note->get('id'),
|
||||
'actor_id' => $actor_id,
|
||||
'reply_to' => $reply_to = $handleInReplyTo($type_note),
|
||||
'modified' => new DateTime(),
|
||||
'type' => match ($type_note->get('type')) {
|
||||
'Page' => 'page',
|
||||
default => 'note'
|
||||
},
|
||||
'source' => $source,
|
||||
];
|
||||
|
||||
// Language
|
||||
if (!\is_null($map['language_id'])) {
|
||||
$map['language_id'] = Language::getByLocale($map['language_id'])->getId();
|
||||
} else {
|
||||
@ -230,6 +238,19 @@ class Note extends Model
|
||||
}
|
||||
}
|
||||
|
||||
// content and rendered
|
||||
$map['content'] = $type_note->get('content') ?? null;
|
||||
$map['content_type'] = \is_null($map['content']) ? null : 'text/html';
|
||||
$map['rendered'] = \is_null($map['content']) ? null : HTML::sanitize($map['content']);
|
||||
if ($type_note->has('source')) {
|
||||
$map['content_type'] = $type_note->get('source')['mediaType'] ?? null;
|
||||
$map['content'] = $type_note->get('source')['content'];
|
||||
if (\is_null($map['rendered'])) {
|
||||
// It doesn't have the content pre-rendered, we can render it ourselves then
|
||||
Event::handle('RenderNoteContent', [$map['content'], $map['content_type'], &$map['rendered'], $actor, $locale, /*&$mentions = */ []]);
|
||||
}
|
||||
}
|
||||
|
||||
$obj = GSNote::create($map);
|
||||
DB::persist($obj);
|
||||
|
||||
@ -303,8 +324,7 @@ class Note extends Model
|
||||
}
|
||||
}
|
||||
|
||||
// The content would be non-sanitized text/html
|
||||
Event::handle('ProcessNoteContent', [$obj, $obj->getRendered(), $obj->getContentType(), $process_note_content_extra_args = ['TagProcessed' => true, 'ignoreLinks' => $mention_uris]]);
|
||||
Event::handle('ProcessNoteContent', [$obj, $obj->getContent(), $obj->getContentType(), $process_note_content_extra_args = ['TagProcessed' => true, 'ignoreLinks' => $mention_uris]]);
|
||||
|
||||
foreach ($attention_targets as $target) {
|
||||
DB::persist(Attention::create(['object_type' => GSNote::schemaName(), 'object_id' => $obj->getId(), 'target_id' => $target->getId()]));
|
||||
|
@ -435,7 +435,7 @@ abstract class Formatting
|
||||
*
|
||||
* @return array [partially-rendered HTML, array of mentions]
|
||||
*/
|
||||
public static function linkifyMentions(string $text, Actor $author, string $locale): array
|
||||
public static function linkifyMentions(string $text, Actor $author, ?string $locale): array
|
||||
{
|
||||
$mentions = self::findMentions($text, $author);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user