Skip to content
Merged
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
7 changes: 4 additions & 3 deletions cypress/e2e/cardFeatures.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,13 @@ describe('Card', function () {

it('Shows the modal with the editor', () => {
cy.get('.card:contains("Hello world")').should('be.visible').click()
cy.intercept({ method: 'PUT', url: '**/ocs/v2.php/apps/deck/api/v1.0/cards/*' }).as('save')
cy.intercept({ method: 'POST', url: '**/apps/text/session/*/save' }).as('save')
cy.get('.modal__card').should('be.visible')
cy.get('.app-sidebar-header__mainname').contains('Hello world')
cy.get('.modal__card .ProseMirror h1').contains('Hello world').should('be.visible')
cy.get('.modal__card .ProseMirror h1')
.click()
.parent()
.type(' writing more text{enter}- List item{enter}with entries{enter}{enter}Paragraph')
cy.wait('@save', { timeout: 7000 })

Expand All @@ -284,7 +285,7 @@ describe('Card', function () {

// Scroll to the bottom to ensure all content is loaded and visible
cy.get('.modal__card .app-sidebar-tabs, .modal__card .app-sidebar__tab--active').first().scrollTo('bottom', { ensureScrollable: false })
cy.contains('.modal__card .ProseMirror p', 'Paragraph').scrollIntoView().should('be.visible')
cy.contains('.modal__card .ProseMirror p', 'Paragraph').should('be.visible')

cy.get('.modal__card .ProseMirror h1').contains('Hello world writing more text').should('be.visible')
cy.get('.modal__card .ProseMirror li').eq(0).contains('List item').should('be.visible')
Expand All @@ -298,7 +299,7 @@ describe('Card', function () {
cy.get('.card:contains("Hello world")').should('be.visible').click()
cy.get('.modal__card').should('be.visible')
cy.get('.modal__card .ProseMirror h1')
.click()
.click().parent()
.type('{enter}/create')
cy.get('.suggestion-list__item.is-selected').should('be.visible').contains('Create a new deck card')
cy.get('.suggestion-list__item.is-selected .link-picker__item').click()
Expand Down
12 changes: 12 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use OCA\Deck\Event\CardCreatedEvent;
use OCA\Deck\Event\CardDeletedEvent;
use OCA\Deck\Event\CardUpdatedEvent;
use OCA\Deck\Event\RegisterTextContextEventListener;
use OCA\Deck\Event\SessionClosedEvent;
use OCA\Deck\Event\SessionCreatedEvent;
use OCA\Deck\Federation\DeckFederationProvider;
Expand All @@ -37,6 +38,7 @@
use OCA\Deck\Listeners\ResourceAdditionalScriptsListener;
use OCA\Deck\Listeners\ResourceListener;
use OCA\Deck\Listeners\ResourceTypeRegisterListener;
use OCA\Deck\Listeners\TextDocumentContentListener;
use OCA\Deck\Middleware\DefaultBoardMiddleware;
use OCA\Deck\Middleware\ExceptionMiddleware;
use OCA\Deck\Middleware\FederationMiddleware;
Expand All @@ -52,7 +54,9 @@
use OCA\Deck\Sharing\Listener;
use OCA\Deck\Teams\DeckTeamResourceProvider;
use OCA\Deck\UserMigration\DeckMigrator;
use OCA\Text\Event\DocumentContentUpdated;
use OCA\Text\Event\LoadEditor;
use OCA\Text\Event\RegisterContextEvent;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
Expand Down Expand Up @@ -106,6 +110,12 @@ public function boot(IBootContext $context): void {
$context->injectFn($this->registerCommentsEntity(...));
$context->injectFn($this->registerCollaborationResources(...));

if (class_exists(DocumentContentUpdated::class)) {
$context->injectFn(function (IEventDispatcher $eventDispatcher) {
$eventDispatcher->addServiceListener(CardUpdatedEvent::class, TextDocumentContentListener::class);
});
}

$context->injectFn(function (IManager $shareManager) {
$shareManager->registerShareProvider(DeckShareProvider::class);
});
Expand Down Expand Up @@ -191,6 +201,8 @@ public function register(IRegistrationContext $context): void {
$context->registerTeamResourceProvider(DeckTeamResourceProvider::class);

$context->registerUserMigrator(DeckMigrator::class);

$context->registerEventListener(RegisterContextEvent::class, RegisterTextContextEventListener::class);
}

public function registerCommentsEntity(IEventDispatcher $eventDispatcher): void {
Expand Down
33 changes: 33 additions & 0 deletions lib/Event/RegisterTextContextEventListener.php
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
);
}
}
46 changes: 46 additions & 0 deletions lib/Listeners/TextDocumentContentListener.php
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()))
);
}
}
134 changes: 134 additions & 0 deletions lib/Provider/TextContextProvider.php
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());
}

}
43 changes: 43 additions & 0 deletions lib/Provider/TextContextProviderFactory.php
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,
);
}
}
Loading
Loading