diff options
author | Joas Schilling <coding@schilljs.com> | 2022-05-31 15:32:06 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2022-06-13 12:52:59 +0200 |
commit | d3bad8f60474712d58e012480883b31806139754 (patch) | |
tree | b9011d1b5f1778a703bac051b1448482d22dd338 /lib/Controller/PollController.php | |
parent | e850664c9aa5532e948ae3399a2a26effde0e09d (diff) |
Hide summary also until the actor voted
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Controller/PollController.php')
-rw-r--r-- | lib/Controller/PollController.php | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/Controller/PollController.php b/lib/Controller/PollController.php index 759a92aa7..07f8fa893 100644 --- a/lib/Controller/PollController.php +++ b/lib/Controller/PollController.php @@ -117,10 +117,9 @@ class PollController extends AEnvironmentAwareController { * @RequireModeratorOrNoLobby * * @param int $pollId - * @param bool $details * @return DataResponse */ - public function showPoll(int $pollId, bool $details = false): DataResponse { + public function showPoll(int $pollId): DataResponse { try { $poll = $this->pollService->getPoll($this->room->getId(), $pollId); } catch (DoesNotExistException $e) { @@ -129,7 +128,7 @@ class PollController extends AEnvironmentAwareController { $votedSelf = $this->pollService->getVotesForActor($this->participant, $poll); $detailedVotes = []; - if ($details && ($poll->getResultMode() === Poll::MODE_PUBLIC || $poll->getStatus() === Poll::STATUS_CLOSED)) { + if ($poll->getResultMode() === Poll::MODE_PUBLIC && $poll->getStatus() === Poll::STATUS_CLOSED) { $detailedVotes = $this->pollService->getVotes($poll); } @@ -187,19 +186,26 @@ class PollController extends AEnvironmentAwareController { return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); } + $detailedVotes = []; + if ($poll->getResultMode() === Poll::MODE_PUBLIC) { + $detailedVotes = $this->pollService->getVotes($poll); + } + $votedSelf = $this->pollService->getVotesForActor($this->participant, $poll); - return new DataResponse($this->renderPoll($poll, $votedSelf)); + return new DataResponse($this->renderPoll($poll, $votedSelf, $detailedVotes)); } protected function renderPoll(Poll $poll, array $votedSelf = [], array $detailedVotes = []): array { $data = $poll->asArray(); unset($data['roomId']); - if ($poll->getResultMode() === Poll::MODE_HIDDEN && $poll->getStatus() === Poll::STATUS_OPEN) { + $canSeeSummary = !empty($votedSelf) && $poll->getResultMode() === Poll::MODE_PUBLIC; + + if (!$canSeeSummary && $poll->getStatus() === Poll::STATUS_OPEN) { $data['votes'] = []; $data['numVoters'] = 0; - } elseif (!empty($detailedVotes)) { + } elseif ($poll->getResultMode() === Poll::MODE_PUBLIC && $poll->getStatus() === Poll::STATUS_CLOSED) { $data['details'] = array_map(static fn (Vote $vote) => $vote->asArray(), $detailedVotes); } |