[PLUGIN][ActivityPub] Correct @context

This commit is contained in:
2022-02-23 17:39:11 +00:00
parent 05b7f2c28b
commit f3c2e49e3f
9 changed files with 99 additions and 58 deletions

View File

@@ -64,9 +64,6 @@ class Activity extends Model
* Create an Entity from an ActivityStreams 2.0 JSON string
* This will persist new GSActivities, GSObjects, and APActivity
*
* @param string|AbstractObject $json
* @param array $options
* @return ActivitypubActivity
* @throws ClientExceptionInterface
* @throws NoSuchActorException
* @throws NotImplementedException
@@ -121,6 +118,7 @@ class Activity extends Model
case 'Undo':
$object_type = $type_object instanceof AbstractObject ? match ($type_object->get('type')) {
'Note' => \App\Entity\Note::class,
// no break
default => throw new NotImplementedException('Unsupported Undo of Object Activity.'),
} : $type_object::class;
@@ -164,7 +162,7 @@ class Activity extends Model
$attr = [
'type' => $gs_verb_to_activity_streams_two_verb,
'@context' => ['https://www.w3.org/ns/activitystreams'],
'@context' => ActivityPub::$activity_streams_two_context,
'id' => Router::url('activity_view', ['id' => $object->getId()], Router::ABSOLUTE_URL),
'published' => $object->getCreated()->format(DateTimeInterface::RFC3339),
'actor' => $object->getActor()->getUri(Router::ABSOLUTE_URL),

View File

@@ -42,7 +42,6 @@ use App\Core\Log;
use App\Core\Router\Router;
use App\Entity\Actor as GSActor;
use App\Util\Exception\ServerException;
use App\Util\Formatting;
use App\Util\TemporaryFile;
use Component\Avatar\Avatar;
use Component\Group\Entity\LocalGroup;
@@ -50,6 +49,7 @@ use DateTime;
use DateTimeInterface;
use Exception;
use InvalidArgumentException;
use Plugin\ActivityPub\ActivityPub;
use Plugin\ActivityPub\Entity\ActivitypubActor;
use Plugin\ActivityPub\Entity\ActivitypubRsa;
use Plugin\ActivityPub\Util\Model;
@@ -168,12 +168,12 @@ class Actor extends Model
$avatar->delete();
}
DB::persist($attachment);
DB::persist(\Component\Avatar\Entity\Avatar::create([
'actor_id' => $actor->getId(),
'attachment_id' => $attachment->getId(),
'title' => $object->get('icon')->get('name') ?? null,
]));
DB::persist($attachment);
DB::persist(\Component\Avatar\Entity\Avatar::create([
'actor_id' => $actor->getId(),
'attachment_id' => $attachment->getId(),
'title' => $object->get('icon')->get('name') ?? null,
]));
Event::handle('AvatarUpdate', [$actor->getId()]);
}
@@ -212,8 +212,8 @@ class Actor extends Model
$public_key = $rsa->getPublicKey();
$uri = $object->getUri(Router::ABSOLUTE_URL);
$attr = [
'@context' => 'https://www.w3.org/ns/activitystreams',
'type' => ($object->getType() === GSActor::GROUP) ? (DB::findOneBy(LocalGroup::class, ['actor_id' => $object->getId()], return_null: true)?->getType() === 'organisation' ? 'Organization' : 'Group'): self::$_gs_actor_type_to_as2_actor_type[$object->getType()],
'@context' => ActivityPub::$activity_streams_two_context,
'type' => ($object->getType() === GSActor::GROUP) ? (DB::findOneBy(LocalGroup::class, ['actor_id' => $object->getId()], return_null: true)?->getType() === 'organisation' ? 'Organization' : 'Group') : self::$_gs_actor_type_to_as2_actor_type[$object->getType()],
'id' => $uri,
'inbox' => Router::url('activitypub_actor_inbox', ['gsactor_id' => $object->getId()], Router::ABSOLUTE_URL),
'outbox' => Router::url('activitypub_actor_outbox', ['gsactor_id' => $object->getId()], Router::ABSOLUTE_URL),

View File

@@ -39,13 +39,12 @@ use App\Core\DB\DB;
use App\Core\Event;
use App\Core\GSFile;
use App\Core\HTTPClient;
use App\Entity\NoteType;
use Component\Notification\Entity\Attention;
use function App\Core\I18n\_m;
use App\Core\Log;
use App\Core\Router\Router;
use App\Core\VisibilityScope;
use App\Entity\Note as GSNote;
use App\Entity\NoteType;
use App\Util\Common;
use App\Util\Exception\ClientException;
use App\Util\Exception\DuplicateFoundException;
@@ -59,6 +58,7 @@ use Component\Attachment\Entity\AttachmentToNote;
use Component\Conversation\Conversation;
use Component\FreeNetwork\FreeNetwork;
use Component\Language\Entity\Language;
use Component\Notification\Entity\Attention;
use Component\Tag\Entity\NoteTag;
use Component\Tag\Tag;
use DateTime;
@@ -146,7 +146,7 @@ class Note extends Model
'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')),
'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,
@@ -154,8 +154,10 @@ 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,
'type' => match ($type_note->get('type')) {
'Page' => NoteType::PAGE, default => NoteType::NOTE
},
'source' => $source,
];
if (!\is_null($map['language_id'])) {
@@ -188,7 +190,7 @@ class Note extends Model
continue;
}
try {
$actor = ActivityPub::getActorByUri($target);
$actor = ActivityPub::getActorByUri($target);
$object_mentions_ids[$actor->getId()] = $target;
// If $to is a group and note is unlisted, set note's scope as Group
if ($actor->isGroup() && $map['scope'] === 'unlisted') {
@@ -209,7 +211,7 @@ class Note extends Model
continue;
}
try {
$actor = ActivityPub::getActorByUri($target);
$actor = ActivityPub::getActorByUri($target);
$object_mentions_ids[$actor->getId()] = $target;
} catch (Exception $e) {
Log::debug('ActivityPub->Model->Note->fromJson->getActorByUri', [$e]);
@@ -231,7 +233,7 @@ class Note extends Model
// Create an attachment for this
$temp_file = new TemporaryFile();
$temp_file->write($media);
$filesize = $temp_file->getSize();
$filesize = $temp_file->getSize();
$max_file_size = Common::getUploadLimit();
if ($max_file_size < $filesize) {
throw new ClientException(_m('No file may be larger than {quota} bytes and the file you sent was {size} bytes. '
@@ -254,7 +256,7 @@ class Note extends Model
case 'Mention':
case 'Group':
try {
$actor = ActivityPub::getActorByUri($ap_tag->get('href'));
$actor = ActivityPub::getActorByUri($ap_tag->get('href'));
$object_mentions_ids[$actor->getId()] = $ap_tag->get('href');
} catch (Exception $e) {
Log::debug('ActivityPub->Model->Note->fromJson->getActorByUri', [$e]);
@@ -272,8 +274,8 @@ class Note extends Model
}
break;
case 'Hashtag':
$match = ltrim($ap_tag->get('name'), '#');
$tag = Tag::extract($match);
$match = ltrim($ap_tag->get('name'), '#');
$tag = Tag::extract($match);
$canonical_tag = $ap_tag->get('canonical') ?? Tag::canonicalTag($tag, \is_null($lang_id = $obj->getLanguageId()) ? null : Language::getById($lang_id)->getLocale());
DB::persist(NoteTag::create([
'tag' => $tag,
@@ -334,8 +336,10 @@ class Note extends Model
}
$attr = [
'@context' => 'https://www.w3.org/ns/activitystreams',
'type' => match($object->getType()) {NoteType::NOTE => 'Note', NoteType::PAGE => 'Page'},
'@context' => ActivityPub::$activity_streams_two_context,
'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),
@@ -365,7 +369,6 @@ class Note extends Model
break;
case VisibilityScope::GROUP:
// Will have the group in the To coming from attentions
// no break
case VisibilityScope::COLLECTION:
// Since we don't support sending unlisted/followers-only
// notices, arriving here means we're instead answering to that type
@@ -379,7 +382,7 @@ class Note extends Model
}
$attention_cc = DB::findBy(Attention::class, ['note_id' => $object->getId()]);
foreach($attention_cc as $cc_id) {
foreach ($attention_cc as $cc_id) {
$target = \App\Entity\Actor::getById($cc_id->getTargetId());
if ($object->getScope() === VisibilityScope::GROUP && $target->isGroup()) {
$attr['to'][] = $target->getUri(Router::ABSOLUTE_URL);