From 8bc276e2fe4874dbea9ca0433f04f6eb88898a78 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 21 Nov 2024 12:31:04 +0100 Subject: [PATCH] fix(openapi): Fix reactions API empty array cases Signed-off-by: Joas Schilling --- lib/Chat/ReactionManager.php | 2 +- lib/Controller/ReactionController.php | 20 ++++++++--------- .../TalkV1/Controller/ReactionController.php | 22 +++++++++---------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/Chat/ReactionManager.php b/lib/Chat/ReactionManager.php index 11a0efe3e1b..3fc31b74cfe 100644 --- a/lib/Chat/ReactionManager.php +++ b/lib/Chat/ReactionManager.php @@ -127,7 +127,7 @@ public function deleteReactionMessage(Room $chat, string $actorType, string $act } /** - * @return array + * @return array> * @throws PreConditionNotMetException */ public function retrieveReactionMessages(Room $chat, Participant $participant, int $messageId, ?string $reaction = null): array { diff --git a/lib/Controller/ReactionController.php b/lib/Controller/ReactionController.php index 85b90aaeab5..e84b84365cd 100644 --- a/lib/Controller/ReactionController.php +++ b/lib/Controller/ReactionController.php @@ -43,7 +43,7 @@ public function __construct( * @param int $messageId ID of the message * @psalm-param non-negative-int $messageId * @param string $reaction Emoji to add - * @return DataResponse|\stdClass, array{}>|DataResponse, array{}> + * @return DataResponse>|\stdClass, array{}>|DataResponse * * 200: Reaction already existed * 201: Reaction added successfully @@ -73,11 +73,11 @@ public function react(int $messageId, string $reaction): DataResponse { ); $status = Http::STATUS_CREATED; } catch (NotFoundException $e) { - return new DataResponse([], Http::STATUS_NOT_FOUND); + return new DataResponse(null, Http::STATUS_NOT_FOUND); } catch (ReactionAlreadyExistsException $e) { $status = Http::STATUS_OK; } catch (ReactionNotSupportedException|ReactionOutOfContextException|\Exception $e) { - return new DataResponse([], Http::STATUS_BAD_REQUEST); + return new DataResponse(null, Http::STATUS_BAD_REQUEST); } $reactions = $this->reactionManager->retrieveReactionMessages($this->getRoom(), $this->getParticipant(), $messageId); return new DataResponse($this->formatReactions($reactions), $status); @@ -89,7 +89,7 @@ public function react(int $messageId, string $reaction): DataResponse { * @param int $messageId ID of the message * @psalm-param non-negative-int $messageId * @param string $reaction Emoji to remove - * @return DataResponse|\stdClass, array{}>|DataResponse, array{}> + * @return DataResponse>|\stdClass, array{}>|DataResponse * * 200: Reaction deleted successfully * 400: Deleting reaction is not possible @@ -118,9 +118,9 @@ public function delete(int $messageId, string $reaction): DataResponse { ); $reactions = $this->reactionManager->retrieveReactionMessages($this->getRoom(), $this->getParticipant(), $messageId); } catch (ReactionNotSupportedException|ReactionOutOfContextException|NotFoundException $e) { - return new DataResponse([], Http::STATUS_NOT_FOUND); + return new DataResponse(null, Http::STATUS_NOT_FOUND); } catch (\Exception $e) { - return new DataResponse([], Http::STATUS_BAD_REQUEST); + return new DataResponse(null, Http::STATUS_BAD_REQUEST); } return new DataResponse($this->formatReactions($reactions), Http::STATUS_OK); @@ -132,7 +132,7 @@ public function delete(int $messageId, string $reaction): DataResponse { * @param int $messageId ID of the message * @psalm-param non-negative-int $messageId * @param string|null $reaction Emoji to filter - * @return DataResponse|\stdClass, array{}>|DataResponse, array{}> + * @return DataResponse>|\stdClass, array{}>|DataResponse * * 200: Reactions returned * 404: Message or reaction not found @@ -152,7 +152,7 @@ public function getReactions(int $messageId, ?string $reaction): DataResponse { // Verify that messageId is part of the room $this->reactionManager->getCommentToReact($this->getRoom(), (string)$messageId); } catch (ReactionNotSupportedException|ReactionOutOfContextException|NotFoundException $e) { - return new DataResponse([], Http::STATUS_NOT_FOUND); + return new DataResponse(null, Http::STATUS_NOT_FOUND); } $reactions = $this->reactionManager->retrieveReactionMessages($this->getRoom(), $this->getParticipant(), $messageId, $reaction); @@ -161,8 +161,8 @@ public function getReactions(int $messageId, ?string $reaction): DataResponse { } /** - * @param array $reactions - * @return array|\stdClass + * @param array> $reactions + * @return array>|\stdClass */ protected function formatReactions(array $reactions): array|\stdClass { if ($this->getResponseFormat() === 'json' && empty($reactions)) { diff --git a/lib/Federation/Proxy/TalkV1/Controller/ReactionController.php b/lib/Federation/Proxy/TalkV1/Controller/ReactionController.php index 2812a7591e1..4cb454a7474 100644 --- a/lib/Federation/Proxy/TalkV1/Controller/ReactionController.php +++ b/lib/Federation/Proxy/TalkV1/Controller/ReactionController.php @@ -32,7 +32,7 @@ public function __construct( * @param int $messageId ID of the message * @psalm-param non-negative-int $messageId * @param string $reaction Emoji to add - * @return DataResponse|\stdClass, array{}>|DataResponse, array{}> + * @return DataResponse>|\stdClass, array{}>|DataResponse * * 200: Reaction already existed * 201: Reaction added successfully @@ -59,10 +59,10 @@ public function react(Room $room, Participant $participant, int $messageId, stri ], true)) { $statusCode = $this->proxy->logUnexpectedStatusCode(__METHOD__, $statusCode); } - return new DataResponse([], $statusCode); + return new DataResponse(null, $statusCode); } - /** @var array $data */ + /** @var array> $data */ $data = $this->proxy->getOCSData($proxy, [Http::STATUS_CREATED, Http::STATUS_OK]); $data = $this->userConverter->convertReactionsList($room, $data); @@ -75,7 +75,7 @@ public function react(Room $room, Participant $participant, int $messageId, stri * @param int $messageId ID of the message * @psalm-param non-negative-int $messageId * @param string $reaction Emoji to remove - * @return DataResponse|\stdClass, array{}>|DataResponse, array{}> + * @return DataResponse>|\stdClass, array{}>|DataResponse * * 200: Reaction deleted successfully * 400: Deleting reaction is not possible @@ -101,10 +101,10 @@ public function delete(Room $room, Participant $participant, int $messageId, str ], true)) { $statusCode = $this->proxy->logUnexpectedStatusCode(__METHOD__, $statusCode); } - return new DataResponse([], $statusCode); + return new DataResponse(null, $statusCode); } - /** @var array $data */ + /** @var array> $data */ $data = $this->proxy->getOCSData($proxy); $data = $this->userConverter->convertReactionsList($room, $data); @@ -118,7 +118,7 @@ public function delete(Room $room, Participant $participant, int $messageId, str * @param int $messageId ID of the message * @psalm-param non-negative-int $messageId * @param string|null $reaction Emoji to filter - * @return DataResponse|\stdClass, array{}>|DataResponse, array{}> + * @return DataResponse>|\stdClass, array{}>|DataResponse * * 200: Reactions returned * 404: Message or reaction not found @@ -140,10 +140,10 @@ public function getReactions(Room $room, Participant $participant, int $messageI if ($statusCode !== Http::STATUS_NOT_FOUND) { $this->proxy->logUnexpectedStatusCode(__METHOD__, $statusCode); } - return new DataResponse([], Http::STATUS_NOT_FOUND); + return new DataResponse(null, Http::STATUS_NOT_FOUND); } - /** @var array $data */ + /** @var array> $data */ $data = $this->proxy->getOCSData($proxy); $data = $this->userConverter->convertReactionsList($room, $data); @@ -151,8 +151,8 @@ public function getReactions(Room $room, Participant $participant, int $messageI } /** - * @param array $reactions - * @return array|\stdClass + * @param array> $reactions + * @return array>|\stdClass */ protected function formatReactions(string $format, array $reactions): array|\stdClass { if ($format === 'json' && empty($reactions)) {