Skip to content

Commit

Permalink
fix(chat): Mark notifications read when setting the readmarker to the…
Browse files Browse the repository at this point in the history
… end

Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Mar 19, 2024
1 parent ba4ff4f commit 5f8c5e8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/Controller/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OCA\Talk\Chat\AutoComplete\Sorter;
use OCA\Talk\Chat\ChatManager;
use OCA\Talk\Chat\MessageParser;
use OCA\Talk\Chat\Notifier;
use OCA\Talk\Chat\ReactionManager;
use OCA\Talk\Exceptions\CannotReachRemoteException;
use OCA\Talk\Federation\Authenticator;
Expand Down Expand Up @@ -130,6 +131,7 @@ public function __construct(
private IL10N $l,
protected Authenticator $federationAuthenticator,
protected ProxyCacheMessageService $pcmService,
protected Notifier $notifier,
) {
parent::__construct($appName, $request);
}
Expand Down Expand Up @@ -1086,14 +1088,19 @@ public function clearHistory(): DataResponse {
#[PublicPage]
#[RequireAuthenticatedParticipant]
public function setReadMarker(?int $lastReadMessage = null): DataResponse {
$setToMessage = $lastReadMessage ?? $this->room->getLastMessageId();
if ($setToMessage === $this->room->getLastMessageId()
&& $this->participant->getAttendee()->getActorType() === Attendee::ACTOR_USERS) {
$this->notifier->markMentionNotificationsRead($this->room, $this->participant->getAttendee()->getActorId());
}

if ($this->room->isFederatedConversation()) {
/** @var \OCA\Talk\Federation\Proxy\TalkV1\Controller\ChatController $proxy */
$proxy = \OCP\Server::get(\OCA\Talk\Federation\Proxy\TalkV1\Controller\ChatController::class);
return $proxy->setReadMarker($this->room, $this->participant, $this->getResponseFormat(), $lastReadMessage);
}

$lastReadMessage = $lastReadMessage ?? $this->room->getLastMessageId();
$this->participantService->updateLastReadMessage($this->participant, $lastReadMessage);
$this->participantService->updateLastReadMessage($this->participant, $setToMessage);
$attendee = $this->participant->getAttendee();

$headers = $lastCommonRead = [];
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/features/federation/chat.feature
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,13 @@ Feature: federation/chat
Given user "participant2" leaves room "LOCAL::room" with 200 (v4)
And user "guest" joins room "room" with 200 (v4)
When user "guest" sends message 'Hi @"federated_user/participant2@{$REMOTE_URL}" bye' to room "room" with 201
When user "guest" sends message "Message 2" to room "room" with 201
Then user "participant2" has the following notifications
| app | object_type | object_id | subject | message |
| spreed | chat | room/Hi @"federated_user/participant2@{$REMOTE_URL}" bye | A guest mentioned you in conversation room | Hi @participant2-displayname bye |
Then user "participant2" reads message "Message 2" in room "LOCAL::room" with 200 (v1)
Then user "participant2" has the following notifications
| app | object_type | object_id | subject | message |

Scenario: Mentioning a federated user as a federated user that is a local user to the mentioned one also triggers a notification for them
Given the following "spreed" app config is set
Expand Down
4 changes: 4 additions & 0 deletions tests/php/Controller/ChatControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use OCA\Talk\Chat\AutoComplete\SearchPlugin;
use OCA\Talk\Chat\ChatManager;
use OCA\Talk\Chat\MessageParser;
use OCA\Talk\Chat\Notifier;
use OCA\Talk\Chat\ReactionManager;
use OCA\Talk\Controller\ChatController;
use OCA\Talk\Federation\Authenticator;
Expand Down Expand Up @@ -117,6 +118,7 @@ class ChatControllerTest extends TestCase {
private $l;
private Authenticator|MockObject $federationAuthenticator;
private ProxyCacheMessageService|MockObject $pcmService;
private Notifier|MockObject $notifier;

/** @var Room|MockObject */
protected $room;
Expand Down Expand Up @@ -157,6 +159,7 @@ public function setUp(): void {
$this->l = $this->createMock(IL10N::class);
$this->federationAuthenticator = $this->createMock(Authenticator::class);
$this->pcmService = $this->createMock(ProxyCacheMessageService::class);
$this->notifier = $this->createMock(Notifier::class);

$this->room = $this->createMock(Room::class);

Expand Down Expand Up @@ -202,6 +205,7 @@ private function recreateChatController() {
$this->l,
$this->federationAuthenticator,
$this->pcmService,
$this->notifier,
);
}

Expand Down

0 comments on commit 5f8c5e8

Please sign in to comment.