Skip to content

Commit

Permalink
[BUGFIX]
Browse files Browse the repository at this point in the history
  • Loading branch information
tonypro committed Jun 10, 2020
1 parent 9bde33f commit e08362a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
30 changes: 29 additions & 1 deletion Classes/Controller/MessageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,6 +26,11 @@ class MessageController extends ActionController
*/
protected $frontendUserRepository = null;

/**
* @var PersistenceManager
*/
protected $persistenceManager = null;

/**
* Loggen in user ID
*
Expand All @@ -48,6 +54,14 @@ public function injectFrontendUserRepository(FrontendUserRepository $frontendUse
$this->frontendUserRepository = $frontendUserRepository;
}

/**
* @param PersistenceManager $persistenceManager
*/
public function injectPersistenceManager(PersistenceManager $persistenceManager)
{
$this->persistenceManager = $persistenceManager;
}

/**
* Init
*/
Expand Down Expand Up @@ -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);
}

Expand All @@ -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]);
}
Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Templates/Message/List.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<f:section name="content">
<f:if condition="{messages}">
<f:for each="{messages}" as="message">
<div class="message-box {f:if(condition: '{message.priority} == 0', then: 'message-box__important')} {f:if(condition: '{message.priority} == 1', then: 'message-box__notice')}">
<div class="message-box <f:if condition='{seen.{message.uid}}'>message-box__collapsed</f:if> {f:if(condition: '{message.priority} == 0', then: 'message-box__important')} {f:if(condition: '{message.priority} == 1', then: 'message-box__notice')}">
<f:link.action action="close"
pageType="2378954"
data="{close-message: '1'}"
Expand Down

0 comments on commit e08362a

Please sign in to comment.