diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2019-03-05 14:11:16 -0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-05 14:11:16 -0100 |
commit | a6ad99eed17b0318af731e8452a3eda092a676e6 (patch) | |
tree | 3acffb5d7e751c068b8f6989ddc32fa7910e6abc /lib | |
parent | ee81f3717cc03f5aa80dea13d075e7eea3898059 (diff) | |
parent | 88f7a56aadd5e769c6714fb28cd9cd1907f84c61 (diff) |
Merge branch 'master' into feature/noid/attachments
Diffstat (limited to 'lib')
64 files changed, 4541 insertions, 579 deletions
@@ -40,7 +40,7 @@ use OCA\Social\Interfaces\Activity\AddInterface; use OCA\Social\Interfaces\Activity\BlockInterface; use OCA\Social\Interfaces\Activity\CreateInterface; use OCA\Social\Interfaces\Activity\DeleteInterface; -use OCA\Social\Interfaces\Activity\FollowInterface; +use OCA\Social\Interfaces\Object\FollowInterface; use OCA\Social\Interfaces\Activity\LikeInterface; use OCA\Social\Interfaces\Activity\RejectInterface; use OCA\Social\Interfaces\Activity\RemoveInterface; @@ -50,6 +50,7 @@ use OCA\Social\Interfaces\Actor\PersonInterface; use OCA\Social\Interfaces\IActivityPubInterface; use OCA\Social\Interfaces\Object\DocumentInterface; use OCA\Social\Interfaces\Object\ImageInterface; +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; @@ -57,13 +58,14 @@ 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\Object\Follow; use OCA\Social\Model\ActivityPub\Activity\Like; use OCA\Social\Model\ActivityPub\Activity\Reject; 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; @@ -92,6 +94,9 @@ class AP { /** @var AddInterface */ public $addInterface; + /** @var AnnounceInterface */ + public $announceInterface; + /** @var BlockInterface */ public $blockInterface; @@ -154,6 +159,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); @@ -196,13 +202,35 @@ class AP { $item->setParent($parent); } + $this->getObjectFromData($data, $item, $level); + + return $item; + } + + + /** + * @param array $data + * @param ACore $item + * @param int $level + * + * @throws RedundancyLimitException + * @throws SocialAppConfigException + */ + public function getObjectFromData(array $data, ACore &$item, int $level) { try { - $object = $this->getItemFromData($this->getArray('object', $data, []), $item, $level); - $item->setObject($object); + $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) { } - - return $item; } @@ -239,6 +267,10 @@ class AP { $item = new Add(); break; + case Announce::TYPE: + $item = new Announce(); + break; + case Block::TYPE: $item = new Block(); break; @@ -332,6 +364,10 @@ class AP { $interface = $this->addInterface; break; + case Announce::TYPE: + $service = $this->announceInterface; + break; + case Block::TYPE: $interface = $this->blockInterface; break; diff --git a/lib/Command/CacheRefresh.php b/lib/Command/CacheRefresh.php index c90355a3..71165df2 100644 --- a/lib/Command/CacheRefresh.php +++ b/lib/Command/CacheRefresh.php @@ -37,6 +37,7 @@ use OCA\Social\Service\AccountService; use OCA\Social\Service\CacheActorService; use OCA\Social\Service\ConfigService; use OCA\Social\Service\DocumentService; +use OCA\Social\Service\HashtagService; use OCA\Social\Service\MiscService; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -46,7 +47,7 @@ class CacheRefresh extends Base { /** @var AccountService */ - private $actorService; + private $accountService; /** @var CacheActorService */ private $cacheActorService; @@ -54,6 +55,9 @@ class CacheRefresh extends Base { /** @var DocumentService */ private $documentService; + /** @var HashtagService */ + private $hashtagService; + /** @var ConfigService */ private $configService; @@ -64,21 +68,24 @@ class CacheRefresh extends Base { /** * CacheUpdate constructor. * - * @param AccountService $actorService + * @param AccountService $accountService * @param CacheActorService $cacheActorService * @param DocumentService $documentService + * @param HashtagService $hashtagService * @param ConfigService $configService * @param MiscService $miscService */ public function __construct( - AccountService $actorService, CacheActorService $cacheActorService, - DocumentService $documentService, ConfigService $configService, MiscService $miscService + AccountService $accountService, CacheActorService $cacheActorService, + DocumentService $documentService, HashtagService $hashtagService, + ConfigService $configService, MiscService $miscService ) { parent::__construct(); - $this->actorService = $actorService; + $this->accountService = $accountService; $this->cacheActorService = $cacheActorService; $this->documentService = $documentService; + $this->hashtagService = $hashtagService; $this->configService = $configService; $this->miscService = $miscService; } @@ -102,10 +109,10 @@ class CacheRefresh extends Base { */ protected function execute(InputInterface $input, OutputInterface $output) { - $result = $this->actorService->blindKeyRotation(); + $result = $this->accountService->blindKeyRotation(); $output->writeLn($result . ' key pairs refreshed'); - $result = $this->actorService->manageCacheLocalActors(); + $result = $this->accountService->manageCacheLocalActors(); $output->writeLn($result . ' local accounts regenerated'); $result = $this->cacheActorService->missingCacheRemoteActors(); @@ -116,6 +123,9 @@ class CacheRefresh extends Base { $result = $this->documentService->manageCacheDocuments(); $output->writeLn($result . ' documents cached'); + + $result = $this->hashtagService->manageHashtags(); + $output->writeLn($result . ' hashtags updated'); } diff --git a/lib/Command/NoteBoost.php b/lib/Command/NoteBoost.php new file mode 100644 index 00000000..477d806b --- /dev/null +++ b/lib/Command/NoteBoost.php @@ -0,0 +1,136 @@ +<?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\Command; + +use Exception; +use OC\Core\Command\Base; +use OCA\Social\Model\ActivityPub\ACore; +use OCA\Social\Model\ActivityPub\Object\Announce; +use OCA\Social\Model\ActivityPub\Stream; +use OCA\Social\Model\Post; +use OCA\Social\Service\AccountService; +use OCA\Social\Service\ActivityService; +use OCA\Social\Service\ConfigService; +use OCA\Social\Service\CurlService; +use OCA\Social\Service\MiscService; +use OCA\Social\Service\NoteService; +use OCA\Social\Service\PostService; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\OutputInterface; + + +class NoteBoost extends Base { + + + /** @var ConfigService */ + private $configService; + + /** @var ActivityService */ + private $activityService; + + /** @var NoteService */ + private $noteService; + + /** @var AccountService */ + private $accountService; + + /** @var PostService */ + private $postService; + + /** @var CurlService */ + private $curlService; + + /** @var MiscService */ + private $miscService; + + + /** + * NoteCreate constructor. + * + * @param ActivityService $activityService + * @param AccountService $accountService + * @param NoteService $noteService + * @param PostService $postService + * @param CurlService $curlService + * @param ConfigService $configService + * @param MiscService $miscService + */ + public function __construct( + ActivityService $activityService, AccountService $accountService, + NoteService $noteService, PostService $postService, CurlService $curlService, + ConfigService $configService, MiscService $miscService + ) { + parent::__construct(); + + $this->activityService = $activityService; + $this->noteService = $noteService; + $this->accountService = $accountService; + $this->postService = $postService; + $this->curlService = $curlService; + $this->configService = $configService; + $this->miscService = $miscService; + } + + + /** + * + */ + protected function configure() { + parent::configure(); + $this->setName('social:note:boost') + ->addArgument('userid', InputArgument::REQUIRED, 'userId of the author') + ->addArgument('note', InputArgument::REQUIRED, 'Note to boost') + ->setDescription('Boost a note'); + } + + + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @throws Exception + */ + protected function execute(InputInterface $input, OutputInterface $output) { + $userId = $input->getArgument('userid'); + $noteId = $input->getArgument('note'); + + $actor = $this->accountService->getActorFromUserId($userId); + $this->noteService->setViewer($actor); + $token = $this->noteService->createBoost($actor, $noteId, $activity); + + echo 'object: ' . json_encode($activity, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n"; + echo 'token: ' . $token . "\n"; + } + +} + diff --git a/lib/Command/NoteCreate.php b/lib/Command/NoteCreate.php index 14216ea8..99c3d18c 100644 --- a/lib/Command/NoteCreate.php +++ b/lib/Command/NoteCreate.php @@ -47,6 +47,7 @@ use Symfony\Component\Console\Output\OutputInterface; class NoteCreate extends Base { + /** @var ConfigService */ private $configService; @@ -54,7 +55,7 @@ class NoteCreate extends Base { private $activityService; /** @var AccountService */ - private $actorService; + private $accountService; /** @var PostService */ private $postService; @@ -70,21 +71,21 @@ class NoteCreate extends Base { * NoteCreate constructor. * * @param ActivityService $activityService - * @param AccountService $actorService + * @param AccountService $accountService * @param PostService $postService * @param CurlService $curlService * @param ConfigService $configService * @param MiscService $miscService */ public function __construct( - ActivityService $activityService, AccountService $actorService, + ActivityService $activityService, AccountService $accountService, PostService $postService, CurlService $curlService, ConfigService $configService, MiscService $miscService ) { parent::__construct(); $this->activityService = $activityService; - $this->actorService = $actorService; + $this->accountService = $accountService; $this->postService = $postService; $this->curlService = $curlService; $this->configService = $configService; @@ -108,6 +109,10 @@ class NoteCreate extends Base { 'type', 'y', InputOption::VALUE_OPTIONAL, 'type: public (default), followers, unlisted, direct' ) + ->addOption( + 'hashtag', 'g', InputOption::VALUE_OPTIONAL, + 'hashtag, without the leading #' + ) ->addArgument('userid', InputArgument::REQUIRED, 'userId of the author') ->addArgument('content', InputArgument::REQUIRED, 'content of the post') ->setDescription('Create a new note'); @@ -125,14 +130,17 @@ class NoteCreate extends Base { $userId = $input->getArgument('userid'); $content = $input->getArgument('content'); $to = $input->getOption('to'); + $hashtag = $input->getOption('hashtag'); $replyTo = $input->getOption('replyTo'); $type = $input->getOption('type'); - $post = new Post($userId); + $actor = $this->accountService->getActorFromUserId($userId); + $post = new Post($actor); $post->setContent($content); $post->setType(($type === null) ? '' : $type); $post->setReplyTo(($replyTo === null) ? '' : $replyTo); $post->addTo(($to === null) ? '' : $to); + $post->setHashtags(($hashtag === null) ? [] : [$hashtag]); $token = $this->postService->createPost($post, $activity); diff --git a/lib/Command/QueueProcess.php b/lib/Command/QueueProcess.php index 20ea8f14..69006183 100644 --- a/lib/Command/QueueProcess.php +++ b/lib/Command/QueueProcess.php @@ -36,7 +36,8 @@ use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Service\ActivityService; use OCA\Social\Service\ConfigService; use OCA\Social\Service\MiscService; -use OCA\Social\Service\QueueService; +use OCA\Social\Service\RequestQueueService; +use OCA\Social\Service\StreamQueueService; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -47,8 +48,11 @@ class QueueProcess extends Base { /** @var ActivityService */ |