feat: Implement reference resolving for cards that have a link in the title

Signed-off-by: Julius Härtl <jus@bitgrid.net>

fix: Enrich on update

Signed-off-by: Julius Knorr <jus@bitgrid.net>

fix: Enrich on create

Signed-off-by: Julius Knorr <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2024-09-01 11:58:08 +02:00
committed by Julius Knorr
parent 46c4c7d4fd
commit 75be929077
12 changed files with 155 additions and 49 deletions

View File

@@ -29,6 +29,7 @@ use OCA\Deck\NoPermissionException;
use OCA\Deck\Notification\NotificationHelper;
use OCA\Deck\StatusException;
use OCA\Deck\Validators\CardServiceValidator;
use OCP\Collaboration\Reference\IReferenceManager;
use OCP\Comments\ICommentsManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IRequest;
@@ -37,9 +38,6 @@ use OCP\IUserManager;
use Psr\Log\LoggerInterface;
class CardService {
private ?string $currentUser;
public function __construct(
private CardMapper $cardMapper,
private StackMapper $stackMapper,
@@ -61,13 +59,13 @@ class CardService {
private IRequest $request,
private CardServiceValidator $cardServiceValidator,
private AssignmentService $assignmentService,
?string $userId,
private IReferenceManager $referenceManager,
private ?string $userId,
) {
$this->currentUser = $userId;
}
public function enrichCards($cards) {
$user = $this->userManager->get($this->currentUser);
$user = $this->userManager->get($this->userId);
$cardIds = array_map(function (Card $card) use ($user) {
// Everything done in here might be heavy as it is executed for every card
@@ -107,11 +105,21 @@ class CardService {
return array_map(
function (Card $card): CardDetails {
return new CardDetails($card);
$cardDetails = new CardDetails($card);
$references = $this->referenceManager->extractReferences($card->getTitle());
$reference = array_shift($references);
if ($reference) {
$referenceData = $this->referenceManager->resolveReference($reference);
$cardDetails->setReferenceData($referenceData);
}
return $cardDetails;
},
$cards
);
}
public function fetchDeleted($boardId) {
$this->cardServiceValidator->check(compact('boardId'));
$this->permissionService->checkPermission($this->boardMapper, $boardId, Acl::PERMISSION_READ);
@@ -191,6 +199,8 @@ class CardService {
$this->changeHelper->cardChanged($card->getId(), false);
$this->eventDispatcher->dispatchTyped(new CardCreatedEvent($card));
[$card] = $this->enrichCards([$card]);
return $card;
}
@@ -265,7 +275,7 @@ class CardService {
}
$changes = new ChangeSet($card);
if ($card->getLastEditor() !== $this->currentUser && $card->getLastEditor() !== null) {
if ($card->getLastEditor() !== $this->userId && $card->getLastEditor() !== null) {
$this->activityManager->triggerEvent(
ActivityManager::DECK_OBJECT_CARD,
$card,
@@ -278,7 +288,7 @@ class CardService {
);
$card->setDescriptionPrev($card->getDescription());
$card->setLastEditor($this->currentUser);
$card->setLastEditor($this->userId);
}
$card->setTitle($title);
$card->setStackId($stackId);
@@ -352,6 +362,8 @@ class CardService {
$this->eventDispatcher->dispatchTyped(new CardUpdatedEvent($card, $changes->getBefore()));
[$card] = $this->enrichCards([$card]);
return $card;
}