Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(openapi): Fix more empty arrays #13837

Merged
merged 9 commits into from
Dec 2, 2024
4 changes: 2 additions & 2 deletions lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ public function __construct(

/**
* @return array{
* spreed: TalkCapabilities,
* }|array<empty>
* spreed?: TalkCapabilities,
* }
*/
public function getCapabilities(): array {
$user = $this->userSession->getUser();
Expand Down
7 changes: 7 additions & 0 deletions lib/Chat/ChatManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use OCA\Talk\Model\Message;
use OCA\Talk\Model\Poll;
use OCA\Talk\Participant;
use OCA\Talk\ResponseDefinitions;
use OCA\Talk\Room;
use OCA\Talk\Service\AttachmentService;
use OCA\Talk\Service\ParticipantService;
Expand Down Expand Up @@ -59,6 +60,8 @@
*
* When a message is saved the mentioned users are notified as needed, and
* pending notifications are removed if the messages are deleted.
*
* @psalm-import-type TalkChatMentionSuggestion from ResponseDefinitions
*/
class ChatManager {
public const MAX_CHAT_LENGTH = 32000;
Expand Down Expand Up @@ -968,6 +971,10 @@ public function searchForObjectsWithFilters(string $search, array $objectIds, st
return $this->commentsManager->searchForObjectsWithFilters($search, 'chat', $objectIds, $verb, $since, $until, $actorType, $actorId, $offset, $limit);
}

/**
* @param list<TalkChatMentionSuggestion> $results
* @return list<TalkChatMentionSuggestion>
*/
public function addConversationNotify(array $results, string $search, Room $room, Participant $participant): array {
if ($room->getType() === Room::TYPE_ONE_TO_ONE) {
return $results;
Expand Down
2 changes: 1 addition & 1 deletion lib/Chat/ReactionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function deleteReactionMessage(Room $chat, string $actorType, string $act
}

/**
* @return array<string, TalkReaction[]>
* @return array<string, list<TalkReaction>>
* @throws PreConditionNotMetException
*/
public function retrieveReactionMessages(Room $chat, Participant $participant, int $messageId, ?string $reaction = null): array {
Expand Down
100 changes: 53 additions & 47 deletions lib/Controller/ChatController.php

Large diffs are not rendered by default.

38 changes: 17 additions & 21 deletions lib/Controller/PollController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
use OCP\AppFramework\Http\Attribute\PublicPage;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\DB\Exception;
use OCP\IRequest;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -169,7 +168,7 @@ public function getAllDraftPolls(): DataResponse {
*
* @param int $pollId ID of the poll
* @psalm-param non-negative-int $pollId
* @return DataResponse<Http::STATUS_OK, TalkPoll, array{}>|DataResponse<Http::STATUS_NOT_FOUND, array<empty>, array{}>
* @return DataResponse<Http::STATUS_OK, TalkPoll, array{}>|DataResponse<Http::STATUS_NOT_FOUND, array{error: string}, array{}>
*
* 200: Poll returned
* 404: Poll not found
Expand All @@ -188,11 +187,11 @@ public function showPoll(int $pollId): DataResponse {
try {
$poll = $this->pollService->getPoll($this->room->getId(), $pollId);
} catch (DoesNotExistException) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
return new DataResponse(['error' => 'poll'], Http::STATUS_NOT_FOUND);
}

if ($poll->getStatus() === Poll::STATUS_DRAFT && !$this->participant->hasModeratorPermissions()) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
return new DataResponse(['error' => 'poll'], Http::STATUS_NOT_FOUND);
}

$votedSelf = $this->pollService->getVotesForActor($this->participant, $poll);
Expand All @@ -209,8 +208,8 @@ public function showPoll(int $pollId): DataResponse {
*
* @param int $pollId ID of the poll
* @psalm-param non-negative-int $pollId
* @param int[] $optionIds IDs of the selected options
* @return DataResponse<Http::STATUS_OK, TalkPoll, array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND, array<empty>, array{}>
* @param list<int> $optionIds IDs of the selected options
* @return DataResponse<Http::STATUS_OK, TalkPoll, array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND, array{error: string}, array{}>
*
* 200: Voted successfully
* 400: Voting is not possible
Expand All @@ -230,21 +229,21 @@ public function votePoll(int $pollId, array $optionIds = []): DataResponse {
try {
$poll = $this->pollService->getPoll($this->room->getId(), $pollId);
} catch (DoesNotExistException) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
return new DataResponse(['error' => 'poll'], Http::STATUS_NOT_FOUND);
}

if ($poll->getStatus() === Poll::STATUS_DRAFT) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
return new DataResponse(['error' => 'poll'], Http::STATUS_NOT_FOUND);
}

if ($poll->getStatus() === Poll::STATUS_CLOSED) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
return new DataResponse(['error' => 'poll'], Http::STATUS_BAD_REQUEST);
}

try {
$votedSelf = $this->pollService->votePoll($this->participant, $poll, $optionIds);
} catch (\RuntimeException $e) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
return new DataResponse(['error' => 'options'], Http::STATUS_BAD_REQUEST);
}

if ($poll->getResultMode() === Poll::MODE_PUBLIC) {
Expand Down Expand Up @@ -274,7 +273,7 @@ public function votePoll(int $pollId, array $optionIds = []): DataResponse {
*
* @param int $pollId ID of the poll
* @psalm-param non-negative-int $pollId
* @return DataResponse<Http::STATUS_OK, TalkPoll, array{}>|DataResponse<Http::STATUS_ACCEPTED|Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_NOT_FOUND|Http::STATUS_INTERNAL_SERVER_ERROR, array<empty>, array{}>
* @return DataResponse<Http::STATUS_OK, TalkPoll, array{}>|DataResponse<Http::STATUS_ACCEPTED, null, array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_NOT_FOUND, array{error: string}, array{}>
*
* 200: Poll closed successfully
* 202: Poll draft was deleted successfully
Expand All @@ -296,27 +295,24 @@ public function closePoll(int $pollId): DataResponse {
try {
$poll = $this->pollService->getPoll($this->room->getId(), $pollId);
} catch (DoesNotExistException) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
return new DataResponse(['error' => 'poll'], Http::STATUS_NOT_FOUND);
}

if ($poll->getStatus() === Poll::STATUS_DRAFT) {
$this->pollService->deleteByPollId($poll->getId());
return new DataResponse([], Http::STATUS_ACCEPTED);
return new DataResponse(null, Http::STATUS_ACCEPTED);
}

if ($poll->getStatus() === Poll::STATUS_CLOSED) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
return new DataResponse(['error' => 'poll'], Http::STATUS_BAD_REQUEST);
}

$poll->setStatus(Poll::STATUS_CLOSED);

try {
$this->pollService->updatePoll($this->participant, $poll);
} catch (WrongPermissionsException $e) {
return new DataResponse([], Http::STATUS_FORBIDDEN);
} catch (Exception $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
} catch (WrongPermissionsException) {
return new DataResponse(['error' => 'poll'], Http::STATUS_FORBIDDEN);
}

$attendee = $this->participant->getAttendee();
Expand Down Expand Up @@ -366,10 +362,10 @@ protected function renderPoll(Poll $poll, array $votedSelf = [], array $detailed
$data['numVoters'] = 0;
}
} elseif ($poll->getResultMode() === Poll::MODE_PUBLIC && $poll->getStatus() === Poll::STATUS_CLOSED) {
$data['details'] = array_map(static fn (Vote $vote) => $vote->asArray(), $detailedVotes);
$data['details'] = array_values(array_map(static fn (Vote $vote) => $vote->asArray(), $detailedVotes));
}

$data['votedSelf'] = array_map(static fn (Vote $vote) => $vote->getOptionId(), $votedSelf);
$data['votedSelf'] = array_values(array_map(static fn (Vote $vote) => $vote->getOptionId(), $votedSelf));

return $data;
}
Expand Down
10 changes: 5 additions & 5 deletions lib/Controller/PublicShareAuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(
* otherwise.
*
* @param string $shareToken Token of the file share
* @return DataResponse<Http::STATUS_CREATED, array{token: string, name: string, displayName: string}, array{}>|DataResponse<Http::STATUS_NOT_FOUND, array<empty>, array{}>
* @return DataResponse<Http::STATUS_CREATED, array{token: string, name: string, displayName: string}, array{}>|DataResponse<Http::STATUS_NOT_FOUND, null, array{}>
*
* 201: Room created successfully
* 404: Share not found
Expand All @@ -59,18 +59,18 @@ public function __construct(
public function createRoom(string $shareToken): DataResponse {
try {
$share = $this->shareManager->getShareByToken($shareToken);
} catch (ShareNotFound $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
} catch (ShareNotFound) {
return new DataResponse(null, Http::STATUS_NOT_FOUND);
}

if (!$share->getSendPasswordByTalk()) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
return new DataResponse(null, Http::STATUS_NOT_FOUND);
}

$sharerUser = $this->userManager->get($share->getSharedBy());

if (!$sharerUser instanceof IUser) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
return new DataResponse(null, Http::STATUS_NOT_FOUND);
}

if ($share->getShareType() === IShare::TYPE_EMAIL) {
Expand Down
20 changes: 10 additions & 10 deletions lib/Controller/ReactionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<Http::STATUS_OK|Http::STATUS_CREATED, array<string, TalkReaction[]>|\stdClass, array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND, array<empty>, array{}>
* @return DataResponse<Http::STATUS_OK|Http::STATUS_CREATED, array<string, list<TalkReaction>>|\stdClass, array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND, null, array{}>
*
* 200: Reaction already existed
* 201: Reaction added successfully
Expand Down Expand Up @@ -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);
Expand All @@ -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<Http::STATUS_OK, array<string, TalkReaction[]>|\stdClass, array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND, array<empty>, array{}>
* @return DataResponse<Http::STATUS_OK, array<string, list<TalkReaction>>|\stdClass, array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_NOT_FOUND, null, array{}>
*
* 200: Reaction deleted successfully
* 400: Deleting reaction is not possible
Expand Down Expand Up @@ -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);
Expand All @@ -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<Http::STATUS_OK, array<string, TalkReaction[]>|\stdClass, array{}>|DataResponse<Http::STATUS_NOT_FOUND, array<empty>, array{}>
* @return DataResponse<Http::STATUS_OK, array<string, list<TalkReaction>>|\stdClass, array{}>|DataResponse<Http::STATUS_NOT_FOUND, null, array{}>
*
* 200: Reactions returned
* 404: Message or reaction not found
Expand All @@ -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);
Expand All @@ -161,8 +161,8 @@ public function getReactions(int $messageId, ?string $reaction): DataResponse {
}

/**
* @param array<string, TalkReaction[]> $reactions
* @return array<string, TalkReaction[]>|\stdClass
* @param array<string, list<TalkReaction>> $reactions
* @return array<string, list<TalkReaction>>|\stdClass
*/
protected function formatReactions(array $reactions): array|\stdClass {
if ($this->getResponseFormat() === 'json' && empty($reactions)) {
Expand Down
Loading
Loading