From 2397bd4fae0292e308207d4956aaf24fd94dcb38 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 18 Mar 2022 09:23:24 +0100 Subject: [PATCH] Add an endpoint for a media tab Signed-off-by: Joas Schilling --- appinfo/routes/routesChatController.php | 2 ++ lib/Controller/ChatController.php | 31 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/appinfo/routes/routesChatController.php b/appinfo/routes/routesChatController.php index 9b70c25b0..55f31b981 100644 --- a/appinfo/routes/routesChatController.php +++ b/appinfo/routes/routesChatController.php @@ -52,5 +52,7 @@ return [ ['name' => 'Chat#mentions', 'url' => '/api/{apiVersion}/chat/{token}/mentions', 'verb' => 'GET', 'requirements' => $requirements], /** @see \OCA\Talk\Controller\ChatController::shareObjectToChat() */ ['name' => 'Chat#shareObjectToChat', 'url' => '/api/{apiVersion}/chat/{token}/share', 'verb' => 'POST', 'requirements' => $requirements], + /** @see \OCA\Talk\Controller\ChatController::getObjectsSharedInRoom() */ + ['name' => 'Chat#getObjectsSharedInRoom', 'url' => '/api/{apiVersion}/chat/{token}/share', 'verb' => 'GET', 'requirements' => $requirements], ], ]; diff --git a/lib/Controller/ChatController.php b/lib/Controller/ChatController.php index 312965dc3..686a75359 100644 --- a/lib/Controller/ChatController.php +++ b/lib/Controller/ChatController.php @@ -700,6 +700,37 @@ class ChatController extends AEnvironmentAwareController { return $this->setReadMarker($unreadId); } + /** + * @PublicPage + * @RequireParticipant + * @RequireReadWriteConversation + * @RequireModeratorOrNoLobby + * + * @param int $offset + * @param int $limit + * @return DataResponse + */ + public function getObjectsSharedInRoom(int $offset = 0, int $limit = 50): DataResponse { + $offset = max(0, $offset); + $limit = min(200, $limit); + + $comments = $this->chatManager->searchForObjects('', [$this->room->getId()], 'object_shared', $offset, $limit); + + $messages = []; + foreach ($comments as $comment) { + $message = $this->messageParser->createMessage($this->room, $this->participant, $comment, $this->l); + $this->messageParser->parseMessage($message); + + if (!$message->getVisibility()) { + continue; + } + + $messages[] = $message->toArray(); + } + + return new DataResponse($messages); + } + /** * @PublicPage * @RequireParticipant