diff options
author | Joas Schilling <coding@schilljs.com> | 2022-03-22 19:02:52 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2022-03-23 10:40:28 +0300 |
commit | acdbdb7838396ecdfe5a1069c2c0fc5d140bf881 (patch) | |
tree | 45e6a6f943b5b2674463c3a24036f781c0eaf486 /lib | |
parent | 5035644bb9e35b92736cce04cbde6e8c2b709842 (diff) |
Instead of the offset based use lastKnownMessageId as for message
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Chat/ChatManager.php | 19 | ||||
-rw-r--r-- | lib/Controller/ChatController.php | 17 |
2 files changed, 31 insertions, 5 deletions
diff --git a/lib/Chat/ChatManager.php b/lib/Chat/ChatManager.php index 9209f9342..290867592 100644 --- a/lib/Chat/ChatManager.php +++ b/lib/Chat/ChatManager.php @@ -567,6 +567,25 @@ class ChatManager { /** * 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 + * * @param string $search content to search for * @param array $objectIds Limit the search by object ids * @param string $verb Limit the verb of the comment diff --git a/lib/Controller/ChatController.php b/lib/Controller/ChatController.php index 686a75359..df22cabe0 100644 --- a/lib/Controller/ChatController.php +++ b/lib/Controller/ChatController.php @@ -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; } /** |