From e08362a6a0f154b085ae27b5b988529fe2ab3aa0 Mon Sep 17 00:00:00 2001 From: Tony Prokopenko Date: Wed, 10 Jun 2020 17:59:23 +0300 Subject: [PATCH] [BUGFIX] --- Classes/Controller/MessageController.php | 30 ++++++++++++++++++- Resources/Private/Templates/Message/List.html | 2 +- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Classes/Controller/MessageController.php b/Classes/Controller/MessageController.php index a12f203..404fbf3 100644 --- a/Classes/Controller/MessageController.php +++ b/Classes/Controller/MessageController.php @@ -9,6 +9,7 @@ use TYPO3\CMS\Extbase\Domain\Model\FrontendUser; use TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; +use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager; /** * MessageController @@ -25,6 +26,11 @@ class MessageController extends ActionController */ protected $frontendUserRepository = null; + /** + * @var PersistenceManager + */ + protected $persistenceManager = null; + /** * Loggen in user ID * @@ -48,6 +54,14 @@ public function injectFrontendUserRepository(FrontendUserRepository $frontendUse $this->frontendUserRepository = $frontendUserRepository; } + /** + * @param PersistenceManager $persistenceManager + */ + public function injectPersistenceManager(PersistenceManager $persistenceManager) + { + $this->persistenceManager = $persistenceManager; + } + /** * Init */ @@ -75,7 +89,15 @@ public function listAction() if ($this->settings['invertSorting']) { $messages = array_reverse($messages->toArray()); } + /** @var FrontendUser $frontendUser */ + $frontendUser = $this->frontendUserRepository->findByUid($this->userId); + $seen = []; + foreach ($messages as $message) { + /** @var Message $message */ + $seen[$message->getUid()] = ($message->getSeenBy()->contains($frontendUser)) ? true : false; + } + $this->view->assign('seen', $seen); $this->view->assign('messages', $messages); } @@ -94,9 +116,15 @@ public function closeAction(Message $message) /** @var FrontendUser $frontendUser */ $frontendUser = $this->frontendUserRepository->findByUid($this->userId); - $message->addSeenBy($frontendUser); + if ($message->getSeenBy()->contains($frontendUser)) { + $message->removeSeenBy($frontendUser); + } else { + $message->addSeenBy($frontendUser); + } $this->messageRepository->update($message); + $this->persistenceManager->persistAll(); + if (GeneralUtility::_GET('type')) { return json_encode(['success' => true]); } diff --git a/Resources/Private/Templates/Message/List.html b/Resources/Private/Templates/Message/List.html index 759f75c..dba4026 100644 --- a/Resources/Private/Templates/Message/List.html +++ b/Resources/Private/Templates/Message/List.html @@ -4,7 +4,7 @@ -
+