Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions lib/Service/CardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use OCA\Deck\Db\ChangeHelper;
use OCA\Deck\Db\Label;
use OCA\Deck\Db\LabelMapper;
use OCA\Deck\Db\Stack;
use OCA\Deck\Db\StackMapper;
use OCA\Deck\Event\CardCreatedEvent;
use OCA\Deck\Event\CardDeletedEvent;
Expand Down Expand Up @@ -64,31 +65,47 @@
) {
}

public function enrichCards($cards) {
/**
* @param Card[] $cards
* @return CardDetails[]
*/
public function enrichCards(array $cards, Stack $stack = null): array {
if (!$cards) {
return [];
}

$user = $this->userManager->get($this->userId);

$cardIds = array_map(function (Card $card) use ($user) {
$cardIds = array_map(function (Card $card) use ($user, $stack) {
// Everything done in here might be heavy as it is executed for every card
$cardId = $card->getId();
$this->cardMapper->mapOwner($card);

$card->setAttachmentCount($this->attachmentService->count($cardId));

// TODO We should find a better way just to get the comment count so we can save 1-3 queries per card here
$countComments = $this->commentsManager->getNumberOfCommentsForObject('deckCard', (string)$card->getId());
$lastRead = $countComments > 0 ? $this->commentsManager->getReadMark('deckCard', (string)$card->getId(), $user) : null;
$countUnreadComments = $lastRead ? $this->commentsManager->getNumberOfCommentsForObject('deckCard', (string)$card->getId(), $lastRead) : 0;
$card->setCommentsUnread($countUnreadComments);
$card->setCommentsCount($countComments);

$stack = $this->stackMapper->find($card->getStackId());
if ($stack === null) {
$stack = $this->stackMapper->find($card->getStackId());
}
$board = $this->boardService->find($stack->getBoardId(), false);
$card->setRelatedStack($stack);
$card->setRelatedBoard($board);

return $card->getId();
return $cardId;
}, $cards);

$commentsCountPerCardId = $this->commentsManager->getNumberOfCommentsForObjects('deckCard', $cardIds);

Check failure on line 96 in lib/Service/CardService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedInterfaceMethod

lib/Service/CardService.php:96:53: UndefinedInterfaceMethod: Method OCP\Comments\ICommentsManager::getNumberOfCommentsForObjects does not exist (see https://psalm.dev/181)
$unreadCommentsCountPerCardId = $this->commentsManager->getNumberOfUnreadCommentsForObjects('deckCard', $cardIds, $user);

Check failure on line 97 in lib/Service/CardService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

InvalidArgument

lib/Service/CardService.php:97:107: InvalidArgument: Argument 2 of OCP\Comments\ICommentsManager::getNumberOfUnreadCommentsForObjects expects array<array-key, string>, but non-empty-array<array-key, int> provided (see https://psalm.dev/004)

foreach ($commentsCountPerCardId as $cardId => $commentCounts) {
foreach ($cards as $card) {
if ($card->getId() === $cardId) {
$card->setCommentsUnread($unreadCommentsCountPerCardId[$cardId]);

Check failure on line 102 in lib/Service/CardService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

InvalidArrayOffset

lib/Service/CardService.php:102:31: InvalidArrayOffset: Cannot access value on variable $unreadCommentsCountPerCardId using a int offset, expecting string (see https://psalm.dev/115)
$card->setCommentsCount($commentCounts);
break;
}
}
}

$assignedLabels = $this->labelMapper->findAssignedLabelsForCards($cardIds);
$assignedUsers = $this->assignedUsersMapper->findIn($cardIds);

Expand Down
2 changes: 1 addition & 1 deletion lib/Service/StackService.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private function enrichStackWithCards($stack, $since = -1) {
return;
}

$stack->setCards($this->cardService->enrichCards($cards));
$stack->setCards($this->cardService->enrichCards($cards, $stack));
}

private function enrichStacksWithCards($stacks, $since = -1) {
Expand Down
Loading