Repository navigation
feat: collaborative description editing #8297
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b1d9a7f
feat: collaborative description editing
grnd-alt dbbc851
feature(description): conflict dialog
grnd-alt 1c4a2fc
fix(description): render basic markdown editor correctly
grnd-alt e60962e
fix(description): show last saved date for description
grnd-alt 6bbe8e7
fix(description): exclusively update description when saving from Text
grnd-alt 4e9fbf3
fix(psalm): stub Text app classes used by the context provider
grnd-alt 94c68e6
fix(text): translate card lookup errors to Text context exceptions
grnd-alt 35626a5
fix(text): register description listener only when Text is available
grnd-alt 5dd557f
fix(cypress): wait for the text save request instead of the deck api …
grnd-alt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OCA\Deck\Event; | ||
|
|
||
| use OCA\Deck\Provider\TextContextProviderFactory; | ||
| use OCA\Text\Event\RegisterContextEvent; | ||
| use OCP\EventDispatcher\Event; | ||
| use OCP\EventDispatcher\IEventListener; | ||
|
|
||
| /** @template-implements IEventListener<Event|RegisterContextEvent> */ | ||
| class RegisterTextContextEventListener implements IEventListener { | ||
| public function __construct( | ||
| private readonly TextContextProviderFactory $textContextProviderFactory, | ||
| ) { | ||
| } | ||
| public function handle(Event $event): void { | ||
| if (!$event instanceof RegisterContextEvent) { | ||
| return; | ||
| } | ||
|
|
||
| $event->getContextManager()->registerContext( | ||
| 'deck_card', | ||
| TextContextProviderFactory::class | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace OCA\Deck\Listeners; | ||
|
|
||
| use OCA\Deck\Event\CardUpdatedEvent; | ||
| use OCA\Deck\Provider\TextContextProviderFactory; | ||
| use OCA\Text\Event\DocumentContentUpdated; | ||
| use OCP\EventDispatcher\Event; | ||
| use OCP\EventDispatcher\IEventDispatcher; | ||
| use OCP\EventDispatcher\IEventListener; | ||
|
|
||
| /** | ||
| * Tells Text that a card description changed so it can resolve open editing sessions. | ||
| * | ||
| * @template-implements IEventListener<Event|CardUpdatedEvent> | ||
| */ | ||
| class TextDocumentContentListener implements IEventListener { | ||
| public function __construct( | ||
| private readonly IEventDispatcher $eventDispatcher, | ||
| private readonly TextContextProviderFactory $contextFactory, | ||
| ) { | ||
| } | ||
|
|
||
| public function handle(Event $event): void { | ||
| if (!($event instanceof CardUpdatedEvent) || !class_exists(DocumentContentUpdated::class)) { | ||
| return; | ||
| } | ||
|
|
||
| $before = $event->getCardBefore(); | ||
| $card = $event->getCard(); | ||
| if ($before === null || $before->getDescription() === $card->getDescription()) { | ||
| return; | ||
| } | ||
|
|
||
| $this->eventDispatcher->dispatchTyped( | ||
| new DocumentContentUpdated($this->contextFactory->buildForCard($card->getId())) | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
| /** | ||
| * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Deck\Provider; | ||
|
|
||
| use OC\Security\SecureRandom; | ||
| use OCA\Deck\Db\Acl; | ||
| use OCA\Deck\Db\Card; | ||
| use OCA\Deck\Db\CardMapper; | ||
| use OCA\Deck\NoPermissionException; | ||
| use OCA\Deck\Service\CardService; | ||
| use OCA\Deck\Service\PermissionService; | ||
| use OCA\Text\Context\IContext; | ||
| use OCA\Text\Context\SessionInfo; | ||
| use OCA\Text\Db\Document; | ||
| use OCP\AppFramework\Db\DoesNotExistException; | ||
| use OCP\Files\File; | ||
| use OCP\Files\NotFoundException; | ||
| use OCP\Files\NotPermittedException; | ||
|
|
||
| class TextContextProvider implements IContext { | ||
| public const CONTEXT_TYPE = 'deck_card'; | ||
|
|
||
| public function __construct( | ||
| private readonly SecureRandom $secureRandom, | ||
| private readonly CardService $cardService, | ||
| private readonly CardMapper $cardMapper, | ||
| private readonly PermissionService $permissionService, | ||
| private readonly string $userId, | ||
| private readonly int $cardId, | ||
| ) { | ||
| } | ||
| public function getId(): int { | ||
| return $this->cardId; | ||
| } | ||
|
|
||
| public function getType(): string { | ||
| return self::CONTEXT_TYPE; | ||
| } | ||
|
|
||
| public function toString(): string { | ||
| return $this->getType() . ' (' . $this->getId() . ')'; | ||
| } | ||
|
|
||
| public function buildDocument(): Document { | ||
| $document = new Document(); | ||
| $document->setContextType($this->getType()); | ||
| $document->setContextId($this->getId()); | ||
| $document->setLastSavedVersion(0); | ||
| $document->setLastSavedVersionTime($this->getLastModified()); | ||
| $document->setLastSavedVersionEtag($this->secureRandom->generate(6)); | ||
|
|
||
| $document->setChecksum($this->computeChecksum()); | ||
| $document->setBaseVersionEtag(uniqid()); | ||
| return $document; | ||
| } | ||
|
|
||
| public function prepareSession(): SessionInfo { | ||
| $readonly = !$this->permissionService->checkPermission($this->cardMapper, $this->cardId, Acl::PERMISSION_EDIT, $this->userId); | ||
| return new SessionInfo( | ||
| readOnly: $readonly, | ||
| lock: null, | ||
| canAttachFiles: false, | ||
| ); | ||
| } | ||
|
|
||
| public function isReadOnly(): bool { | ||
| return !$this->permissionService->checkPermission($this->cardMapper, $this->cardId, Acl::PERMISSION_EDIT, $this->userId); | ||
| } | ||
|
|
||
| public function updateDocument(Document $document): void { | ||
| $document->setChecksum($this->computeChecksum()); | ||
| $document->setLastSavedVersionTime($this->getLastModified()); | ||
| } | ||
|
|
||
| /** | ||
| * @throws NotFoundException | ||
| * @throws NotPermittedException | ||
| */ | ||
| private function findCard(): Card { | ||
| try { | ||
| return $this->cardService->find($this->cardId); | ||
| } catch (DoesNotExistException $e) { | ||
| throw new NotFoundException($e->getMessage(), 0, $e); | ||
| } catch (NoPermissionException $e) { | ||
| throw new NotPermittedException($e->getMessage(), 0, $e); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @throws NotFoundException | ||
| * @throws NotPermittedException | ||
| */ | ||
| private function getLastModified(): int { | ||
| $card = $this->findCard(); | ||
| return (int)($card->getLastModified() ?: time()); | ||
| } | ||
|
|
||
| public function getFile(): ?File { | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * @throws NotFoundException | ||
| * @throws NotPermittedException | ||
| */ | ||
| public function loadContent(): ?string { | ||
| $card = $this->findCard(); | ||
| return $card->getDescription(); | ||
| } | ||
|
|
||
| public function cleanup(): void { | ||
| } | ||
|
|
||
| public function save(string $content, callable $afterSave): void { | ||
| $this->cardService->updateDescription($this->cardId, $content); | ||
| $afterSave(); | ||
| } | ||
|
|
||
| /** | ||
| * @throws NotFoundException | ||
| * @throws NotPermittedException | ||
| */ | ||
| private function computeChecksum(): string { | ||
| $card = $this->findCard(); | ||
| return hash('crc32', $card->getDescription()); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\Deck\Provider; | ||
|
|
||
| use OC\Security\SecureRandom; | ||
| use OCA\Deck\Db\CardMapper; | ||
| use OCA\Deck\Service\CardService; | ||
| use OCA\Deck\Service\PermissionService; | ||
| use OCA\Text\Context\IContext; | ||
| use OCA\Text\Context\IContextFactory; | ||
| use OCP\IUser; | ||
| use OCP\Share\IShare; | ||
|
|
||
| class TextContextProviderFactory implements IContextFactory { | ||
| public function __construct( | ||
| private readonly SecureRandom $secureRandom, | ||
| private readonly CardService $cardService, | ||
| private readonly CardMapper $cardMapper, | ||
| private readonly PermissionService $permissionService, | ||
| private readonly string $userId, | ||
| ) { | ||
| } | ||
|
|
||
| public function build(IUser|IShare $auth, string $type, int $id): IContext { | ||
| return $this->buildForCard($id); | ||
| } | ||
|
|
||
| public function buildForCard(int $cardId): TextContextProvider { | ||
| return new TextContextProvider( | ||
| secureRandom: $this->secureRandom, | ||
| cardService: $this->cardService, | ||
| cardMapper: $this->cardMapper, | ||
| permissionService: $this->permissionService, | ||
| userId: $this->userId, | ||
| cardId: $cardId, | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was a little confused by the name. Sounds like it would listen to updates of the Document Content while actually it listens to updates of the card content. But maybe it fits your naming scheme.