summaryrefslogtreecommitdiffstats
path: root/lib/Controller/PollController.php
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2022-06-03 09:43:45 +0200
committerJoas Schilling <coding@schilljs.com>2022-06-13 12:52:59 +0200
commitc9919b86bf306f13c8f2e55cb002f7e1704dec40 (patch)
treef13b613eac96668abd3b38a92d82b949d5396f3a /lib/Controller/PollController.php
parentd3bad8f60474712d58e012480883b31806139754 (diff)
Add system messages for voting and closing
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Controller/PollController.php')
-rw-r--r--lib/Controller/PollController.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/Controller/PollController.php b/lib/Controller/PollController.php
index 07f8fa893..9ed4c305f 100644
--- a/lib/Controller/PollController.php
+++ b/lib/Controller/PollController.php
@@ -30,6 +30,7 @@ use OCA\Talk\Chat\ChatManager;
use OCA\Talk\Exceptions\WrongPermissionsException;
use OCA\Talk\Model\Poll;
use OCA\Talk\Model\Vote;
+use OCA\Talk\Service\AttachmentService;
use OCA\Talk\Service\PollService;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http;
@@ -42,6 +43,7 @@ use Psr\Log\LoggerInterface;
class PollController extends AEnvironmentAwareController {
protected ChatManager $chatManager;
protected PollService $pollService;
+ protected AttachmentService $attachmentService;
protected ITimeFactory $timeFactory;
protected LoggerInterface $logger;
@@ -49,10 +51,12 @@ class PollController extends AEnvironmentAwareController {
IRequest $request,
ChatManager $chatManager,
PollService $pollService,
+ AttachmentService $attachmentService,
ITimeFactory $timeFactory,
LoggerInterface $logger) {
parent::__construct($appName, $request);
$this->pollService = $pollService;
+ $this->attachmentService = $attachmentService;
$this->chatManager = $chatManager;
$this->timeFactory = $timeFactory;
$this->logger = $logger;
@@ -157,6 +161,25 @@ class PollController extends AEnvironmentAwareController {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
+ if ($poll->getResultMode() === Poll::MODE_PUBLIC) {
+ $attendee = $this->participant->getAttendee();
+ try {
+ $message = json_encode([
+ 'message' => 'poll_voted',
+ 'parameters' => [
+ 'poll' => [
+ 'type' => 'talk-poll',
+ 'id' => $poll->getId(),
+ 'name' => $poll->getQuestion(),
+ ],
+ ],
+ ], JSON_THROW_ON_ERROR);
+ $this->chatManager->addSystemMessage($this->room, $attendee->getActorType(), $attendee->getActorId(), $message, $this->timeFactory->getDateTime(), true);
+ } catch (\Exception $e) {
+ $this->logger->error($e->getMessage(), ['exception' => $e]);
+ }
+ }
+
return new DataResponse($this->renderPoll($poll, $votedSelf));
}
@@ -186,6 +209,23 @@ class PollController extends AEnvironmentAwareController {
return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
}
+ $attendee = $this->participant->getAttendee();
+ try {
+ $message = json_encode([
+ 'message' => 'poll_closed',
+ 'parameters' => [
+ 'poll' => [
+ 'type' => 'talk-poll',
+ 'id' => $poll->getId(),
+ 'name' => $poll->getQuestion(),
+ ],
+ ],
+ ], JSON_THROW_ON_ERROR);
+ $this->chatManager->addSystemMessage($this->room, $attendee->getActorType(), $attendee->getActorId(), $message, $this->timeFactory->getDateTime(), true);
+ } catch (\Exception $e) {
+ $this->logger->error($e->getMessage(), ['exception' => $e]);
+ }
+
$detailedVotes = [];
if ($poll->getResultMode() === Poll::MODE_PUBLIC) {
$detailedVotes = $this->pollService->getVotes($poll);