diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2019-01-21 15:10:41 -0100 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2019-01-24 10:50:03 -0100 |
commit | 2081e9b3a564dbca19e0d4151ba32e60978f52e3 (patch) | |
tree | 1c3e553ec651c72a8641af7d34e5330dc1dc94dc | |
parent | 393e73f7e295c737c8c880405a3c0f4984f92c4b (diff) |
Model and Interface: Announce
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
-rw-r--r-- | lib/AP.php | 46 | ||||
-rw-r--r-- | lib/Interfaces/Object/AnnounceInterface.php | 120 | ||||
-rw-r--r-- | lib/Model/ActivityPub/Object/Announce.php | 96 |
3 files changed, 257 insertions, 5 deletions
@@ -48,6 +48,7 @@ use OCA\Social\Interfaces\Activity\UndoInterface; use OCA\Social\Interfaces\Activity\UpdateInterface; use OCA\Social\Interfaces\Actor\PersonInterface; use OCA\Social\Interfaces\IActivityPubInterface; +use OCA\Social\Interfaces\Object\AnnounceInterface; use OCA\Social\Interfaces\Object\NoteInterface; use OCA\Social\Model\ActivityPub\ACore; use OCA\Social\Model\ActivityPub\Activity\Accept; @@ -62,6 +63,7 @@ use OCA\Social\Model\ActivityPub\Activity\Remove; use OCA\Social\Model\ActivityPub\Activity\Undo; use OCA\Social\Model\ActivityPub\Activity\Update; use OCA\Social\Model\ActivityPub\Actor\Person; +use OCA\Social\Model\ActivityPub\Object\Announce; use OCA\Social\Model\ActivityPub\Object\Document; use OCA\Social\Model\ActivityPub\Object\Image; use OCA\Social\Model\ActivityPub\Object\Note; @@ -90,6 +92,9 @@ class AP { /** @var AddInterface */ public $addInterface; + /** @var AnnounceInterface */ + public $announceInterface; + /** @var BlockInterface */ public $blockInterface; @@ -146,6 +151,7 @@ class AP { try { $ap->acceptInterface = \OC::$server->query(AcceptInterface::class); $ap->addInterface = \OC::$server->query(AddInterface::class); + $ap->announceInterface = \OC::$server->query(AnnounceInterface::class); $ap->blockInterface = \OC::$server->query(BlockInterface::class); $ap->createInterface = \OC::$server->query(CreateInterface::class); $ap->deleteInterface = \OC::$server->query(DeleteInterface::class); @@ -186,11 +192,7 @@ class AP { $item->setParent($parent); } - try { - $object = $this->getItemFromData($this->getArray('object', $data, []), $item, $level); - $item->setObject($object); - } catch (ItemUnknownException $e) { - } + $this->getObjectFromData($data, $item, $level); try { /** @var Document $icon */ @@ -205,6 +207,32 @@ class AP { /** * @param array $data + * @param ACore $item + * @param int $level + * + * @throws RedundancyLimitException + * @throws SocialAppConfigException + */ + public function getObjectFromData(array $data, ACore &$item, int $level) { + try { + $objectData = $this->getArray('object', $data, []); + if (empty($objectData)) { + $objectId = $this->get('object', $data, ''); + if ($objectId !== '') { + // TODO: validate AS_URL + $item->setObjectId($objectId); + } + } else { + $object = $this->getItemFromData($objectData, $item, $level); + $item->setObject($object); + } + } catch (ItemUnknownException $e) { + } + } + + + /** + * @param array $data * * @return ACore * @throws SocialAppConfigException @@ -236,6 +264,10 @@ class AP { $item = new Add(); break; + case Announce::TYPE: + $item = new Announce(); + break; + case Block::TYPE: $item = new Block(); break; @@ -325,6 +357,10 @@ class AP { $service = $this->addInterface; break; + case Announce::TYPE: + $service = $this->announceInterface; + break; + case Block::TYPE: $service = $this->blockInterface; break; diff --git a/lib/Interfaces/Object/AnnounceInterface.php b/lib/Interfaces/Object/AnnounceInterface.php new file mode 100644 index 00000000..abaf10e4 --- /dev/null +++ b/lib/Interfaces/Object/AnnounceInterface.php @@ -0,0 +1,120 @@ +<?php +declare(strict_types=1); + + +/** + * Nextcloud - Social Support + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Maxence Lange <maxence@artificial-owl.com> + * @copyright 2018, Maxence Lange <maxence@artificial-owl.com> + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + + +namespace OCA\Social\Interfaces\Object; + + +use OCA\Social\Exceptions\ItemNotFoundException; +use OCA\Social\Interfaces\IActivityPubInterface; +use OCA\Social\Model\ActivityPub\ACore; +use OCA\Social\Model\ActivityPub\Object\Announce; +use OCA\Social\Service\MiscService; + + +class AnnounceInterface implements IActivityPubInterface { + + + /** @var MiscService */ + private $miscService; + + + /** + * AnnounceInterface constructor. + * + * @param MiscService $miscService + */ + public function __construct(MiscService $miscService) { + $this->miscService = $miscService; + } + + + /** + * @param ACore $activity + * @param ACore $item + */ + public function activity(Acore $activity, ACore $item) { + } + + + /** + * @param ACore $item + */ + public function processIncomingRequest(ACore $item) { +// if (!$item->gotObject()) { +// return; +// } + $object = $item->getObjectId(); + $this->miscService->log('___' . json_encode($object)); +// +// try { +// $service = AP::$activityPub->getInterfaceForItem($item->getObject()); +// $service->activity($item, $object); +// } catch (ItemUnknownException $e) { +// } +// + } + + + /** + * @param ACore $item + */ + public function processResult(ACore $item) { + } + + + /** + * @param string $id + * + * @return ACore + * @throws ItemNotFoundException + */ + public function getItemById(string $id): ACore { + throw new ItemNotFoundException(); + } + + /** + * @param ACore $item + */ + public function save(ACore $item) { + /** @var Announce $item */ +// $this->cacheDocumentsRequest->save($item); + } + + + /** + * @param ACore $item + */ + public function delete(ACore $item) { +// $this->cacheDocumentsRequest->delete($item); + } + + +} + diff --git a/lib/Model/ActivityPub/Object/Announce.php b/lib/Model/ActivityPub/Object/Announce.php new file mode 100644 index 00000000..ede50958 --- /dev/null +++ b/lib/Model/ActivityPub/Object/Announce.php @@ -0,0 +1,96 @@ +<?php +declare(strict_types=1); + + +/** + * Nextcloud - Social Support + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Maxence Lange <maxence@artificial-owl.com> + * @copyright 2018, Maxence Lange <maxence@artificial-owl.com> + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + + +namespace OCA\Social\Model\ActivityPub\Object; + + +use JsonSerializable; +use OCA\Social\Model\ActivityPub\ACore; + + +/** + * Class Follow + * + * @package OCA\Social\Model\ActivityPub\Object + */ +class Announce extends ACore implements JsonSerializable { + + + const TYPE = 'Announce'; + + + + + /** + * Follow constructor. + * + * @param ACore $parent + */ + public function __construct($parent = null) { + parent::__construct($parent); + + $this->setType(self::TYPE); + } + + + /** + * @param array $data + */ + public function import(array $data) { + parent::import($data); + } + + + /** + * @param array $data + */ + public function importFromDatabase(array $data) { + parent::importFromDatabase($data); + } + + + /** + * @return array + */ + public function jsonSerialize(): array { + $result = parent::jsonSerialize(); + + if ($this->isCompleteDetails()) { + array_merge( + $result, + [] + ); + } + + return $result; + } + +} + |