From c9ef41a3a6f078b774438344bea3de9018e30792 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 27 Feb 2024 21:05:51 +0100 Subject: [PATCH] fix(federation): Fix return type of editing Signed-off-by: Joas Schilling --- .../TalkV1/Controller/ChatController.php | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/Federation/Proxy/TalkV1/Controller/ChatController.php b/lib/Federation/Proxy/TalkV1/Controller/ChatController.php index 730622b941c7..6e4494eb582a 100644 --- a/lib/Federation/Proxy/TalkV1/Controller/ChatController.php +++ b/lib/Federation/Proxy/TalkV1/Controller/ChatController.php @@ -233,7 +233,7 @@ public function getMessageContext(Room $room, Participant $participant, int $mes } /** - * @return DataResponse|DataResponse|DataResponse, array{}> + * @return DataResponse|DataResponse|DataResponse, array{}> * @throws CannotReachRemoteException * * 200: Message edited successfully @@ -255,28 +255,29 @@ public function editMessage(Room $room, Participant $participant, int $messageId ], ); - /** @var Http::STATUS_OK|Http::STATUS_ACCEPTED|Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_NOT_FOUND|Http::STATUS_REQUEST_ENTITY_TOO_LARGE $statusCode */ $statusCode = $proxy->getStatusCode(); - if ($statusCode !== Http::STATUS_OK && $statusCode !== Http::STATUS_ACCEPTED) { - if (in_array($statusCode, [ + if (!in_array($statusCode, [ Http::STATUS_BAD_REQUEST, Http::STATUS_FORBIDDEN, Http::STATUS_NOT_FOUND, + Http::STATUS_METHOD_NOT_ALLOWED, Http::STATUS_REQUEST_ENTITY_TOO_LARGE, ], true)) { $statusCode = $this->proxy->logUnexpectedStatusCode(__METHOD__, $statusCode); + $data = ['error' => 'status']; + } elseif ($statusCode === Http::STATUS_BAD_REQUEST) { + /** @var array{error: string} $data */ + $data = $this->proxy->getOCSData($proxy, [Http::STATUS_BAD_REQUEST]); + } else { + $data = []; } - return new DataResponse([], $statusCode); + return new DataResponse($data, $statusCode); } - /** @var ?TalkChatMessageWithParent $data */ + /** @var TalkChatMessageWithParent $data */ $data = $this->proxy->getOCSData($proxy, [Http::STATUS_OK, Http::STATUS_ACCEPTED]); - if (!empty($data)) { - $data = $this->userConverter->convertMessage($room, $data); - } else { - $data = null; - } + $data = $this->userConverter->convertMessage($room, $data); $headers = []; if ($proxy->getHeader('X-Chat-Last-Common-Read')) {