From d0459734496fcd8c0d922d1d17aced3429eb68c8 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 21 Oct 2020 17:54:19 +0200 Subject: [PATCH] add reblog content to mastadon api Signed-off-by: Robin Appelman --- lib/Model/ActivityPub/ACore.php | 6 +++++ lib/Model/ActivityPub/Object/Announce.php | 30 +++++++++++------------ lib/Model/ActivityPub/Stream.php | 12 ++++++++- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/lib/Model/ActivityPub/ACore.php b/lib/Model/ActivityPub/ACore.php index 135de478..2e00e0dc 100644 --- a/lib/Model/ActivityPub/ACore.php +++ b/lib/Model/ActivityPub/ACore.php @@ -657,6 +657,12 @@ class ACore extends Item implements JsonSerializable { $this->setLocal(($this->getInt('local', $data, 0) === 1)); } + /** + * @param array $data + */ + public function importFromCache(array $data) { + $this->import($data); + } /** * @param int $format diff --git a/lib/Model/ActivityPub/Object/Announce.php b/lib/Model/ActivityPub/Object/Announce.php index a13e5b6a..0d4eab15 100644 --- a/lib/Model/ActivityPub/Object/Announce.php +++ b/lib/Model/ActivityPub/Object/Announce.php @@ -33,6 +33,7 @@ namespace OCA\Social\Model\ActivityPub\Object; use Exception; use JsonSerializable; +use OCA\Social\AP; use OCA\Social\Model\ActivityPub\ACore; use OCA\Social\Model\ActivityPub\Stream; @@ -72,26 +73,25 @@ class Announce extends Stream implements JsonSerializable { $this->setAttributedTo($this->getActorId()); } - - /** - * @param array $data - * - * @throws Exception - */ - public function importFromDatabase(array $data) { - parent::importFromDatabase($data); - } - - /** * @return array */ - public function jsonSerialize(): array { - $result = parent::jsonSerialize(); - //$result['actor'] = $this->getAttributedTo(); + public function exportAsLocal(): array { + $result = parent::exportAsLocal(); + + if ($this->hasCache()) { + $cache = $this->getCache(); + if ($object = $cache->getItem($this->getObjectId())) { + $object = $object->getObject(); + /** @var Stream $item */ + $item = AP::$activityPub->getItemFromType($this->get('type', $object, Stream::TYPE)); + $item->importFromCache($object); + $result['reblog'] = $item->exportAsLocal(); + $result['content'] = $item->getContent(); + } + } return $result; } - } diff --git a/lib/Model/ActivityPub/Stream.php b/lib/Model/ActivityPub/Stream.php index 7a33dce6..68b187a7 100644 --- a/lib/Model/ActivityPub/Stream.php +++ b/lib/Model/ActivityPub/Stream.php @@ -36,6 +36,7 @@ use daita\MySmallPhpTools\Model\CacheItem; use DateTime; use Exception; use JsonSerializable; +use OCA\Social\Model\ActivityPub\Actor\Person; use OCA\Social\Model\StreamAction; use OCA\Social\Traits\TDetails; @@ -436,6 +437,15 @@ class Stream extends ACore implements IQueryRow, JsonSerializable { $this->setCache($cache); } + public function importFromCache(array $data) { + parent::importFromCache($data); + + $actor = new Person(); + $actor->importFromCache($data['actor_info']); + $this->setActor($actor); + $this->setCompleteDetails(true); + } + /** * @return array @@ -520,7 +530,7 @@ class Stream extends ACore implements IQueryRow, JsonSerializable { // TODO - store created_at full string with milliseconds ? if ($this->hasActor()) { $actor = $this->getActor(); - $result['account'] = $actor; + $result['account'] = $actor->exportAsLocal(); } return array_merge(parent::exportAsLocal(), $result);