From 7f2eede76bf40ba2c60deb10b9356ca9e8864889 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Thu, 13 Dec 2018 08:40:27 -0100 Subject: [PATCH] moving stuff around Signed-off-by: Maxence Lange --- lib/Command/CacheRefresh.php | 4 +- lib/Command/NoteCreate.php | 2 +- lib/Controller/ActivityPubController.php | 5 +- lib/Controller/LocalController.php | 10 +- lib/Controller/NavigationController.php | 6 +- lib/Controller/SocialPubController.php | 4 +- lib/Cron/Cache.php | 4 +- lib/Db/ActorsRequest.php | 2 +- lib/Db/ActorsRequestBuilder.php | 2 +- lib/Db/CacheActorsRequest.php | 2 +- lib/Db/CacheActorsRequestBuilder.php | 2 +- lib/Db/CacheDocumentsRequest.php | 2 +- lib/Db/CacheDocumentsRequestBuilder.php | 3 +- lib/Db/CoreRequestBuilder.php | 8 +- lib/Db/FollowsRequest.php | 3 +- lib/Db/FollowsRequestBuilder.php | 2 +- lib/Db/NotesRequest.php | 4 +- lib/Db/NotesRequestBuilder.php | 4 +- lib/Model/ActivityPub/ACore.php | 27 +- lib/Model/ActivityPub/Activity/Add.php | 81 ++++++ lib/Model/ActivityPub/Activity/Block.php | 81 ++++++ lib/Model/ActivityPub/Activity/Create.php | 3 +- .../ActivityPub/{ => Activity}/Follow.php | 6 +- .../ActivityPub/Activity/Like.php} | 48 ++-- lib/Model/ActivityPub/Activity/Remove.php | 81 ++++++ lib/Model/ActivityPub/Activity/Update.php | 81 ++++++ lib/Model/ActivityPub/{ => Actor}/Person.php | 4 +- lib/Model/ActivityPub/Item.php | 1 + .../ActivityPub/{ => Object}/Document.php | 3 +- lib/Model/ActivityPub/{ => Object}/Image.php | 3 +- lib/Model/ActivityPub/{ => Object}/Note.php | 3 +- .../ActivityPub/{ => Object}/Tombstone.php | 3 +- .../ActivityPub/Activity/AcceptService.php | 105 ++++++++ .../ActivityPub/Activity/AddService.php | 106 ++++++++ .../ActivityPub/Activity/BlockService.php | 106 ++++++++ .../ActivityPub/Activity/CreateService.php | 104 ++++++++ .../{ => Activity}/DeleteService.php | 68 +++-- .../{ => Activity}/FollowService.php | 104 +++++--- .../ActivityPub/Activity/LikeService.php | 104 ++++++++ .../ActivityPub/Activity/RejectService.php | 105 ++++++++ .../ActivityPub/Activity/RemoveService.php | 106 ++++++++ .../ActivityPub/Activity/UndoService.php | 108 ++++++++ .../ActivityPub/Activity/UpdateService.php | 104 ++++++++ .../ActivityPub/{ => Actor}/PersonService.php | 40 ++- lib/Service/ActivityPub/ICoreService.php | 28 ++- .../{ => Object}/DocumentService.php | 29 ++- .../ActivityPub/{ => Object}/NoteService.php | 52 ++-- lib/Service/ActivityService.php | 10 +- lib/Service/ActorService.php | 6 +- lib/Service/ConfigService.php | 2 - lib/Service/ImportService.php | 234 ++++++++++++++---- lib/Service/PostService.php | 2 +- 52 files changed, 1753 insertions(+), 264 deletions(-) create mode 100644 lib/Model/ActivityPub/Activity/Add.php create mode 100644 lib/Model/ActivityPub/Activity/Block.php rename lib/Model/ActivityPub/{ => Activity}/Follow.php (94%) rename lib/{Service/ActivityPub/UndoService.php => Model/ActivityPub/Activity/Like.php} (65%) create mode 100644 lib/Model/ActivityPub/Activity/Remove.php create mode 100644 lib/Model/ActivityPub/Activity/Update.php rename lib/Model/ActivityPub/{ => Actor}/Person.php (98%) rename lib/Model/ActivityPub/{ => Object}/Document.php (98%) rename lib/Model/ActivityPub/{ => Object}/Image.php (95%) rename lib/Model/ActivityPub/{ => Object}/Note.php (98%) rename lib/Model/ActivityPub/{ => Object}/Tombstone.php (94%) create mode 100644 lib/Service/ActivityPub/Activity/AcceptService.php create mode 100644 lib/Service/ActivityPub/Activity/AddService.php create mode 100644 lib/Service/ActivityPub/Activity/BlockService.php create mode 100644 lib/Service/ActivityPub/Activity/CreateService.php rename lib/Service/ActivityPub/{ => Activity}/DeleteService.php (70%) rename lib/Service/ActivityPub/{ => Activity}/FollowService.php (76%) create mode 100644 lib/Service/ActivityPub/Activity/LikeService.php create mode 100644 lib/Service/ActivityPub/Activity/RejectService.php create mode 100644 lib/Service/ActivityPub/Activity/RemoveService.php create mode 100644 lib/Service/ActivityPub/Activity/UndoService.php create mode 100644 lib/Service/ActivityPub/Activity/UpdateService.php rename lib/Service/ActivityPub/{ => Actor}/PersonService.php (90%) rename lib/Service/ActivityPub/{ => Object}/DocumentService.php (90%) rename lib/Service/ActivityPub/{ => Object}/NoteService.php (91%) diff --git a/lib/Command/CacheRefresh.php b/lib/Command/CacheRefresh.php index 26a688fe..4990c918 100644 --- a/lib/Command/CacheRefresh.php +++ b/lib/Command/CacheRefresh.php @@ -33,8 +33,8 @@ namespace OCA\Social\Command; use Exception; use OC\Core\Command\Base; -use OCA\Social\Service\ActivityPub\DocumentService; -use OCA\Social\Service\ActivityPub\PersonService; +use OCA\Social\Service\ActivityPub\Object\DocumentService; +use OCA\Social\Service\ActivityPub\Actor\PersonService; use OCA\Social\Service\ActorService; use OCA\Social\Service\ConfigService; use OCA\Social\Service\MiscService; diff --git a/lib/Command/NoteCreate.php b/lib/Command/NoteCreate.php index 307fa4af..1b7da816 100644 --- a/lib/Command/NoteCreate.php +++ b/lib/Command/NoteCreate.php @@ -33,7 +33,7 @@ namespace OCA\Social\Command; use Exception; use OC\Core\Command\Base; use OCA\Social\Model\Post; -use OCA\Social\Service\ActivityPub\NoteService; +use OCA\Social\Service\ActivityPub\Object\NoteService; use OCA\Social\Service\ActivityService; use OCA\Social\Service\ActorService; use OCA\Social\Service\ConfigService; diff --git a/lib/Controller/ActivityPubController.php b/lib/Controller/ActivityPubController.php index b686bf65..0d9f9668 100644 --- a/lib/Controller/ActivityPubController.php +++ b/lib/Controller/ActivityPubController.php @@ -37,14 +37,13 @@ use OCA\Social\AppInfo\Application; use OCA\Social\Db\NotesRequest; use OCA\Social\Exceptions\SignatureIsGoneException; use OCA\Social\Exceptions\UnknownItemException; -use OCA\Social\Service\ActivityPub\FollowService; -use OCA\Social\Service\ActivityPub\PersonService; +use OCA\Social\Service\ActivityPub\Activity\FollowService; +use OCA\Social\Service\ActivityPub\Actor\PersonService; use OCA\Social\Service\ActivityService; use OCA\Social\Service\ActorService; use OCA\Social\Service\ImportService; use OCA\Social\Service\MiscService; use OCP\AppFramework\Controller; -use OCP\AppFramework\Http\NotFoundResponse; use OCP\AppFramework\Http\Response; use OCP\IRequest; diff --git a/lib/Controller/LocalController.php b/lib/Controller/LocalController.php index a99782d9..1fa26009 100644 --- a/lib/Controller/LocalController.php +++ b/lib/Controller/LocalController.php @@ -37,12 +37,12 @@ use OCA\Social\AppInfo\Application; use OCA\Social\Exceptions\AccountDoesNotExistException; use OCA\Social\Exceptions\InvalidResourceException; use OCA\Social\Model\ActivityPub\ACore; -use OCA\Social\Model\ActivityPub\Person; +use OCA\Social\Model\ActivityPub\Actor\Person; use OCA\Social\Model\Post; -use OCA\Social\Service\ActivityPub\DocumentService; -use OCA\Social\Service\ActivityPub\FollowService; -use OCA\Social\Service\ActivityPub\NoteService; -use OCA\Social\Service\ActivityPub\PersonService; +use OCA\Social\Service\ActivityPub\Object\DocumentService; +use OCA\Social\Service\ActivityPub\Activity\FollowService; +use OCA\Social\Service\ActivityPub\Object\NoteService; +use OCA\Social\Service\ActivityPub\Actor\PersonService; use OCA\Social\Service\ActorService; use OCA\Social\Service\MiscService; use OCA\Social\Service\PostService; diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php index cbe5a1f1..f3e64c36 100644 --- a/lib/Controller/NavigationController.php +++ b/lib/Controller/NavigationController.php @@ -37,8 +37,8 @@ use OC\User\NoUserException; use OCA\Social\AppInfo\Application; use OCA\Social\Exceptions\AccountAlreadyExistsException; use OCA\Social\Exceptions\SocialAppConfigException; -use OCA\Social\Service\ActivityPub\DocumentService; -use OCA\Social\Service\ActivityPub\PersonService; +use OCA\Social\Service\ActivityPub\Object\DocumentService; +use OCA\Social\Service\ActivityPub\Actor\PersonService; use OCA\Social\Service\ActorService; use OCA\Social\Service\CheckService; use OCA\Social\Service\ConfigService; @@ -227,7 +227,7 @@ class NavigationController extends Controller { $setup = false; try { - $address = $this->configService->getCloudAddress(true); + $this->configService->getCloudAddress(true); $setup = true; } catch (SocialAppConfigException $e) { } diff --git a/lib/Controller/SocialPubController.php b/lib/Controller/SocialPubController.php index efd35049..5654b32d 100644 --- a/lib/Controller/SocialPubController.php +++ b/lib/Controller/SocialPubController.php @@ -34,8 +34,8 @@ use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse; use Exception; use OCA\Social\AppInfo\Application; use OCA\Social\Exceptions\CacheActorDoesNotExistException; -use OCA\Social\Model\ActivityPub\Person; -use OCA\Social\Service\ActivityPub\PersonService; +use OCA\Social\Model\ActivityPub\Actor\Person; +use OCA\Social\Service\ActivityPub\Actor\PersonService; use OCA\Social\Service\ActorService; use OCA\Social\Service\MiscService; use OCP\AppFramework\Controller; diff --git a/lib/Cron/Cache.php b/lib/Cron/Cache.php index df9b741a..087cef31 100644 --- a/lib/Cron/Cache.php +++ b/lib/Cron/Cache.php @@ -34,8 +34,8 @@ namespace OCA\Social\Cron; use Exception; use OC\BackgroundJob\TimedJob; use OCA\Social\AppInfo\Application; -use OCA\Social\Service\ActivityPub\DocumentService; -use OCA\Social\Service\ActivityPub\PersonService; +use OCA\Social\Service\ActivityPub\Object\DocumentService; +use OCA\Social\Service\ActivityPub\Actor\PersonService; use OCA\Social\Service\ActorService; use OCA\Social\Service\ConfigService; use OCA\Social\Service\MiscService; diff --git a/lib/Db/ActorsRequest.php b/lib/Db/ActorsRequest.php index a8ad8a28..be241ab4 100644 --- a/lib/Db/ActorsRequest.php +++ b/lib/Db/ActorsRequest.php @@ -32,7 +32,7 @@ namespace OCA\Social\Db; use OCA\Social\Exceptions\ActorDoesNotExistException; use OCA\Social\Exceptions\SocialAppConfigException; -use OCA\Social\Model\ActivityPub\Person; +use OCA\Social\Model\ActivityPub\Actor\Person; use OCA\Social\Service\ConfigService; use OCA\Social\Service\MiscService; use OCP\IDBConnection; diff --git a/lib/Db/ActorsRequestBuilder.php b/lib/Db/ActorsRequestBuilder.php index 0312dea3..5263c6e3 100644 --- a/lib/Db/ActorsRequestBuilder.php +++ b/lib/Db/ActorsRequestBuilder.php @@ -32,7 +32,7 @@ namespace OCA\Social\Db; use daita\MySmallPhpTools\Traits\TArrayTools; use OCA\Social\Exceptions\SocialAppConfigException; -use OCA\Social\Model\ActivityPub\Person; +use OCA\Social\Model\ActivityPub\Actor\Person; use OCP\DB\QueryBuilder\IQueryBuilder; class ActorsRequestBuilder extends CoreRequestBuilder { diff --git a/lib/Db/CacheActorsRequest.php b/lib/Db/CacheActorsRequest.php index e69afbc1..6298c12b 100644 --- a/lib/Db/CacheActorsRequest.php +++ b/lib/Db/CacheActorsRequest.php @@ -33,7 +33,7 @@ namespace OCA\Social\Db; use DateTime; use Exception; use OCA\Social\Exceptions\CacheActorDoesNotExistException; -use OCA\Social\Model\ActivityPub\Person; +use OCA\Social\Model\ActivityPub\Actor\Person; use OCA\Social\Service\ConfigService; use OCA\Social\Service\MiscService; use OCP\DB\QueryBuilder\IQueryBuilder; diff --git a/lib/Db/CacheActorsRequestBuilder.php b/lib/Db/CacheActorsRequestBuilder.php index 4833d0e9..fe0e5313 100644 --- a/lib/Db/CacheActorsRequestBuilder.php +++ b/lib/Db/CacheActorsRequestBuilder.php @@ -32,7 +32,7 @@ namespace OCA\Social\Db; use daita\MySmallPhpTools\Traits\TArrayTools; use OCA\Social\Exceptions\InvalidResourceException; -use OCA\Social\Model\ActivityPub\Person; +use OCA\Social\Model\ActivityPub\Actor\Person; use OCP\DB\QueryBuilder\IQueryBuilder; class CacheActorsRequestBuilder extends CoreRequestBuilder { diff --git a/lib/Db/CacheDocumentsRequest.php b/lib/Db/CacheDocumentsRequest.php index 3b5d917a..43b9ad3e 100644 --- a/lib/Db/CacheDocumentsRequest.php +++ b/lib/Db/CacheDocumentsRequest.php @@ -33,7 +33,7 @@ namespace OCA\Social\Db; use DateTime; use Exception; use OCA\Social\Exceptions\CacheDocumentDoesNotExistException; -use OCA\Social\Model\ActivityPub\Document; +use OCA\Social\Model\ActivityPub\Object\Document; use OCP\DB\QueryBuilder\IQueryBuilder; class CacheDocumentsRequest extends CacheDocumentsRequestBuilder { diff --git a/lib/Db/CacheDocumentsRequestBuilder.php b/lib/Db/CacheDocumentsRequestBuilder.php index 4271fe6d..300f5066 100644 --- a/lib/Db/CacheDocumentsRequestBuilder.php +++ b/lib/Db/CacheDocumentsRequestBuilder.php @@ -31,8 +31,7 @@ namespace OCA\Social\Db; use daita\MySmallPhpTools\Traits\TArrayTools; -use OCA\Social\Model\ActivityPub\Document; -use OCA\Social\Model\ActivityPub\Image; +use OCA\Social\Model\ActivityPub\Object\Document; use OCP\DB\QueryBuilder\IQueryBuilder; class CacheDocumentsRequestBuilder extends CoreRequestBuilder { diff --git a/lib/Db/CoreRequestBuilder.php b/lib/Db/CoreRequestBuilder.php index 8f594ddd..1e96b620 100644 --- a/lib/Db/CoreRequestBuilder.php +++ b/lib/Db/CoreRequestBuilder.php @@ -36,10 +36,10 @@ use DateTime; use Doctrine\DBAL\Query\QueryBuilder; use Exception; use OCA\Social\Exceptions\InvalidResourceException; -use OCA\Social\Model\ActivityPub\Document; -use OCA\Social\Model\ActivityPub\Follow; -use OCA\Social\Model\ActivityPub\Image; -use OCA\Social\Model\ActivityPub\Person; +use OCA\Social\Model\ActivityPub\Object\Document; +use OCA\Social\Model\ActivityPub\Activity\Follow; +use OCA\Social\Model\ActivityPub\Object\Image; +use OCA\Social\Model\ActivityPub\Actor\Person; use OCA\Social\Service\ConfigService; use OCA\Social\Service\MiscService; use OCP\DB\QueryBuilder\IQueryBuilder; diff --git a/lib/Db/FollowsRequest.php b/lib/Db/FollowsRequest.php index fac47cdb..eb8789ed 100644 --- a/lib/Db/FollowsRequest.php +++ b/lib/Db/FollowsRequest.php @@ -34,8 +34,7 @@ namespace OCA\Social\Db; use daita\MySmallPhpTools\Traits\TArrayTools; use DateTime; use OCA\Social\Exceptions\FollowDoesNotExistException; -use OCA\Social\Exceptions\InvalidResourceException; -use OCA\Social\Model\ActivityPub\Follow; +use OCA\Social\Model\ActivityPub\Activity\Follow; use OCP\DB\QueryBuilder\IQueryBuilder; diff --git a/lib/Db/FollowsRequestBuilder.php b/lib/Db/FollowsRequestBuilder.php index 01e08442..6fb323a6 100644 --- a/lib/Db/FollowsRequestBuilder.php +++ b/lib/Db/FollowsRequestBuilder.php @@ -33,7 +33,7 @@ namespace OCA\Social\Db; use daita\MySmallPhpTools\Traits\TArrayTools; use OCA\Social\Exceptions\InvalidResourceException; -use OCA\Social\Model\ActivityPub\Follow; +use OCA\Social\Model\ActivityPub\Activity\Follow; use OCP\DB\QueryBuilder\IQueryBuilder; diff --git a/lib/Db/NotesRequest.php b/lib/Db/NotesRequest.php index fdd1313b..fa2f77b2 100644 --- a/lib/Db/NotesRequest.php +++ b/lib/Db/NotesRequest.php @@ -32,8 +32,8 @@ namespace OCA\Social\Db; use DateTime; use OCA\Social\Exceptions\NoteNotFoundException; -use OCA\Social\Model\ActivityPub\Note; -use OCA\Social\Model\ActivityPub\Person; +use OCA\Social\Model\ActivityPub\Object\Note; +use OCA\Social\Model\ActivityPub\Actor\Person; use OCA\Social\Service\ActivityService; use OCA\Social\Service\ConfigService; use OCA\Social\Service\MiscService; diff --git a/lib/Db/NotesRequestBuilder.php b/lib/Db/NotesRequestBuilder.php index 872004fa..4adaf37a 100644 --- a/lib/Db/NotesRequestBuilder.php +++ b/lib/Db/NotesRequestBuilder.php @@ -34,8 +34,8 @@ use daita\MySmallPhpTools\Traits\TArrayTools; use DateTime; use Doctrine\DBAL\Query\QueryBuilder; use OCA\Social\Exceptions\InvalidResourceException; -use OCA\Social\Model\ActivityPub\Note; -use OCA\Social\Model\ActivityPub\Person; +use OCA\Social\Model\ActivityPub\Object\Note; +use OCA\Social\Model\ActivityPub\Actor\Person; use OCA\Social\Model\InstancePath; use OCP\DB\QueryBuilder\ICompositeExpression; use OCP\DB\QueryBuilder\IQueryBuilder; diff --git a/lib/Model/ActivityPub/ACore.php b/lib/Model/ActivityPub/ACore.php index 3e76e2fc..c0b8ccf3 100644 --- a/lib/Model/ActivityPub/ACore.php +++ b/lib/Model/ActivityPub/ACore.php @@ -37,6 +37,7 @@ use OCA\Social\Exceptions\ActivityCantBeVerifiedException; use OCA\Social\Exceptions\InvalidOriginException; use OCA\Social\Exceptions\InvalidResourceEntryException; use OCA\Social\Exceptions\UrlCloudException; +use OCA\Social\Model\ActivityPub\Object\Document; use OCA\Social\Service\ActivityPub\ICoreService; @@ -87,18 +88,18 @@ abstract class ACore extends Item implements JsonSerializable { /** - * @param Item $parent + * @param ACore $parent * - * @return Item + * @return ACore */ - public function setParent(Item $parent): ACore { + public function setParent(ACore $parent): ACore { $this->parent = $parent; return $this; } /** - * @return Item + * @return ACore */ public function getParent(): ACore { return $this->parent; @@ -384,13 +385,13 @@ abstract class ACore extends Item implements JsonSerializable { * @param string $default * * @return string - * @throws InvalidResourceEntryException */ public function validate(int $as, string $k, array $arr, string $default = ''): string { - $value = $this->validateEntryString($as, $this->get($k, $arr, $default)); - - - return $value; + try { + return $this->validateEntryString($as, $this->get($k, $arr, $default)); + } catch (InvalidResourceEntryException $e) { + return $default; + } } @@ -401,14 +402,16 @@ abstract class ACore extends Item implements JsonSerializable { * @param array $default * * @return array - * @throws InvalidResourceEntryException */ public function validateArray(int $as, string $k, array $arr, array $default = []): array { $values = $this->getArray($k, $arr, $default); $result = []; foreach ($values as $value) { - $result[] = $this->validateEntryString($as, $value); + try { + $result[] = $this->validateEntryString($as, $value); + } catch (InvalidResourceEntryException $e) { + } } return $result; @@ -469,8 +472,6 @@ abstract class ACore extends Item implements JsonSerializable { /** * @param array $data - * - * @throws InvalidResourceEntryException */ public function import(array $data) { $this->setId($this->validate(self::AS_ID, 'id', $data, '')); diff --git a/lib/Model/ActivityPub/Activity/Add.php b/lib/Model/ActivityPub/Activity/Add.php new file mode 100644 index 00000000..321913eb --- /dev/null +++ b/lib/Model/ActivityPub/Activity/Add.php @@ -0,0 +1,81 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCA\Social\Model\ActivityPub\Activity; + + +use JsonSerializable; +use OCA\Social\Model\ActivityPub\ACore; + + +/** + * Class Add + * + * @package OCA\Social\Model\ActivityPub\Activity + */ +class Add extends ACore implements JsonSerializable { + + + const TYPE = 'Add'; + + + /** + * Activity 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); + } + + + /** + * @return array + */ + public function jsonSerialize(): array { + return array_merge( + parent::jsonSerialize(), + [ + ] + ); + } + +} + diff --git a/lib/Model/ActivityPub/Activity/Block.php b/lib/Model/ActivityPub/Activity/Block.php new file mode 100644 index 00000000..2245ff88 --- /dev/null +++ b/lib/Model/ActivityPub/Activity/Block.php @@ -0,0 +1,81 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCA\Social\Model\ActivityPub\Activity; + + +use JsonSerializable; +use OCA\Social\Model\ActivityPub\ACore; + + +/** + * Class Block + * + * @package OCA\Social\Model\ActivityPub\Activity + */ +class Block extends ACore implements JsonSerializable { + + + const TYPE = 'Block'; + + + /** + * Block 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); + } + + + /** + * @return array + */ + public function jsonSerialize(): array { + return array_merge( + parent::jsonSerialize(), + [ + ] + ); + } + +} + diff --git a/lib/Model/ActivityPub/Activity/Create.php b/lib/Model/ActivityPub/Activity/Create.php index 79385836..a2b8690f 100644 --- a/lib/Model/ActivityPub/Activity/Create.php +++ b/lib/Model/ActivityPub/Activity/Create.php @@ -47,7 +47,7 @@ class Create extends ACore implements JsonSerializable { /** - * Activity constructor. + * Create constructor. * * @param ACore $parent */ @@ -63,7 +63,6 @@ class Create extends ACore implements JsonSerializable { */ public function import(array $data) { parent::import($data); - $this->setActorId($this->validate(ACore::AS_ID, 'actor', $data, '')); } diff --git a/lib/Model/ActivityPub/Follow.php b/lib/Model/ActivityPub/Activity/Follow.php similarity index 94% rename from lib/Model/ActivityPub/Follow.php rename to lib/Model/ActivityPub/Activity/Follow.php index e6e22738..1d35680a 100644 --- a/lib/Model/ActivityPub/Follow.php +++ b/lib/Model/ActivityPub/Activity/Follow.php @@ -28,11 +28,11 @@ declare(strict_types=1); */ -namespace OCA\Social\Model\ActivityPub; +namespace OCA\Social\Model\ActivityPub\Activity; use JsonSerializable; -use OCA\Social\Exceptions\InvalidResourceEntryException; +use OCA\Social\Model\ActivityPub\ACore; /** @@ -105,8 +105,6 @@ class Follow extends ACore implements JsonSerializable { /** * @param array $data - * - * @throws InvalidResourceEntryException */ public function import(array $data) { parent::import($data); diff --git a/lib/Service/ActivityPub/UndoService.php b/lib/Model/ActivityPub/Activity/Like.php similarity index 65% rename from lib/Service/ActivityPub/UndoService.php rename to lib/Model/ActivityPub/Activity/Like.php index cc43449b..947f30c4 100644 --- a/lib/Service/ActivityPub/UndoService.php +++ b/lib/Model/ActivityPub/Activity/Like.php @@ -28,51 +28,53 @@ declare(strict_types=1); */ -namespace OCA\Social\Service\ActivityPub; +namespace OCA\Social\Model\ActivityPub\Activity; -use Exception; +use JsonSerializable; use OCA\Social\Model\ActivityPub\ACore; -use OCA\Social\Service\MiscService; -class UndoService implements ICoreService { +/** + * Class Like + * + * @package OCA\Social\Model\ActivityPub\Activity + */ +class Like extends ACore implements JsonSerializable { - /** @var MiscService */ - private $miscService; + const TYPE = 'Like'; /** - * UndoService constructor. + * Like constructor. * - * @param MiscService $miscService + * @param ACore $parent */ - public function __construct(MiscService $miscService) { - $this->miscService = $miscService; + public function __construct($parent = null) { + parent::__construct($parent); + + $this->setType(self::TYPE); } /** - * @param ACore $undo - * - * @throws Exception + * @param array $data */ - public function parse(ACore $undo) { + public function import(array $data) { + parent::import($data); } /** - * @param ACore $item + * @return array */ - public function save(ACore $item) { - } - - - /** - * @param ACore $item - */ - public function delete(ACore $item) { + public function jsonSerialize(): array { + return array_merge( + parent::jsonSerialize(), + [ + ] + ); } } diff --git a/lib/Model/ActivityPub/Activity/Remove.php b/lib/Model/ActivityPub/Activity/Remove.php new file mode 100644 index 00000000..b51f5dd8 --- /dev/null +++ b/lib/Model/ActivityPub/Activity/Remove.php @@ -0,0 +1,81 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCA\Social\Model\ActivityPub\Activity; + + +use JsonSerializable; +use OCA\Social\Model\ActivityPub\ACore; + + +/** + * Class Remove + * + * @package OCA\Social\Model\ActivityPub\Activity + */ +class Remove extends ACore implements JsonSerializable { + + + const TYPE = 'Remove'; + + + /** + * Remove 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); + } + + + /** + * @return array + */ + public function jsonSerialize(): array { + return array_merge( + parent::jsonSerialize(), + [ + ] + ); + } + +} + diff --git a/lib/Model/ActivityPub/Activity/Update.php b/lib/Model/ActivityPub/Activity/Update.php new file mode 100644 index 00000000..6d29140e --- /dev/null +++ b/lib/Model/ActivityPub/Activity/Update.php @@ -0,0 +1,81 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCA\Social\Model\ActivityPub\Activity; + + +use JsonSerializable; +use OCA\Social\Model\ActivityPub\ACore; + + +/** + * Class Update + * + * @package OCA\Social\Model\ActivityPub\Activity + */ +class Update extends ACore implements JsonSerializable { + + + const TYPE = 'Update'; + + + /** + * Update 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); + } + + + /** + * @return array + */ + public function jsonSerialize(): array { + return array_merge( + parent::jsonSerialize(), + [ + ] + ); + } + +} + diff --git a/lib/Model/ActivityPub/Person.php b/lib/Model/ActivityPub/Actor/Person.php similarity index 98% rename from lib/Model/ActivityPub/Person.php rename to lib/Model/ActivityPub/Actor/Person.php index 2ca62225..adb0ce2f 100644 --- a/lib/Model/ActivityPub/Person.php +++ b/lib/Model/ActivityPub/Actor/Person.php @@ -28,12 +28,14 @@ declare(strict_types=1); */ -namespace OCA\Social\Model\ActivityPub; +namespace OCA\Social\Model\ActivityPub\Actor; use JsonSerializable; use OCA\Social\Exceptions\InvalidResourceEntryException; use OCA\Social\Exceptions\UrlCloudException; +use OCA\Social\Model\ActivityPub\ACore; +use OCA\Social\Model\ActivityPub\Object\Image; /** diff --git a/lib/Model/ActivityPub/Item.php b/lib/Model/ActivityPub/Item.php index b96550a0..1b70038e 100644 --- a/lib/Model/ActivityPub/Item.php +++ b/lib/Model/ActivityPub/Item.php @@ -30,6 +30,7 @@ declare(strict_types=1); namespace OCA\Social\Model\ActivityPub; +use OCA\Social\Model\ActivityPub\Actor\Person; use OCA\Social\Model\InstancePath; diff --git a/lib/Model/ActivityPub/Document.php b/lib/Model/ActivityPub/Object/Document.php similarity index 98% rename from lib/Model/ActivityPub/Document.php rename to lib/Model/ActivityPub/Object/Document.php index 38624c74..b99a9f51 100644 --- a/lib/Model/ActivityPub/Document.php +++ b/lib/Model/ActivityPub/Object/Document.php @@ -28,13 +28,14 @@ declare(strict_types=1); */ -namespace OCA\Social\Model\ActivityPub; +namespace OCA\Social\Model\ActivityPub\Object; use DateTime; use JsonSerializable; use OCA\Social\Exceptions\InvalidResourceEntryException; use OCA\Social\Exceptions\UrlCloudException; +use OCA\Social\Model\ActivityPub\ACore; /** diff --git a/lib/Model/ActivityPub/Image.php b/lib/Model/ActivityPub/Object/Image.php similarity index 95% rename from lib/Model/ActivityPub/Image.php rename to lib/Model/ActivityPub/Object/Image.php index 5947c4a6..11a6d652 100644 --- a/lib/Model/ActivityPub/Image.php +++ b/lib/Model/ActivityPub/Object/Image.php @@ -28,11 +28,12 @@ declare(strict_types=1); */ -namespace OCA\Social\Model\ActivityPub; +namespace OCA\Social\Model\ActivityPub\Object; use JsonSerializable; use OCA\Social\Exceptions\UrlCloudException; +use OCA\Social\Model\ActivityPub\ACore; /** diff --git a/lib/Model/ActivityPub/Note.php b/lib/Model/ActivityPub/Object/Note.php similarity index 98% rename from lib/Model/ActivityPub/Note.php rename to lib/Model/ActivityPub/Object/Note.php index 7598305e..ddfac724 100644 --- a/lib/Model/ActivityPub/Note.php +++ b/lib/Model/ActivityPub/Object/Note.php @@ -27,11 +27,12 @@ declare(strict_types=1); * */ -namespace OCA\Social\Model\ActivityPub; +namespace OCA\Social\Model\ActivityPub\Object; use DateTime; use JsonSerializable; +use OCA\Social\Model\ActivityPub\ACore; use OCA\Social\Service\ActivityService; class Note extends ACore implements JsonSerializable { diff --git a/lib/Model/ActivityPub/Tombstone.php b/lib/Model/ActivityPub/Object/Tombstone.php similarity index 94% rename from lib/Model/ActivityPub/Tombstone.php rename to lib/Model/ActivityPub/Object/Tombstone.php index 8904081f..6247f37d 100644 --- a/lib/Model/ActivityPub/Tombstone.php +++ b/lib/Model/ActivityPub/Object/Tombstone.php @@ -28,10 +28,11 @@ declare(strict_types=1); */ -namespace OCA\Social\Model\ActivityPub; +namespace OCA\Social\Model\ActivityPub\Object; use JsonSerializable; +use OCA\Social\Model\ActivityPub\ACore; /** diff --git a/lib/Service/ActivityPub/Activity/AcceptService.php b/lib/Service/ActivityPub/Activity/AcceptService.php new file mode 100644 index 00000000..bbdfb2aa --- /dev/null +++ b/lib/Service/ActivityPub/Activity/AcceptService.php @@ -0,0 +1,105 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCA\Social\Service\ActivityPub\Activity; + + +use OCA\Social\Exceptions\UnknownItemException; +use OCA\Social\Model\ActivityPub\ACore; +use OCA\Social\Service\ActivityPub\ICoreService; +use OCA\Social\Service\ImportService; +use OCA\Social\Service\MiscService; + + +class AcceptService implements ICoreService { + + + /** @var MiscService */ + private $miscService; + + + /** + * AcceptService constructor. + * + * @param MiscService $miscService + */ + public function __construct(MiscService $miscService) { + $this->miscService = $miscService; + } + + + /** + * @param ACore $item + * @param ImportService $importService + */ + public function processIncomingRequest(ACore $item, ImportService $importService) { + if (!$item->gotObject()) { + return; + } + $object = $item->getObject(); + + try { + $service = $importService->getServiceForItem($item->getObject()); + $service->activity($item, $object); + } catch (UnknownItemException $e) { + } + } + + + /** + * @param ACore $item + * @param ImportService $importService + */ + public function processResult(ACore $item, ImportService $importService) { + } + + + + /** + * @param ACore $item + */ + public function save(ACore $item) { + } + + + /** + * @param ACore $item + */ + public function delete(ACore $item) { + } + + /** + * @param ACore $activity + * @param ACore $item + */ + public function activity(ACore $activity, ACore $item) { + } +} + diff --git a/lib/Service/ActivityPub/Activity/AddService.php b/lib/Service/ActivityPub/Activity/AddService.php new file mode 100644 index 00000000..166e2b80 --- /dev/null +++ b/lib/Service/ActivityPub/Activity/AddService.php @@ -0,0 +1,106 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCA\Social\Service\ActivityPub\Activity; + + +use OCA\Social\Exceptions\UnknownItemException; +use OCA\Social\Model\ActivityPub\ACore; +use OCA\Social\Service\ActivityPub\ICoreService; +use OCA\Social\Service\ImportService; +use OCA\Social\Service\MiscService; + + +class AddService implements ICoreService { + + + /** @var MiscService */ + private $miscService; + + + /** + * AddService constructor. + * + * @param MiscService $miscService + */ + public function __construct(MiscService $miscService) { + $this->miscService = $miscService; + } + + + /** + * @param ACore $item + * @param ImportService $importService + */ + public function processIncomingRequest(ACore $item, ImportService $importService) { + if (!$item->gotObject()) { + return; + } + $object = $item->getObject(); + + try { + $service = $importService->getServiceForItem($item->getObject()); + $service->activity($item, $object); + } catch (UnknownItemException $e) { + } + } + + + /** + * @param ACore $item + * @param ImportService $importService + */ + public function processResult(ACore $item, ImportService $importService) { + } + + + + + /** + * @param ACore $item + */ + public function save(ACore $item) { + } + + + /** + * @param ACore $item + */ + public function delete(ACore $item) { + } + + /** + * @param ACore $activity + * @param ACore $item + */ + public function activity(ACore $activity, ACore $item) { + } +} + diff --git a/lib/Service/ActivityPub/Activity/BlockService.php b/lib/Service/ActivityPub/Activity/BlockService.php new file mode 100644 index 00000000..35c58e3f --- /dev/null +++ b/lib/Service/ActivityPub/Activity/BlockService.php @@ -0,0 +1,106 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCA\Social\Service\ActivityPub\Activity; + + +use OCA\Social\Exceptions\UnknownItemException; +use OCA\Social\Model\ActivityPub\ACore; +use OCA\Social\Service\ActivityPub\ICoreService; +use OCA\Social\Service\ImportService; +use OCA\Social\Service\MiscService; + + +class BlockService implements ICoreService { + + + /** @var MiscService */ + private $miscService; + + + /** + * BlockService constructor. + * + * @param MiscService $miscService + */ + public function __construct(MiscService $miscService) { + $this->miscService = $miscService; + } + + + /** + * @param ACore $item + * @param ImportService $importService + */ + public function processIncomingRequest(ACore $item, ImportService $importService) { + if (!$item->gotObject()) { + return; + } + $object = $item->getObject(); + + try { + $service = $importService->getServiceForItem($item->getObject()); + $service->activity($item, $object); + } catch (UnknownItemException $e) { + } + } + + + /** + * @param ACore $item + * @param ImportService $importService + */ + public function processResult(ACore $item, ImportService $importService) { + } + + + + + /** + * @param ACore $item + */ + public function save(ACore $item) { + } + + + /** + * @param ACore $item + */ + public function delete(ACore $item) { + } + + /** + * @param ACore $activity + * @param ACore $item + */ + public function activity(ACore $activity, ACore $item) { + } +} + diff --git a/lib/Service/ActivityPub/Activity/CreateService.php b/lib/Service/ActivityPub/Activity/CreateService.php new file mode 100644 index 00000000..fe874dd8 --- /dev/null +++ b/lib/Service/ActivityPub/Activity/CreateService.php @@ -0,0 +1,104 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCA\Social\Service\ActivityPub\Activity; + + +use OCA\Social\Exceptions\UnknownItemException; +use OCA\Social\Model\ActivityPub\ACore; +use OCA\Social\Service\ActivityPub\ICoreService; +use OCA\Social\Service\ImportService; +use OCA\Social\Service\MiscService; + + +class CreateService implements ICoreService { + + + /** @var MiscService */ + private $miscService; + + + /** + * CreateService constructor. + * + * @param MiscService $miscService + */ + public function __construct(MiscService $miscService) { + $this->miscService = $miscService; + } + + + /** + * @param ACore $item + * @param ImportService $importService + */ + public function processIncomingRequest(ACore $item, ImportService $importService) { + if (!$item->gotObject()) { + return; + } + $object = $item->getObject(); + + try { + $service = $importService->getServiceForItem($item->getObject()); + $service->activity($item, $object); + } catch (UnknownItemException $e) { + } + } + + + /** + * @param ACore $item + * @param ImportService $importService + */ + public function processResult(ACore $item, ImportService $importService) { + } + + + /** + * @param ACore $item + */ + public function save(ACore $item) { + } + + + /** + * @param ACore $item + */ + public function delete(ACore $item) { + } + + /** + * @param ACore $activity + * @param ACore $item + */ + public function activity(ACore $activity, ACore $item) { + } +} + diff --git a/lib/Service/ActivityPub/DeleteService.php b/lib/Service/ActivityPub/Activity/DeleteService.php similarity index 70% rename from lib/Service/ActivityPub/DeleteService.php rename to lib/Service/ActivityPub/Activity/DeleteService.php index 1b150ed6..fb789d03 100644 --- a/lib/Service/ActivityPub/DeleteService.php +++ b/lib/Service/ActivityPub/Activity/DeleteService.php @@ -28,31 +28,26 @@ declare(strict_types=1); */ -namespace OCA\Social\Service\ActivityPub; +namespace OCA\Social\Service\ActivityPub\Activity; -use Exception; -use OCA\Social\Db\NotesRequest; use OCA\Social\Exceptions\InvalidOriginException; use OCA\Social\Exceptions\InvalidResourceException; use OCA\Social\Exceptions\UnknownItemException; use OCA\Social\Model\ActivityPub\ACore; use OCA\Social\Model\ActivityPub\Activity\Delete; +use OCA\Social\Service\ActivityPub\ICoreService; use OCA\Social\Service\ActivityService; +use OCA\Social\Service\ImportService; use OCA\Social\Service\MiscService; class DeleteService implements ICoreService { - /** @var NotesRequest */ - private $notesRequest; - /** @var ActivityService */ private $activityService; - /** @var NoteService */ - private $noteService; /** @var MiscService */ private $miscService; @@ -61,33 +56,22 @@ class DeleteService implements ICoreService { /** * UndoService constructor. * - * @param NotesRequest $notesRequest * @param ActivityService $activityService - * @param NoteService $noteService * @param MiscService $miscService */ - public function __construct( - NotesRequest $notesRequest, ActivityService $activityService, NoteService $noteService, - MiscService $miscService - ) { - $this->notesRequest = $notesRequest; + public function __construct(ActivityService $activityService, MiscService $miscService) { $this->activityService = $activityService; - $this->noteService = $noteService; $this->miscService = $miscService; } /** * @param ACore $delete + * @param ImportService $importService * - * @throws UnknownItemException * @throws InvalidOriginException */ - public function parse(ACore $delete) { - - if (!$delete->isRoot()) { - throw new UnknownItemException(); - } + public function processIncomingRequest(ACore $delete, ImportService $importService) { if ($delete->gotObject()) { $id = $delete->getObject() @@ -101,29 +85,35 @@ class DeleteService implements ICoreService { /** @var Delete $delete */ try { $item = $this->activityService->getItem($id); + $service = $importService->getServiceForItem($item); - switch ($item->getType()) { - - case 'Note': - $service = $this->noteService; - break; - - default: - throw new UnknownItemException(); - } - - try { - $service->delete($item); - } catch (Exception $e) { - $this->miscService->log( - 2, 'Cannot delete ' . $delete->getType() . ': ' . $e->getMessage() - ); - } + // we could use ->activity($delete, $item) but the delete() is important enough to + // be here, and to use it. + $service->delete($item); + } catch (UnknownItemException $e) { } catch (InvalidResourceException $e) { } } + + /** + * @param ACore $item + * @param ImportService $importService + */ + public function processResult(ACore $item, ImportService $importService) { + } + + + + /** + * @param ACore $activity + * @param ACore $item + */ + public function activity(Acore $activity, ACore $item) { + } + + /** * @param ACore $item */ diff --git a/lib/Service/ActivityPub/FollowService.php b/lib/Service/ActivityPub/Activity/FollowService.php similarity index 76% rename from lib/Service/ActivityPub/FollowService.php rename to lib/Service/ActivityPub/Activity/FollowService.php index bd802be5..0d90a040 100644 --- a/lib/Service/ActivityPub/FollowService.php +++ b/lib/Service/ActivityPub/Activity/FollowService.php @@ -28,29 +28,35 @@ declare(strict_types=1); */ -namespace OCA\Social\Service\ActivityPub; +namespace OCA\Social\Service\ActivityPub\Activity; +use daita\MySmallPhpTools\Exceptions\MalformedArrayException; use Exception; use OCA\Social\Db\FollowsRequest; use OCA\Social\Exceptions\ActorDoesNotExistException; use OCA\Social\Exceptions\CacheActorDoesNotExistException; use OCA\Social\Exceptions\FollowDoesNotExistException; use OCA\Social\Exceptions\FollowSameAccountException; +use OCA\Social\Exceptions\InvalidOriginException; use OCA\Social\Exceptions\InvalidResourceException; +use OCA\Social\Exceptions\Request410Exception; use OCA\Social\Exceptions\RequestException; use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Exceptions\UrlCloudException; use OCA\Social\Model\ActivityPub\ACore; use OCA\Social\Model\ActivityPub\Activity\Accept; +use OCA\Social\Model\ActivityPub\Activity\Follow; use OCA\Social\Model\ActivityPub\Activity\Reject; use OCA\Social\Model\ActivityPub\Activity\Undo; -use OCA\Social\Model\ActivityPub\Follow; use OCA\Social\Model\ActivityPub\OrderedCollection; -use OCA\Social\Model\ActivityPub\Person; +use OCA\Social\Model\ActivityPub\Actor\Person; use OCA\Social\Model\InstancePath; +use OCA\Social\Service\ActivityPub\ICoreService; +use OCA\Social\Service\ActivityPub\Actor\PersonService; use OCA\Social\Service\ActivityService; use OCA\Social\Service\ConfigService; +use OCA\Social\Service\ImportService; use OCA\Social\Service\MiscService; @@ -225,6 +231,14 @@ class FollowService implements ICoreService { } + /** + * @param ACore $item + * @param ImportService $importService + */ + public function processResult(ACore $item, ImportService $importService) { + } + + /** * @param Follow $follow */ @@ -257,54 +271,62 @@ class FollowService implements ICoreService { * This method is called when saving the Follow object * * @param ACore $follow + * @param ImportService $importService * - * @throws Exception + * @throws InvalidResourceException + * @throws RequestException + * @throws SocialAppConfigException + * @throws UrlCloudException + * @throws InvalidOriginException + * @throws Request410Exception + * @throws MalformedArrayException */ - public function parse(ACore $follow) { - + public function processIncomingRequest(ACore $follow, ImportService $importService) { /** @var Follow $follow */ - if ($follow->isRoot()) { - $follow->checkOrigin($follow->getActorId()); + $follow->checkOrigin($follow->getActorId()); - try { - $knownFollow = $this->followsRequest->getByPersons( - $follow->getActorId(), $follow->getObjectId() - ); - // in case of local follower. - // TODO - remove when following a local account does not need curl request anymore - if ($knownFollow->getId() === $follow->getId() && !$knownFollow->isAccepted()) { - $this->confirmFollowRequest($follow); - } - } catch (FollowDoesNotExistException $e) { - $actor = $this->personService->getFromId($follow->getObjectId()); - if ($actor->isLocal()) { - $follow->setFollowId($actor->getFollowers()); - $this->followsRequest->save($follow); - $this->confirmFollowRequest($follow); - } + try { + $knownFollow = $this->followsRequest->getByPersons( + $follow->getActorId(), $follow->getObjectId() + ); + + if ($knownFollow->getId() === $follow->getId() && !$knownFollow->isAccepted()) { + $this->confirmFollowRequest($follow); } - - } else { - $parent = $follow->getParent(); - if (!$parent->isRoot()) { - return; + } catch (FollowDoesNotExistException $e) { + $actor = $this->personService->getFromId($follow->getObjectId()); + if ($actor->isLocal()) { + $follow->setFollowId($actor->getFollowers()); + $this->followsRequest->save($follow); + $this->confirmFollowRequest($follow); } + } - if ($parent->getType() === Undo::TYPE) { - $parent->checkOrigin($follow->getActorId()); - $this->followsRequest->deleteByPersons($follow); - } +// } else { + } - if ($parent->getType() === Reject::TYPE) { - $parent->checkOrigin($follow->getObjectId()); - $this->followsRequest->deleteByPersons($follow); - } - if ($parent->getType() === Accept::TYPE) { - $parent->checkOrigin($follow->getObjectId()); - $this->followsRequest->accepted($follow); - } + /** + * @param ACore $activity + * @param ACore $item + * + * @throws InvalidOriginException + */ + public function activity(Acore $activity, ACore $item) { + /** @var Follow $item */ + if ($activity->getType() === Undo::TYPE) { + $activity->checkOrigin($item->getActorId()); + $this->followsRequest->deleteByPersons($item); + } + if ($activity->getType() === Reject::TYPE) { + $activity->checkOrigin($item->getObjectId()); + $this->followsRequest->deleteByPersons($item); + } + + if ($activity->getType() === Accept::TYPE) { + $activity->checkOrigin($item->getObjectId()); + $this->followsRequest->accepted($item); } } diff --git a/lib/Service/ActivityPub/Activity/LikeService.php b/lib/Service/ActivityPub/Activity/LikeService.php new file mode 100644 index 00000000..a85c82c5 --- /dev/null +++ b/lib/Service/ActivityPub/Activity/LikeService.php @@ -0,0 +1,104 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCA\Social\Service\ActivityPub\Activity; + + +use OCA\Social\Exceptions\UnknownItemException; +use OCA\Social\Model\ActivityPub\ACore; +use OCA\Social\Service\ActivityPub\ICoreService; +use OCA\Social\Service\ImportService; +use OCA\Social\Service\MiscService; + + +class LikeService implements ICoreService { + + + /** @var MiscService */ + private $miscService; + + + /** + * LikeService constructor. + * + * @param MiscService $miscService + */ + public function __construct(MiscService $miscService) { + $this->miscService = $miscService; + } + + + /** + * @param ACore $item + * @param ImportService $importService + */ + public function processIncomingRequest(ACore $item, ImportService $importService) { + if (!$item->gotObject()) { + return; + } + $object = $item->getObject(); + + try { + $service = $importService->getServiceForItem($item->getObject()); + $service->activity($item, $object); + } catch (UnknownItemException $e) { + } + } + + + /** + * @param ACore $item + * @param ImportService $importService + */ + public function processResult(ACore $item, ImportService $importService) { + } + + + /** + * @param ACore $item + */ + public function save(ACore $item) { + } + + + /** + * @param ACore $item + */ + public function delete(ACore $item) { + } + + /** + * @param ACore $activity + * @param ACore $item + */ + public function activity(ACore $activity, ACore $item) { + } +} + diff --git a/lib/Service/ActivityPub/Activity/RejectService.php b/lib/Service/ActivityPub/Activity/RejectService.php new file mode 100644 index 00000000..859703fe --- /dev/null +++ b/lib/Service/ActivityPub/Activity/RejectService.php @@ -0,0 +1,105 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCA\Social\Service\ActivityPub\Activity; + + +use OCA\Social\Exceptions\UnknownItemException; +use OCA\Social\Model\ActivityPub\ACore; +use OCA\Social\Service\ActivityPub\ICoreService; +use OCA\Social\Service\ImportService; +use OCA\Social\Service\MiscService; + + +class RejectService implements ICoreService { + + + /** @var MiscService */ + private $miscService; + + + /** + * RejectService constructor. + * + * @param MiscService $miscService + */ + public function __construct(MiscService $miscService) { + $this->miscService = $miscService; + } + + + /** + * @param ACore $item + * @param ImportService $importService + */ + public function processIncomingRequest(ACore $item, ImportService $importService) { + if (!$item->gotObject()) { + return; + } + $object = $item->getObject(); + + try { + $service = $importService->getServiceForItem($item->getObject()); + $service->activity($item, $object); + } catch (UnknownItemException $e) { + } + } + + + /** + * @param ACore $item + * @param ImportService $importService + */ + public function processResult(ACore $item, ImportService $importService) { + } + + + + /** + * @param ACore $item + */ + public function save(ACore $item) { + } + + + /** + * @param ACore $item + */ + public function delete(ACore $item) { + } + + /** + * @param ACore $activity + * @param ACore $item + */ + public function activity(ACore $activity, ACore $item) { + } +} + diff --git a/lib/Service/ActivityPub/Activity/RemoveService.php b/lib/Service/ActivityPub/Activity/RemoveService.php new file mode 100644 index 00000000..525fa5c7 --- /dev/null +++ b/lib/Service/ActivityPub/Activity/RemoveService.php @@ -0,0 +1,106 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCA\Social\Service\ActivityPub\Activity; + + +use OCA\Social\Exceptions\UnknownItemException; +use OCA\Social\Model\ActivityPub\ACore; +use OCA\Social\Service\ActivityPub\ICoreService; +use OCA\Social\Service\ImportService; +use OCA\Social\Service\MiscService; + + +class RemoveService implements ICoreService { + + + /** @var MiscService */ + private $miscService; + + + /** + * RemoveService constructor. + * + * @param MiscService $miscService + */ + public function __construct(MiscService $miscService) { + $this->miscService = $miscService; + } + + + /** + * @param ACore $item + * @param ImportService $importService + */ + public function processIncomingRequest(ACore $item, ImportService $importService) { + if (!$item->gotObject()) { + return; + } + $object = $item->getObject(); + + try { + $service = $importService->getServiceForItem($item->getObject()); + $service->activity($item, $object); + } catch (UnknownItemException $e) { + } + } + + + /** + * @param ACore $item + * @param ImportService $importService + */ + public function processResult(ACore $item, ImportService $importService) { + } + + + + /** + * @param ACore $item + */ + public function save(ACore $item) { + } + + + /** + * @param ACore $item + */ + public function delete(ACore $item) { + } + + + /** + * @param ACore $activity + * @param ACore $item + */ + public function activity(ACore $activity, ACore $item) { + } +} + diff --git a/lib/Service/ActivityPub/Activity/UndoService.php b/lib/Service/ActivityPub/Activity/UndoService.php new file mode 100644 index 00000000..96d7b30e --- /dev/null +++ b/lib/Service/ActivityPub/Activity/UndoService.php @@ -0,0 +1,108 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCA\Social\Service\ActivityPub\Activity; + + +use OCA\Social\Exceptions\UnknownItemException; +use OCA\Social\Model\ActivityPub\ACore; +use OCA\Social\Service\ActivityPub\ICoreService; +use OCA\Social\Service\ImportService; +use OCA\Social\Service\MiscService; + + +class UndoService implements ICoreService { + + + /** @var MiscService */ + private $miscService; + + + /** + * UndoService constructor. + * + * @param MiscService $miscService + */ + public function __construct(MiscService $miscService) { + $this->miscService = $miscService; + } + + + /** + * @param ACore $item + * @param ImportService $importService + */ + public function processIncomingRequest(ACore $item, ImportService $importService) { + if (!$item->gotObject()) { + return; + } + $object = $item->getObject(); + + try { + $service = $importService->getServiceForItem($item->getObject()); + $service->activity($item, $object); + } catch (UnknownItemException $e) { + } + } + + + /** + * @param ACore $item + * @param ImportService $importService + */ + public function processResult(ACore $item, ImportService $importService) { + } + + + + + /** + * @param ACore $item + */ + public function save(ACore $item) { + } + + + /** + * @param ACore $item + */ + public function delete(ACore $item) { + } + + + /** + * @param ACore $activity + * @param ACore $item + */ + public function activity(Acore $activity, ACore $item) { + } + +} + diff --git a/lib/Service/ActivityPub/Activity/UpdateService.php b/lib/Service/ActivityPub/Activity/UpdateService.php new file mode 100644 index 00000000..82582600 --- /dev/null +++ b/lib/Service/ActivityPub/Activity/UpdateService.php @@ -0,0 +1,104 @@ + + * @copyright 2018, Maxence Lange + * @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 . + * + */ + + +namespace OCA\Social\Service\ActivityPub\Activity; + + +use OCA\Social\Exceptions\UnknownItemException; +use OCA\Social\Model\ActivityPub\ACore; +use OCA\Social\Service\ActivityPub\ICoreService; +use OCA\Social\Service\ImportService; +use OCA\Social\Service\MiscService; + + +class UpdateService implements ICoreService { + + + /** @var MiscService */ + private $miscService; + + + /** + * UpdateService constructor. + * + * @param MiscService $miscService + */ + public function __construct(MiscService $miscService) { + $this->miscService = $miscService; + } + + + /** + * @param ACore $item + * @param ImportService $importService + */ + public function processIncomingRequest(ACore $item, ImportService $importService) { + if (!$item->gotObject()) { + return; + } + $object = $item->getObject(); + + try { + $service = $importService->getServiceForItem($item->getObject()); + $service->activity($item, $object); + } catch (UnknownItemException $e) { + } + } + + + /** + * @param ACore $item + * @param ImportService $importService + */ + public function processResult(ACore $item, ImportService $importService) { + } + + + /** + * @param ACore $item + */ + public function save(ACore $item) { + } + + + /** + * @param ACore $item + */ + public function delete(ACore $item) { + } + + /** + * @param ACore $activity + * @param ACore $item + */ + public function activity(ACore $activity, ACore $item) { + } +} + diff --git a/lib/Service/ActivityPub/PersonService.php b/lib/Service/ActivityPub/Actor/PersonService.php similarity index 90% rename from lib/Service/ActivityPub/PersonService.php rename to lib/Service/ActivityPub/Actor/PersonService.php index 3674483c..914bedb1 100644 --- a/lib/Service/ActivityPub/PersonService.php +++ b/lib/Service/ActivityPub/Actor/PersonService.php @@ -28,7 +28,7 @@ declare(strict_types=1); */ -namespace OCA\Social\Service\ActivityPub; +namespace OCA\Social\Service\ActivityPub\Actor; use daita\MySmallPhpTools\Exceptions\MalformedArrayException; @@ -45,8 +45,11 @@ use OCA\Social\Exceptions\RequestException; use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Exceptions\UrlCloudException; use OCA\Social\Model\ActivityPub\ACore; -use OCA\Social\Model\ActivityPub\Person; +use OCA\Social\Model\ActivityPub\Activity\Update; +use OCA\Social\Model\ActivityPub\Actor\Person; +use OCA\Social\Service\ActivityPub\ICoreService; use OCA\Social\Service\ConfigService; +use OCA\Social\Service\ImportService; use OCA\Social\Service\InstanceService; use OCA\Social\Service\MiscService; @@ -257,20 +260,23 @@ class PersonService implements ICoreService { /** - * This method is called when saving the Follow object - * * @param ACore $person + * @param ImportService $importService */ - public function parse(ACore $person) { - /** @var Person $person */ - if ($person->isRoot() === false || $person->getId() === '') { - return; - } - - $this->save($person); + public function processIncomingRequest(ACore $person, ImportService $importService) { } + /** + * @param ACore $item + * @param ImportService $importService + */ + public function processResult(ACore $item, ImportService $importService) { + } + + + + /** * @param ACore $person */ @@ -292,6 +298,18 @@ class PersonService implements ICoreService { } + /** + * @param ACore $activity + * @param ACore $item + */ + public function activity(Acore $activity, ACore $item) { + /** @var Person $item */ + if ($activity->getType() === Update::TYPE) { + $this->miscService->log('### UPDATE PERSON !' . json_encode($item)); + } + } + + /** * @throws Exception * @return int diff --git a/lib/Service/ActivityPub/ICoreService.php b/lib/Service/ActivityPub/ICoreService.php index fd6cda09..a0ec09b8 100644 --- a/lib/Service/ActivityPub/ICoreService.php +++ b/lib/Service/ActivityPub/ICoreService.php @@ -32,6 +32,7 @@ namespace OCA\Social\Service\ActivityPub; use OCA\Social\Model\ActivityPub\ACore; +use OCA\Social\Service\ImportService; /** @@ -43,18 +44,43 @@ interface ICoreService { /** + * Freshly imported item can be processed/parsed on incoming Request. + * * @param ACore $item + * @param ImportService $importService */ - public function parse(ACore $item); + public function processIncomingRequest(ACore $item, ImportService $importService); /** + * Freshly imported item can be processed/parsed on result of outgoing request. + * + * @param ACore $item + * @param ImportService $importService + */ + public function processResult(ACore $item, ImportService $importService); + + + /** + * When an activity is triggered by an 'Model\ActivityPub\Activity' model. + * + * @param ACore $activity + * @param ACore $item + */ + public function activity(ACore $activity, ACore $item); + + + /** + * Save the current item. + * * @param ACore $item */ public function save(ACore $item); /** + * Delete the current item. + * * @param ACore $item */ public function delete(ACore $item); diff --git a/lib/Service/ActivityPub/DocumentService.php b/lib/Service/ActivityPub/Object/DocumentService.php similarity index 90% rename from lib/Service/ActivityPub/DocumentService.php rename to lib/Service/ActivityPub/Object/DocumentService.php index 538fd9fa..b8a576ff 100644 --- a/lib/Service/ActivityPub/DocumentService.php +++ b/lib/Service/ActivityPub/Object/DocumentService.php @@ -28,7 +28,7 @@ declare(strict_types=1); */ -namespace OCA\Social\Service\ActivityPub; +namespace OCA\Social\Service\ActivityPub\Object; use Exception; @@ -41,11 +41,13 @@ use OCA\Social\Exceptions\CacheDocumentDoesNotExistException; use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Exceptions\UrlCloudException; use OCA\Social\Model\ActivityPub\ACore; -use OCA\Social\Model\ActivityPub\Document; -use OCA\Social\Model\ActivityPub\Image; -use OCA\Social\Model\ActivityPub\Person; +use OCA\Social\Model\ActivityPub\Object\Document; +use OCA\Social\Model\ActivityPub\Object\Image; +use OCA\Social\Model\ActivityPub\Actor\Person; +use OCA\Social\Service\ActivityPub\ICoreService; use OCA\Social\Service\CacheService; use OCA\Social\Service\ConfigService; +use OCA\Social\Service\ImportService; use OCA\Social\Service\MiscService; use OCP\Files\NotPermittedException; use OCP\Files\SimpleFS\ISimpleFile; @@ -232,9 +234,26 @@ class DocumentService implements ICoreService { /** + * @param ACore $activity * @param ACore $item */ - public function parse(ACore $item) { + public function activity(Acore $activity, ACore $item) { + } + + + /** + * @param ACore $item + * @param ImportService $importService + */ + public function processIncomingRequest(ACore $item, ImportService $importService) { + } + + + /** + * @param ACore $item + * @param ImportService $importService + */ + public function processResult(ACore $item, ImportService $importService) { } diff --git a/lib/Service/ActivityPub/NoteService.php b/lib/Service/ActivityPub/Object/NoteService.php similarity index 91% rename from lib/Service/ActivityPub/NoteService.php rename to lib/Service/ActivityPub/Object/NoteService.php index af0257f9..a8b9a968 100644 --- a/lib/Service/ActivityPub/NoteService.php +++ b/lib/Service/ActivityPub/Object/NoteService.php @@ -28,7 +28,7 @@ declare(strict_types=1); */ -namespace OCA\Social\Service\ActivityPub; +namespace OCA\Social\Service\ActivityPub\Object; use Exception; @@ -41,13 +41,16 @@ use OCA\Social\Exceptions\RequestException; use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Model\ActivityPub\ACore; use OCA\Social\Model\ActivityPub\Activity\Create; -use OCA\Social\Model\ActivityPub\Note; -use OCA\Social\Model\ActivityPub\Person; +use OCA\Social\Model\ActivityPub\Object\Note; +use OCA\Social\Model\ActivityPub\Actor\Person; use OCA\Social\Model\InstancePath; +use OCA\Social\Service\ActivityPub\Actor\PersonService; +use OCA\Social\Service\ActivityPub\ICoreService; use OCA\Social\Service\ActivityService; use OCA\Social\Service\ActorService; use OCA\Social\Service\ConfigService; use OCA\Social\Service\CurlService; +use OCA\Social\Service\ImportService; use OCA\Social\Service\MiscService; @@ -273,28 +276,18 @@ class NoteService implements ICoreService { /** - * This method is called when saving the Note object - * * @param ACore $note - * - * @throws InvalidOriginException + * @param ImportService $importService */ - public function parse(ACore $note) { + public function processIncomingRequest(ACore $note, ImportService $importService) { + } - /** @var Note $note */ - if ($note->isRoot()) { - return; - } - $parent = $note->getParent(); - if (!$parent->isRoot()) { - return; - } - - if ($parent->getType() === Create::TYPE) { - $parent->checkOrigin($note->getAttributedTo()); - $this->save($note); - } + /** + * @param ACore $item + * @param ImportService $importService + */ + public function processResult(ACore $item, ImportService $importService) { } @@ -312,6 +305,22 @@ class NoteService implements ICoreService { } + /** + * @param ACore $activity + * @param ACore $item + * + * @throws InvalidOriginException + */ + public function activity(Acore $activity, ACore $item) { + /** @var Note $item */ + + if ($activity->getType() === Create::TYPE) { + $activity->checkOrigin($item->getAttributedTo()); + $this->save($item); + } + } + + /** * @param Note $note * @@ -404,6 +413,7 @@ class NoteService implements ICoreService { */ public function getStreamInternalTimeline(int $since = 0, int $limit = 5): array { // TODO - admin should be able to provide a list of 'friendly/internal' instance of ActivityPub + return []; } diff --git a/lib/Service/ActivityService.php b/lib/Service/ActivityService.php index 1dd74c0c..7c20caed 100644 --- a/lib/Service/ActivityService.php +++ b/lib/Service/ActivityService.php @@ -53,11 +53,11 @@ use OCA\Social\Exceptions\UrlCloudException; use OCA\Social\Model\ActivityPub\ACore; use OCA\Social\Model\ActivityPub\Activity\Create; use OCA\Social\Model\ActivityPub\Activity\Delete; -use OCA\Social\Model\ActivityPub\Person; -use OCA\Social\Model\ActivityPub\Tombstone; +use OCA\Social\Model\ActivityPub\Actor\Person; +use OCA\Social\Model\ActivityPub\Object\Tombstone; use OCA\Social\Model\InstancePath; use OCA\Social\Model\RequestQueue; -use OCA\Social\Service\ActivityPub\PersonService; +use OCA\Social\Service\ActivityPub\Actor\PersonService; use OCP\IRequest; class ActivityService { @@ -482,7 +482,7 @@ class ActivityService { /** * @param IRequest $request * - * @return + * @return string * @throws InvalidResourceException * @throws MalformedArrayException * @throws Request410Exception @@ -492,7 +492,7 @@ class ActivityService { * @throws UrlCloudException * @throws InvalidOriginException */ - private function checkSignature(IRequest $request) { + private function checkSignature(IRequest $request): string { $signatureHeader = $request->getHeader('Signature'); $sign = $this->parseSignatureHeader($signatureHeader); diff --git a/lib/Service/ActorService.php b/lib/Service/ActorService.php index 174a3732..cb088fab 100644 --- a/lib/Service/ActorService.php +++ b/lib/Service/ActorService.php @@ -41,9 +41,9 @@ use OCA\Social\Exceptions\ActorDoesNotExistException; use OCA\Social\Exceptions\FollowDoesNotExistException; use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Exceptions\UrlCloudException; -use OCA\Social\Model\ActivityPub\Person; -use OCA\Social\Service\ActivityPub\DocumentService; -use OCA\Social\Service\ActivityPub\PersonService; +use OCA\Social\Model\ActivityPub\Actor\Person; +use OCA\Social\Service\ActivityPub\Object\DocumentService; +use OCA\Social\Service\ActivityPub\Actor\PersonService; use OCP\Accounts\IAccountManager; use OCP\IUserManager; diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index fe7e9c66..df59fe1c 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -31,8 +31,6 @@ namespace OCA\Social\Service; use daita\MySmallPhpTools\Traits\TArrayTools; use daita\MySmallPhpTools\Traits\TPathTools; -use OC\IntegrityCheck\Helpers\AppLocator; -use OCA\Files\App; use OCA\Social\AppInfo\Application; use OCA\Social\Exceptions\SocialAppConfigException; use OCP\IConfig; diff --git a/lib/Service/ImportService.php b/lib/Service/ImportService.php index 73072a7e..cddfb937 100644 --- a/lib/Service/ImportService.php +++ b/lib/Service/ImportService.php @@ -35,25 +35,40 @@ use daita\MySmallPhpTools\Traits\TArrayTools; use Exception; use OCA\Social\Exceptions\ActivityPubFormatException; use OCA\Social\Exceptions\InvalidResourceEntryException; -use OCA\Social\Exceptions\InvalidResourceException; use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Exceptions\UnknownItemException; use OCA\Social\Exceptions\UrlCloudException; use OCA\Social\Model\ActivityPub\ACore; use OCA\Social\Model\ActivityPub\Activity\Accept; +use OCA\Social\Model\ActivityPub\Activity\Add; +use OCA\Social\Model\ActivityPub\Activity\Block; use OCA\Social\Model\ActivityPub\Activity\Create; use OCA\Social\Model\ActivityPub\Activity\Delete; +use OCA\Social\Model\ActivityPub\Activity\Follow; +use OCA\Social\Model\ActivityPub\Activity\Like; use OCA\Social\Model\ActivityPub\Activity\Reject; -use OCA\Social\Model\ActivityPub\Tombstone; -use OCA\Social\Model\ActivityPub\Document; -use OCA\Social\Model\ActivityPub\Follow; -use OCA\Social\Model\ActivityPub\Image; -use OCA\Social\Model\ActivityPub\Note; +use OCA\Social\Model\ActivityPub\Activity\Remove; use OCA\Social\Model\ActivityPub\Activity\Undo; -use OCA\Social\Service\ActivityPub\DeleteService; -use OCA\Social\Service\ActivityPub\FollowService; -use OCA\Social\Service\ActivityPub\NoteService; -use OCA\Social\Service\ActivityPub\UndoService; +use OCA\Social\Model\ActivityPub\Activity\Update; +use OCA\Social\Model\ActivityPub\Object\Document; +use OCA\Social\Model\ActivityPub\Object\Image; +use OCA\Social\Model\ActivityPub\Object\Note; +use OCA\Social\Model\ActivityPub\Actor\Person; +use OCA\Social\Model\ActivityPub\Object\Tombstone; +use OCA\Social\Service\ActivityPub\Activity\AcceptService; +use OCA\Social\Service\ActivityPub\Activity\AddService; +use OCA\Social\Service\ActivityPub\Activity\BlockService; +use OCA\Social\Service\ActivityPub\Activity\CreateService; +use OCA\Social\Service\ActivityPub\Activity\DeleteService; +use OCA\Social\Service\ActivityPub\Activity\FollowService; +use OCA\Social\Service\ActivityPub\Activity\LikeService; +use OCA\Social\Service\ActivityPub\Activity\RejectService; +use OCA\Social\Service\ActivityPub\Activity\RemoveService; +use OCA\Social\Service\ActivityPub\Activity\UndoService; +use OCA\Social\Service\ActivityPub\Activity\UpdateService; +use OCA\Social\Service\ActivityPub\ICoreService; +use OCA\Social\Service\ActivityPub\Object\NoteService; +use OCA\Social\Service\ActivityPub\Actor\PersonService; class ImportService { @@ -61,18 +76,44 @@ class ImportService { use TArrayTools; + /** @var AcceptService */ + private $acceptService; - /** @var NoteService */ - private $noteService; + /** @var AddService */ + private $addService; - /** @var UndoService */ - private $undoService; + /** @var BlockService */ + private $blockService; + + /** @var CreateService */ + private $createService; + + /** @var DeleteService */ + private $deleteService; /** @var FollowService */ private $followService; - /** @var DeleteService */ - private $deleteService; + /** @var LikeService */ + private $likeService; + + /** @var PersonService */ + private $personService; + + /** @var NoteService */ + private $noteService; + + /** @var RejectService */ + private $rejectService; + + /** @var RemoveService */ + private $removeService; + + /** @var UndoService */ + private $undoService; + + /** @var UpdateService */ + private $updateService; /** @var ConfigService */ private $configService; @@ -84,21 +125,43 @@ class ImportService { /** * ImportService constructor. * - * @param NoteService $noteService - * @param UndoService $undoService - * @param FollowService $followService + * @param AcceptService $acceptService + * @param AddService $addService + * @param BlockService $blockService + * @param CreateService $createService * @param DeleteService $deleteService + * @param FollowService $followService + * @param NoteService $noteService + * @param LikeService $likeService + * @param PersonService $personService + * @param RejectService $rejectService + * @param RemoveService $removeService + * @param UndoService $undoService + * @param UpdateService $updateService * @param ConfigService $configService * @param MiscService $miscService */ public function __construct( - NoteService $noteService, UndoService $undoService, FollowService $followService, - DeleteService $deleteService, ConfigService $configService, MiscService $miscService + AcceptService $acceptService, AddService $addService, BlockService $blockService, + CreateService $createService, DeleteService $deleteService, FollowService $followService, + NoteService $noteService, LikeService $likeService, PersonService $personService, + RejectService $rejectService, RemoveService $removeService, + UndoService $undoService, UpdateService $updateService, + ConfigService $configService, MiscService $miscService ) { + $this->acceptService = $acceptService; + $this->addService = $addService; + $this->blockService = $blockService; + $this->createService = $createService; + $this->deleteService = $deleteService; + $this->followService = $followService; + $this->likeService = $likeService; + $this->rejectService = $rejectService; + $this->removeService = $removeService; + $this->personService = $personService; $this->noteService = $noteService; $this->undoService = $undoService; - $this->followService = $followService; - $this->deleteService = $deleteService; + $this->updateService = $updateService; $this->configService = $configService; $this->miscService = $miscService; } @@ -142,6 +205,14 @@ class ImportService { $item = new Accept($root); break; + case Add::TYPE: + $item = new Add($root); + break; + + case Block::TYPE: + $item = new Block($root); + break; + case Create::TYPE: $item = new Create($root); break; @@ -158,14 +229,26 @@ class ImportService { $item = new Image($root); break; + case Like::TYPE: + $item = new Like($root); + break; + case Note::TYPE: $item = new Note($root); break; + case Person::TYPE: + $item = new Note($root); + break; + case Reject::TYPE: $item = new Reject($root); break; + case Remove::TYPE: + $item = new Remove($root); + break; + case Tombstone::TYPE: $item = new Tombstone($root); break; @@ -174,6 +257,10 @@ class ImportService { $item = new Undo($root); break; + case Update::TYPE: + $item = new Update($root); + break; + default: throw new UnknownItemException(); } @@ -206,33 +293,18 @@ class ImportService { */ public function parseIncomingRequest(ACore $activity) { - if ($activity->gotObject()) { - try { - $this->parseIncomingRequest($activity->getObject()); - } catch (UnknownItemException $e) { - } - } + // not sure we need to recursive on activity/parsing. +// if ($activity->gotObject()) { +// try { +// $this->parseIncomingRequest($activity->getObject()); +// } catch (UnknownItemException $e) { +// } +// } - switch ($activity->getType()) { - - case Delete::TYPE: - $service = $this->deleteService; - break; - - case Follow::TYPE: - $service = $this->followService; - break; - - case Note::TYPE: - $service = $this->noteService; - break; - - default: - throw new UnknownItemException(); - } + $service = $this->getServiceForItem($activity); try { - $service->parse($activity); + $service->processIncomingRequest($activity, $this); } catch (Exception $e) { $this->miscService->log( 'Cannot parse ' . $activity->getType() . ': ' . $e->getMessage() @@ -244,13 +316,71 @@ class ImportService { /** * @param ACore $activity * - * @param string $id - * - * @throws InvalidResourceException + * @return ICoreService + * @throws UnknownItemException */ - public function verifyOrigin(ACore $activity, string $id) { - throw new InvalidResourceException(); + public function getServiceForItem(Acore $activity): ICoreService { + switch ($activity->getType()) { + + case Accept::TYPE: + $service = $this->acceptService; + break; + + case Add::TYPE: + $service = $this->addService; + break; + + case Block::TYPE: + $service = $this->blockService; + break; + + case Create::TYPE: + $service = $this->createService; + break; + + case Delete::TYPE: + $service = $this->deleteService; + break; + + case Follow::TYPE: + $service = $this->followService; + break; + + case Like::TYPE: + $service = $this->likeService; + break; + + case Note::TYPE: + $service = $this->noteService; + break; + + case Person::TYPE: + $service = $this->personService; + break; + + case Reject::TYPE: + $service = $this->rejectService; + break; + + case Remove::TYPE: + $service = $this->removeService; + break; + + case Undo::TYPE: + $service = $this->undoService; + break; + + case Update::TYPE: + $service = $this->updateService; + break; + + default: + throw new UnknownItemException(); + } + + return $service; } + } diff --git a/lib/Service/PostService.php b/lib/Service/PostService.php index 0ea482be..ca19e93e 100644 --- a/lib/Service/PostService.php +++ b/lib/Service/PostService.php @@ -36,7 +36,7 @@ use OCA\Social\Exceptions\ActorDoesNotExistException; use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Model\ActivityPub\ACore; use OCA\Social\Model\Post; -use OCA\Social\Service\ActivityPub\NoteService; +use OCA\Social\Service\ActivityPub\Object\NoteService; class PostService {