streamService = $streamService; $this->boostService = $boostService; $this->likeService = $likeService; $this->streamActionService = $streamActionService; } /** * should return null * will return Stream only with translate action * * @param int $nid * @param string $action * * @return Stream|null * @throws InvalidActionException */ public function action(Person $actor, int $nid, string $action): ?Stream { if (!in_array($action, self::$availableStatusAction)) { throw new InvalidActionException(); } $post = $this->streamService->getStreamByNid($nid); switch ($action) { case self::TRANSLATE: return $this->translate($nid); case self::FAVOURITE: $this->favourite($actor, $post->getId()); break; case self::UNFAVOURITE: $this->favourite($actor, $post->getId(), false); break; case self::REBLOG: $this->reblog($actor, $post->getId()); break; case self::UNREBLOG: $this->reblog($actor, $post->getId(), false); break; } return null; } /** * TODO: returns a translated version of the Status * * @param int $nid * * @return Stream * @throws StreamNotFoundException */ private function translate(int $nid): Stream { return $this->streamService->getStreamByNid($nid); } private function favourite(Person $actor, string $postId, bool $enabled = true): void { if ($enabled) { $this->likeService->create($actor, $postId); } else { $this->likeService->delete($actor, $postId); } } private function reblog(Person $actor, string $postId, bool $enabled = true): void { if ($enabled) { $this->boostService->create($actor, $postId); } else { $this->boostService->delete($actor, $postId); } } }