diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2019-06-21 10:58:10 -0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-21 10:58:10 -0100 |
commit | 20a4cb0b6f547fc85b3e05cd5a1de247d33ad918 (patch) | |
tree | 27deb5ff990ee5dd862db3469e7a2c04d1af15e3 /lib/Service/BoostService.php | |
parent | 74a2f80209733543c48035184c2321158a0e2da3 (diff) | |
parent | 177e0a03308bea4cb0cc2449423d4a50af15cb21 (diff) |
Merge pull request #586 from nextcloud/rewrite-announce
Better Announce
Diffstat (limited to 'lib/Service/BoostService.php')
-rw-r--r-- | lib/Service/BoostService.php | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/lib/Service/BoostService.php b/lib/Service/BoostService.php index bf705e4a..7019d6b6 100644 --- a/lib/Service/BoostService.php +++ b/lib/Service/BoostService.php @@ -34,6 +34,7 @@ use daita\MySmallPhpTools\Traits\TStringTools; use Exception; use OCA\Social\AP; use OCA\Social\Db\StreamRequest; +use OCA\Social\Exceptions\ItemUnknownException; use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Exceptions\StreamNotFoundException; use OCA\Social\Model\ActivityPub\ACore; @@ -114,14 +115,9 @@ class BoostService { * @throws Exception */ public function create(Person $actor, string $postId, &$token = ''): ACore { - - try { - return $this->get($actor, $postId); - } catch (StreamNotFoundException $e) { - } - + /** @var Announce $announce */ $announce = AP::$activityPub->getItemFromType(Announce::TYPE); - $this->noteService->assignItem($announce, $actor, Stream::TYPE_PUBLIC); + $this->noteService->assignItem($announce, $actor, Stream::TYPE_ANNOUNCE); $announce->setActor($actor); $note = $this->noteService->getNoteById($postId, true); @@ -129,7 +125,11 @@ class BoostService { throw new StreamNotFoundException('Stream is not a Note'); } - $announce->addCc($note->getAttributedTo()); + if (!$note->isPublic()) { + throw new StreamNotFoundException('Stream is not Public'); + } + + $announce->addCc($actor->getFollowers()); $announce->setObjectId($note->getId()); $announce->setRequestToken($this->uuid()); @@ -148,14 +148,15 @@ class BoostService { /** - * @param Person $actor * @param string $postId * * @return Stream + * @throws ItemUnknownException + * @throws SocialAppConfigException * @throws StreamNotFoundException */ - public function get(Person $actor, string $postId): Stream { - $stream = $this->streamRequest->getStreamByObjectId($actor, Announce::TYPE, $postId); + public function get(string $postId): Stream { + $stream = $this->streamRequest->getStreamByObjectId($postId, Announce::TYPE); return $stream; } @@ -167,8 +168,8 @@ class BoostService { * @param string $token * * @return ACore - * @throws StreamNotFoundException * @throws SocialAppConfigException + * @throws StreamNotFoundException */ public function delete(Person $actor, string $postId, &$token = ''): ACore { $undo = new Undo(); @@ -180,16 +181,24 @@ class BoostService { throw new StreamNotFoundException('Stream is not a Note'); } - $announce = $this->streamRequest->getStreamByObjectId($actor, Announce::TYPE, $postId); + try { + $announce = $this->streamRequest->getStreamByObjectId($postId, Announce::TYPE); + $announce->setActor($actor); - $undo->setObject($announce); - $undo->setCcArray($announce->getCcArray()); + $undo->setObjectId($announce->getId()); + $undo->addCc($actor->getFollowers()); - $this->streamRequest->deleteStreamById($announce->getId(), Announce::TYPE); - $this->streamActionService->setActionBool($actor->getId(), $postId, 'boosted', false); - $this->signatureService->signObject($actor, $undo); + $interface = AP::$activityPub->getInterfaceFromType(Announce::TYPE); + $interface->delete($announce); +// $this->streamRequest->deleteStreamById($announce->getId(), Announce::TYPE); + $this->signatureService->signObject($actor, $undo); - $token = $this->activityService->request($undo); + $token = $this->activityService->request($undo); + } catch (ItemUnknownException $e) { + } catch (StreamNotFoundException $e) { + } + + $this->streamActionService->setActionBool($actor->getId(), $postId, 'boosted', false); return $undo; } |