diff --git a/lib/Chat/ChatManager.php b/lib/Chat/ChatManager.php index 81aa0f468bfe..9938f00f0b52 100644 --- a/lib/Chat/ChatManager.php +++ b/lib/Chat/ChatManager.php @@ -90,6 +90,7 @@ public function sendMessage($chatId, $actorType, $actorId, $message, \DateTime $ * maximum time to wait must be set using the $timeout parameter. * * @param string $chatId + * @param string $userId * @param int $timeout the maximum number of seconds to wait for messages * @param int $offset optional, starting point * @param \DateTime|null $notOlderThan optional, the date and time of the @@ -98,7 +99,7 @@ public function sendMessage($chatId, $actorType, $actorId, $message, \DateTime $ * creation date and message are relevant), or an empty array if the * timeout expired. */ - public function receiveMessages($chatId, $timeout, $offset = 0, \DateTime $notOlderThan = null) { + public function receiveMessages($chatId, $userId, $timeout, $offset = 0, \DateTime $notOlderThan = null) { $comments = []; $commentsFound = false; @@ -114,6 +115,8 @@ public function receiveMessages($chatId, $timeout, $offset = 0, \DateTime $notOl } } + $this->notifier->markMentionNotificationsRead($chatId, $userId); + if ($commentsFound) { // The limit and offset of getForObject can not be based on the // number of comments, as more comments may have been added between diff --git a/lib/Chat/Notifier.php b/lib/Chat/Notifier.php index 273d01922eeb..2471db3f5378 100644 --- a/lib/Chat/Notifier.php +++ b/lib/Chat/Notifier.php @@ -104,6 +104,24 @@ public function removePendingNotificationsForRoom($roomId) { $this->notificationManager->markProcessed($notification); } + /** + * Removes all the pending mention notifications for the room + * + * @param string $roomId + * @param string $userId + */ + public function markMentionNotificationsRead($roomId, $userId) { + $notification = $this->notificationManager->createNotification(); + + $notification + ->setApp('spreed') + ->setObject('room', $roomId) + ->setSubject('mention') + ->setUser($userId); + + $this->notificationManager->markProcessed($notification); + } + /** * Returns the IDs of the users mentioned in the given comment. * diff --git a/lib/Controller/ChatController.php b/lib/Controller/ChatController.php index b9073c07e158..fee134b0c906 100644 --- a/lib/Controller/ChatController.php +++ b/lib/Controller/ChatController.php @@ -206,7 +206,7 @@ public function receiveMessages($token, $offset = 0, $notOlderThanTimestamp = 0, $timeout = $maximumTimeout; } - $comments = $this->chatManager->receiveMessages((string) $room->getId(), $timeout, $offset, $notOlderThan); + $comments = $this->chatManager->receiveMessages((string) $room->getId(), $this->userId, $timeout, $offset, $notOlderThan); return new DataResponse(array_map(function(IComment $comment) use ($token) { $displayName = null;