Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable26] fix(chat): Fix responding with "X-Chat-Last-Common-Read" when request… #10340

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Controller/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,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 {
Expand Down
37 changes: 29 additions & 8 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class FeatureContext implements Context, SnippetAcceptingContext {
protected static $inviteIdToRemote;
/** @var int[] */
protected static $questionToPollId;

/** @var array<string, mixed>|null */
protected static ?array $nextChatRequestParameters = null;

protected static $permissionsMap = [
'D' => 0, // PERMISSIONS_DEFAULT
Expand Down Expand Up @@ -2061,19 +2062,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);
}

Expand Down
24 changes: 24 additions & 0 deletions tests/integration/features/chat-2/read-status.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down