diff --git a/plugins/ActivityPub/ActivityPubPlugin.php b/plugins/ActivityPub/ActivityPubPlugin.php index 610f1e755c..75167eeae1 100644 --- a/plugins/ActivityPub/ActivityPubPlugin.php +++ b/plugins/ActivityPub/ActivityPubPlugin.php @@ -97,8 +97,8 @@ class ActivityPubPlugin extends Plugin // Look for a local notice (unfortunately GNU social doesn't // provide this functionality natively) try { - $candidate = Notice::getByID((int)substr($url, (strlen(common_local_url('apNotice', ['id' => 0]))-1))); - if (common_local_url('apNotice', ['id' => $candidate->getID()]) === $url) { // Sanity check + $candidate = Notice::getByID((int)substr($url, (strlen(Activitypub_notice::note_uri(0))-1))); + if (Activitypub_notice::note_uri($candidate->getID()) === $url) { // Sanity check return $candidate; } else { common_debug('ActivityPubPlugin Notice Grabber: '.$candidate->getUrl(). ' is different of '.$url); @@ -196,6 +196,12 @@ class ActivityPubPlugin extends Plugin $acceptHeaders ); + $m->connect( + 'object/note/:id', + ['action' => 'apNotice'], + ['id' => '[0-9]+'], + ); + $m->connect( 'user/:id/liked.json', ['action' => 'apActorLiked'], diff --git a/plugins/ActivityPub/actions/apactoroutbox.php b/plugins/ActivityPub/actions/apactoroutbox.php index 3762e80a72..b80ec568fe 100644 --- a/plugins/ActivityPub/actions/apactoroutbox.php +++ b/plugins/ActivityPub/actions/apactoroutbox.php @@ -124,6 +124,7 @@ class apActorOutboxAction extends ManagedAction if ($note->object_type == 'http://activitystrea.ms/schema/1.0/note') { $notices[] = Activitypub_create::create_to_array( $note->getProfile()->getUri(), + common_local_url('apNotice', ['id' => $note->getID()]), Activitypub_notice::notice_to_array($note) ); } diff --git a/plugins/ActivityPub/lib/models/Activitypub_create.php b/plugins/ActivityPub/lib/models/Activitypub_create.php index 0a6c0e50a6..569569ffee 100644 --- a/plugins/ActivityPub/lib/models/Activitypub_create.php +++ b/plugins/ActivityPub/lib/models/Activitypub_create.php @@ -40,16 +40,17 @@ class Activitypub_create * Generates an ActivityPub representation of a Create * * @param string $actor - * @param array $object + * @param string $uri + * @param mixed $object * @param bool $directMessage whether it is a private Create activity or not * @return array pretty array to be used in a response * @author Diogo Cordeiro */ - public static function create_to_array(string $actor, array $object, bool $directMessage = false): array + public static function create_to_array(string $actor, string $uri, $object, bool $directMessage = false): array { $res = [ '@context' => 'https://www.w3.org/ns/activitystreams', - 'id' => $object['id'] . '#create', + 'id' => $uri, 'type' => 'Create', 'directMessage' => $directMessage, 'to' => $object['to'], diff --git a/plugins/ActivityPub/lib/models/Activitypub_notice.php b/plugins/ActivityPub/lib/models/Activitypub_notice.php index 486a3b182f..8a1165cc36 100644 --- a/plugins/ActivityPub/lib/models/Activitypub_notice.php +++ b/plugins/ActivityPub/lib/models/Activitypub_notice.php @@ -100,7 +100,7 @@ class Activitypub_notice } else { // Note $item = [ '@context' => 'https://www.w3.org/ns/activitystreams', - 'id' => self::getUri($notice), + 'id' => self::note_uri($notice->getID()), 'type' => 'Note', 'published' => str_replace(' ', 'T', $notice->getCreated()) . 'Z', 'url' => $notice->getUrl(), @@ -310,6 +310,7 @@ class Activitypub_notice * @throws InvalidUrlException * @throws Exception * @author Bruno Casteleiro + * @see note_uri when it's not a generic activity but a object type note */ public static function getUri(Notice $notice): string { @@ -320,6 +321,19 @@ class Activitypub_notice } } + /** + * Use this if your Notice is in fact a note + * + * @param int $id + * @return string it's uri + * @author Diogo Cordeiro + * @see getUri for every other activity that aren't objects of a certain type like note + */ + public static function note_uri(int $id): string + { + return common_root_url() . 'object/note/' . $id; + } + /** * Extract note policy type from note targets. * diff --git a/plugins/ActivityPub/lib/models/Activitypub_tombstone.php b/plugins/ActivityPub/lib/models/Activitypub_tombstone.php index aa2be34bb0..fed2eeb85f 100644 --- a/plugins/ActivityPub/lib/models/Activitypub_tombstone.php +++ b/plugins/ActivityPub/lib/models/Activitypub_tombstone.php @@ -48,11 +48,11 @@ class Activitypub_tombstone $dead = Deleted_notice::getByID($id); $res = [ '@context' => 'https://www.w3.org/ns/activitystreams', - 'id' => Activitypub_notice::getUri($id), + 'id' => Activitypub_notice::note_uri($id), 'type' => 'Tombstone', 'created' => str_replace(' ', 'T', $dead->act_created) . 'Z', 'deleted' => str_replace(' ', 'T', $dead->created) . 'Z' ]; return $res; } -} \ No newline at end of file +} diff --git a/plugins/ActivityPub/lib/postman.php b/plugins/ActivityPub/lib/postman.php index 8818c6c23b..5d7cdeeeeb 100644 --- a/plugins/ActivityPub/lib/postman.php +++ b/plugins/ActivityPub/lib/postman.php @@ -290,6 +290,7 @@ class Activitypub_postman { $data = Activitypub_create::create_to_array( $this->actor_uri, + common_local_url('apNotice', ['id' => $notice->getID()]), Activitypub_notice::notice_to_array($notice) ); $data = json_encode($data, JSON_UNESCAPED_SLASHES); @@ -321,6 +322,7 @@ class Activitypub_postman { $data = Activitypub_create::create_to_array( $this->actor_uri, + common_local_url('apNotice', ['id' => $message->getID()]), Activitypub_message::message_to_array($message), true );