diff --git a/lib/Controller/ChatController.php b/lib/Controller/ChatController.php index 393c3283806..c882b046fd9 100644 --- a/lib/Controller/ChatController.php +++ b/lib/Controller/ChatController.php @@ -423,7 +423,7 @@ public function receiveMessages(int $lookIntoFuture, $comments = $this->chatManager->getHistory($this->room, $lastKnownMessageId, $limit, (bool)$includeLastKnown); } - return $this->prepareCommentsAsDataResponse($comments); + return $this->prepareCommentsAsDataResponse($comments, $lastCommonReadId); } protected function prepareCommentsAsDataResponse(array $comments, int $lastCommonReadId = 0): DataResponse { diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index 9fbe3d87097..6db7b178456 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -70,6 +70,8 @@ class FeatureContext implements Context, SnippetAcceptingContext { protected static $botNameToId; /** @var array */ protected static $botNameToHash; + /** @var array|null */ + protected static ?array $nextChatRequestParameters = null; protected static $permissionsMap = [ @@ -2158,19 +2160,39 @@ public function userSendsReplyToRoom($user, $reply, $message, $identifier, $stat } } + /** + * @Then /^next message request has the following parameters set$/ + */ + public function setChatParametersForNextRequest(TableNode $formData = null): void { + $parameters = []; + foreach ($formData->getRowsHash() as $key => $value) { + if (in_array($key, ['lastCommonReadId', 'lastKnownMessageId'], true)) { + $parameters[$key] = self::$textToMessageId[$value]; + } else { + $parameters[$key] = $value; + } + } + self::$nextChatRequestParameters = $parameters; + } + /** * @Then /^user "([^"]*)" sees the following messages in room "([^"]*)" with (\d+)(?: \((v1)\))?$/ - * - * @param string $user - * @param string $identifier - * @param string $statusCode - * @param string $apiVersion */ - public function userSeesTheFollowingMessagesInRoom($user, $identifier, $statusCode, $apiVersion = 'v1', TableNode $formData = null) { + public function userSeesTheFollowingMessagesInRoom(string $user, string $identifier, int $statusCode, string $apiVersion = 'v1', TableNode $formData = null) { + $query = ['lookIntoFuture' => 0]; + if (self::$nextChatRequestParameters !== null) { + $query = array_merge($query, self::$nextChatRequestParameters); + self::$nextChatRequestParameters = null; + } + $this->setCurrentUser($user); - $this->sendRequest('GET', '/apps/spreed/api/' . $apiVersion . '/chat/' . self::$identifierToToken[$identifier] . '?lookIntoFuture=0'); + $this->sendRequest('GET', '/apps/spreed/api/' . $apiVersion . '/chat/' . self::$identifierToToken[$identifier] . '?' . http_build_query($query)); $this->assertStatusCode($this->response, $statusCode); + if ($statusCode === 304) { + return; + } + $this->compareDataResponse($formData); } diff --git a/tests/integration/features/chat-2/read-status.feature b/tests/integration/features/chat-2/read-status.feature index a1d8346e785..a909b397d99 100644 --- a/tests/integration/features/chat-2/read-status.feature +++ b/tests/integration/features/chat-2/read-status.feature @@ -54,6 +54,30 @@ Feature: chat-2/read-status When user "participant2" reads message "Message 3" in room "chatting" with 200 Then last response has last common read message header set to "Message 3" + When next message request has the following parameters set + | lastCommonReadId | Message 1 | + | lastKnownMessageId | Message 1 | + | timeout | 0 | + | lookIntoFuture | 1 | + Then user "participant1" sees the following messages in room "chatting" with 200 + | room | actorType | actorId | actorDisplayName | message | messageParameters | + | chatting | users | participant2 | participant2-displayname | Message 2 | [] | + | chatting | users | participant2 | participant2-displayname | Message 3 | [] | + Then last response has last common read message header set to "Message 3" + When next message request has the following parameters set + | lastCommonReadId | Message 1 | + | lastKnownMessageId | Message 3 | + | timeout | 0 | + | lookIntoFuture | 1 | + Then user "participant1" sees the following messages in room "chatting" with 200 + Then last response has last common read message header set to "Message 3" + When next message request has the following parameters set + | lastCommonReadId | Message 3 | + | lastKnownMessageId | Message 3 | + | timeout | 0 | + | lookIntoFuture | 1 | + Then user "participant1" sees the following messages in room "chatting" with 304 + Scenario: User switching to private is not considered anymore Given user "participant1" creates room "chatting" (v4)