Skip to content

Commit

Permalink
fix(federation): Fix return type of editing
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Feb 28, 2024
1 parent b550195 commit 05c37e8
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions lib/Federation/Proxy/TalkV1/Controller/ChatController.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public function getMessageContext(Room $room, Participant $participant, int $mes
}

/**
* @return DataResponse<Http::STATUS_OK|Http::STATUS_ACCEPTED, TalkChatMessageWithParent, array{X-Chat-Last-Common-Read?: numeric-string}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: string}, array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_NOT_FOUND|Http::STATUS_METHOD_NOT_ALLOWED, array<empty>, array{}>
* @return DataResponse<Http::STATUS_OK|Http::STATUS_ACCEPTED, TalkChatMessageWithParent, array{X-Chat-Last-Common-Read?: numeric-string}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: string}, array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_NOT_FOUND|Http::STATUS_METHOD_NOT_ALLOWED|Http::STATUS_REQUEST_ENTITY_TOO_LARGE, array<empty>, array{}>
* @throws CannotReachRemoteException
*
* 200: Message edited successfully
Expand All @@ -231,28 +231,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')) {
Expand Down

0 comments on commit 05c37e8

Please sign in to comment.