From 53c46127c10359bb63003a9a949cbc5b0800460e Mon Sep 17 00:00:00 2001 From: Diogo Peralta Cordeiro Date: Thu, 2 Dec 2021 03:33:40 +0000 Subject: [PATCH] [ActivityPub][Explorer] Store remote's url properly --- .../ActivityPub/Entity/ActivitypubActor.php | 13 ++++++++++ plugins/ActivityPub/Util/Explorer.php | 24 +++++++++---------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/plugins/ActivityPub/Entity/ActivitypubActor.php b/plugins/ActivityPub/Entity/ActivitypubActor.php index 9f8f0f2de3..7010e14ab6 100644 --- a/plugins/ActivityPub/Entity/ActivitypubActor.php +++ b/plugins/ActivityPub/Entity/ActivitypubActor.php @@ -58,6 +58,7 @@ class ActivitypubActor extends Entity private int $actor_id; private string $inbox_uri; private ?string $inbox_shared_uri = null; + private string $url; private DateTimeInterface $created; private DateTimeInterface $modified; @@ -72,6 +73,17 @@ class ActivitypubActor extends Entity return $this; } + public function getUrl(): string + { + return $this->url; + } + + public function setUrl(string $url): self + { + $this->url = $url; + return $this; + } + public function getActorId(): int { return $this->actor_id; @@ -229,6 +241,7 @@ class ActivitypubActor extends Entity 'actor_id' => ['type' => 'int', 'not null' => true], 'inbox_uri' => ['type' => 'text', 'not null' => true], 'inbox_shared_uri' => ['type' => 'text'], + 'url' => ['type' => 'text'], 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'], 'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'], ], diff --git a/plugins/ActivityPub/Util/Explorer.php b/plugins/ActivityPub/Util/Explorer.php index 30288630e7..f0bae30f7f 100644 --- a/plugins/ActivityPub/Util/Explorer.php +++ b/plugins/ActivityPub/Util/Explorer.php @@ -238,7 +238,6 @@ class Explorer 'fullname' => $res['name'] ?? null, 'created' => new DateTime($res['published'] ?? 'now'), 'bio' => isset($res['summary']) ? mb_substr(Security::sanitize($res['summary']), 0, 1000) : null, - 'homepage' => $res['url'], 'is_local' => false, 'modified' => new DateTime(), ]; @@ -252,22 +251,21 @@ class Explorer DB::persist($actor); // ActivityPub Actor - $aprofile = new ActivitypubActor(); - $aprofile->setInboxUri($res['inbox']); - $aprofile->setInboxSharedUri($res['endpoints']['sharedInbox'] ?? $res['inbox']); - $aprofile->setUri($res['id']); - $aprofile->setActorId($actor->getId()); - $aprofile->setCreated(new DateTime()); - $aprofile->setModified(new DateTime()); + $aprofile = ActivitypubActor::create([ + 'inbox_uri' => $res['inbox'], + 'inbox_shared_uri' => $res['endpoints']['sharedInbox'], + 'uri' => $res['id'], + 'actor_id' => $actor->getId(), + 'url' => $res['url'] ?? null, + ]); DB::persist($aprofile); // Public Key - $apRSA = new ActivitypubRsa(); - $apRSA->setActorId($actor->getID()); - $apRSA->setPublicKey($res['publicKey']['publicKeyPem']); - $apRSA->setCreated(new DateTime()); - $apRSA->setModified(new DateTime()); + $apRSA = ActivitypubRsa::create([ + 'actor_id' => $actor->getID(), + 'public_key' => $res['publicKey']['publicKeyPem'], + ]); DB::persist($apRSA);