Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions lib/Controller/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ public function shareObjectToChat(string $objectType, string $objectId, string $
* for the follow-up query.
*
* @param 0|1 $lookIntoFuture Polling for new messages (1) or getting the history of the chat (0)
* @param int $limit Number of chat messages to receive (100 by default, 200 at most)
* @param int<1, 200> $limit Number of chat messages to receive (100 by default, 200 at most)
* @param int $lastKnownMessageId The last known message (serves as offset)
* @psalm-param non-negative-int $lastKnownMessageId
* @param int $lastCommonReadId The last known common read message
Expand Down Expand Up @@ -401,7 +401,7 @@ public function receiveMessages(int $lookIntoFuture,
int $includeLastKnown = 0,
int $noStatusUpdate = 0,
int $markNotificationsAsRead = 1): DataResponse {
$limit = min(200, $limit);
$limit = min(200, max(1, $limit));
$timeout = min(30, $timeout);

if ($this->room->isFederatedConversation()) {
Expand Down Expand Up @@ -739,7 +739,7 @@ protected function prepareCommentsAsDataResponse(array $comments, int $lastCommo
*
* @param int $messageId The focused message which should be in the "middle" of the returned context
* @psalm-param non-negative-int $messageId
* @param int<1, 100> $limit Number of chat messages to receive in both directions (50 by default, 100 at most, might return 201 messages)
* @param int<0, 100> $limit Number of chat messages to receive in both directions (50 by default, 100 at most, might return 201 messages)
* @return DataResponse<Http::STATUS_OK, list<TalkChatMessageWithParent>, array{'X-Chat-Last-Common-Read'?: numeric-string, X-Chat-Last-Given?: numeric-string}>|DataResponse<Http::STATUS_NOT_MODIFIED, null, array{}>
*
* 200: Message context returned
Expand All @@ -752,7 +752,7 @@ protected function prepareCommentsAsDataResponse(array $comments, int $lastCommo
public function getMessageContext(
int $messageId,
int $limit = 50): DataResponse {
$limit = min(100, $limit);
$limit = min(100, max(0, $limit));

if ($this->room->isFederatedConversation()) {
/** @var \OCA\Talk\Federation\Proxy\TalkV1\Controller\ChatController $proxy */
Expand All @@ -765,9 +765,16 @@ public function getMessageContext(
// Guest in a fully expired chat, no history, just loading the chat from beginning for now
$commentsHistory = $commentsFuture = [];
} else {
$commentsHistory = $this->chatManager->getHistory($this->room, $messageId, $limit, true);
// Load at least 1 history entry to get the includeLastKnown
$historyLimit = max(1, $limit);
$commentsHistory = $this->chatManager->getHistory($this->room, $messageId, $historyLimit, true);
$commentsHistory = array_reverse($commentsHistory);
$commentsFuture = $this->chatManager->waitForNewMessages($this->room, $messageId, $limit, 0, $currentUser, false);
if ($limit === 0) {
// No context requested, only the known message
$commentsFuture = [];
} else {
$commentsFuture = $this->chatManager->waitForNewMessages($this->room, $messageId, $limit, 0, $currentUser, false);
}
}

return $this->prepareCommentsAsDataResponse(array_merge($commentsHistory, $commentsFuture));
Expand Down Expand Up @@ -1404,7 +1411,7 @@ public function markUnread(): DataResponse {
#[RequireModeratorOrNoLobby]
#[RequireParticipant]
public function getObjectsSharedInRoomOverview(int $limit = 7): DataResponse {
$limit = min(20, $limit);
$limit = min(20, max(1, $limit));

$objectTypes = [
Attachment::TYPE_AUDIO,
Expand Down Expand Up @@ -1458,7 +1465,7 @@ public function getObjectsSharedInRoomOverview(int $limit = 7): DataResponse {
#[RequireParticipant]
public function getObjectsSharedInRoom(string $objectType, int $lastKnownMessageId = 0, int $limit = 100): DataResponse {
$offset = max(0, $lastKnownMessageId);
$limit = min(200, $limit);
$limit = min(200, max(1, $limit));

$attachments = $this->attachmentService->getAttachmentsByType($this->room, $objectType, $offset, $limit);
$messageIds = array_map(static fn (Attachment $attachment): int => $attachment->getMessageId(), $attachments);
Expand Down
6 changes: 4 additions & 2 deletions openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -6272,7 +6272,9 @@
"schema": {
"type": "integer",
"format": "int64",
"default": 100
"default": 100,
"minimum": 1,
"maximum": 200
}
},
{
Expand Down Expand Up @@ -7730,7 +7732,7 @@
"type": "integer",
"format": "int64",
"default": 50,
"minimum": 1,
"minimum": 0,
"maximum": 100
}
},
Expand Down
6 changes: 4 additions & 2 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -6177,7 +6177,9 @@
"schema": {
"type": "integer",
"format": "int64",
"default": 100
"default": 100,
"minimum": 1,
"maximum": 200
}
},
{
Expand Down Expand Up @@ -7635,7 +7637,7 @@
"type": "integer",
"format": "int64",
"default": 50,
"minimum": 1,
"minimum": 0,
"maximum": 100
}
},
Expand Down
Loading