Instead of the offset based use lastKnownMessageId as for message

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2022-03-22 17:02:52 +01:00
Родитель 5035644bb9
Коммит acdbdb7838
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 7076EA9751AACDDA
4 изменённых файлов: 39 добавлений и 7 удалений

Просмотреть файл

@ -163,7 +163,7 @@ See [OCP\RichObjectStrings\Definitions](https://github.com/nextcloud/server/blob
field | type | Description
---|---|---
`offset` | int | Offset parameter to get another chunk of chat messages
`lastKnownMessageId` | int | Serves as an offset for the query. The lastKnownMessageId for the next page is available in the `X-Chat-Last-Given` header.
`limit` | int | Number of chat messages with shares you want to get
* Response:
@ -173,6 +173,12 @@ See [OCP\RichObjectStrings\Definitions](https://github.com/nextcloud/server/blob
+ `404 Not Found` When the conversation could not be found for the participant
+ `412 Precondition Failed` When the lobby is active and the user is not a moderator
- Header:
field | type | Description
---|---|---
`X-Chat-Last-Given` | int | Offset (lastKnownMessageId) for the next page.
- Data:
Array of messages as defined in [Receive chat messages of a conversation](#receive-chat-messages-of-a-conversation)

Просмотреть файл

@ -564,6 +564,25 @@ class ChatManager {
$this->notifier->removePendingNotificationsForRoom($chat);
}
/**
* Search for comments with a given content
*
* @param Room $chat
* @param int $offset
* @param int $limit
* @return IComment[]
*/
public function getSharedObjectMessages(Room $chat, int $offset, int $limit): array {
return $this->commentsManager->getCommentsWithVerbForObjectSinceComment(
'chat',
(string) $chat->getId(),
['object_shared'],
$offset,
'desc',
$limit
);
}
/**
* Search for comments with a given content
*

Просмотреть файл

@ -706,15 +706,15 @@ class ChatController extends AEnvironmentAwareController {
* @RequireReadWriteConversation
* @RequireModeratorOrNoLobby
*
* @param int $offset
* @param int $lastKnownMessageId
* @param int $limit
* @return DataResponse
*/
public function getObjectsSharedInRoom(int $offset = 0, int $limit = 50): DataResponse {
$offset = max(0, $offset);
public function getObjectsSharedInRoom(int $lastKnownMessageId = 0, int $limit = 100): DataResponse {
$offset = max(0, $lastKnownMessageId);
$limit = min(200, $limit);
$comments = $this->chatManager->searchForObjects('', [$this->room->getId()], 'object_shared', $offset, $limit);
$comments = $this->chatManager->getSharedObjectMessages($this->room, $offset, $limit);
$messages = [];
foreach ($comments as $comment) {
@ -728,7 +728,14 @@ class ChatController extends AEnvironmentAwareController {
$messages[] = $message->toArray();
}
return new DataResponse($messages);
$response = new DataResponse($messages, Http::STATUS_OK);
$newLastKnown = end($comments);
if ($newLastKnown instanceof IComment) {
$response->addHeader('X-Chat-Last-Given', $newLastKnown->getId());
}
return $response;
}
/**

Просмотреть файл

@ -1561,7 +1561,7 @@ class FeatureContext implements Context, SnippetAcceptingContext {
* @param string $statusCode
* @param string $apiVersion
*/
public function userSeesTheFollowingSharedMediaInRoom($user, $identifier, $statusCode, $apiVersion = 'v1', TableNode $formData = null) {
public function userSeesTheFollowingSharedMediaInRoom($user, $identifier, $statusCode, $apiVersion = 'v1', TableNode $formData = null): void {
$this->setCurrentUser($user);
$this->sendRequest('GET', '/apps/spreed/api/' . $apiVersion . '/chat/' . self::$identifierToToken[$identifier] . '/share');
$this->assertStatusCode($this->response, $statusCode);