From 9ae0c19dfaad53dda55a5252672ce1ecda08e126 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 15 Mar 2023 19:06:31 -0100 Subject: [PATCH] add icon to actor Signed-off-by: Maxence Lange --- lib/Db/CacheActorsRequestBuilder.php | 4 +- lib/Db/SocialCrossQueryBuilder.php | 2 - lib/Model/ActivityPub/Actor/Person.php | 55 +++++++++++++++++--------- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/lib/Db/CacheActorsRequestBuilder.php b/lib/Db/CacheActorsRequestBuilder.php index 04df7947..59779306 100644 --- a/lib/Db/CacheActorsRequestBuilder.php +++ b/lib/Db/CacheActorsRequestBuilder.php @@ -58,9 +58,9 @@ class CacheActorsRequestBuilder extends CoreRequestBuilder { /** * Base of the Sql Update request * - * @return IQueryBuilder + * @return SocialQueryBuilder */ - protected function getCacheActorsUpdateSql(): IQueryBuilder { + protected function getCacheActorsUpdateSql(): SocialQueryBuilder { $qb = $this->getQueryBuilder(); $qb->update(self::TABLE_CACHE_ACTORS); diff --git a/lib/Db/SocialCrossQueryBuilder.php b/lib/Db/SocialCrossQueryBuilder.php index 39487768..884cbbbd 100644 --- a/lib/Db/SocialCrossQueryBuilder.php +++ b/lib/Db/SocialCrossQueryBuilder.php @@ -170,8 +170,6 @@ class SocialCrossQueryBuilder extends SocialCoreQueryBuilder { } $expr = $this->expr(); - $func = $this->func(); - $pf = (($alias === '') ? $this->getDefaultSelectAlias() : $alias); $this->selectAlias('cd.id', 'cachedocument_id') ->selectAlias('cd.type', 'cachedocument_type') diff --git a/lib/Model/ActivityPub/Actor/Person.php b/lib/Model/ActivityPub/Actor/Person.php index 158aa692..3f8f74ad 100644 --- a/lib/Model/ActivityPub/Actor/Person.php +++ b/lib/Model/ActivityPub/Actor/Person.php @@ -697,6 +697,12 @@ class Person extends ACore implements IQueryRow, JsonSerializable { ->setFeatured($this->validate(self::AS_URL, 'featured', $data, '')) ->setDetailsAll($this->getArray('details', $data, [])); + if ($this->hasIcon()) { + $this->setAvatar($this->getIcon()->getUrl()); + } else { + $this->setAvatar($this->getAvatar()); + } + try { $cTime = new DateTime($this->get('creation', $data, 'yesterday')); $this->setCreation($cTime->getTimestamp()); @@ -722,27 +728,38 @@ class Person extends ACore implements IQueryRow, JsonSerializable { * @return array */ public function exportAsActivityPub(): array { + $data = [ + 'aliases' => [ + $this->getUrlSocial() . '@' . $this->getPreferredUsername(), + $this->getUrlSocial() . 'users/' . $this->getPreferredUsername() + ], + 'preferredUsername' => $this->getPreferredUsername(), + 'name' => $this->getName(), + 'inbox' => $this->getInbox(), + 'outbox' => $this->getOutbox(), + 'account' => $this->getAccount(), + 'following' => $this->getFollowing(), + 'followers' => $this->getFollowers(), + 'endpoints' => ['sharedInbox' => $this->getSharedInbox()], + 'publicKey' => [ + 'id' => $this->getId() . '#main-key', + 'owner' => $this->getId(), + 'publicKeyPem' => $this->getPublicKey() + ] + ]; + + if ($this->hasIcon()) { + $icon = $this->getIcon(); + $data['icon'] = [ + 'type' => $icon->getType(), + 'mediaType' => $icon->getMediaType(), + 'url' => $icon->getUrl() + ]; + } + $result = array_merge( parent::exportAsActivityPub(), - [ - 'aliases' => [ - $this->getUrlSocial() . '@' . $this->getPreferredUsername(), - $this->getUrlSocial() . 'users/' . $this->getPreferredUsername() - ], - 'preferredUsername' => $this->getPreferredUsername(), - 'name' => $this->getName(), - 'inbox' => $this->getInbox(), - 'outbox' => $this->getOutbox(), - 'account' => $this->getAccount(), - 'following' => $this->getFollowing(), - 'followers' => $this->getFollowers(), - 'endpoints' => ['sharedInbox' => $this->getSharedInbox()], - 'publicKey' => [ - 'id' => $this->getId() . '#main-key', - 'owner' => $this->getId(), - 'publicKeyPem' => $this->getPublicKey() - ] - ] + $data ); if ($this->isCompleteDetails()) {