Skip to content

Commit

Permalink
Mark mention notifications as read, when the user pulls the chat mess…
Browse files Browse the repository at this point in the history
…ages of the room

Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Nov 20, 2017
1 parent bacf34c commit e615d17
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/Chat/ChatManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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
Expand Down
18 changes: 18 additions & 0 deletions lib/Chat/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e615d17

Please sign in to comment.