-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(backend): Reset document session when updated from outside editor
When a text file is updated via other means than from the editor (e.g. when uploaded/synced via webdav) and there is no unsaved steps in the document session, reset the document session This will prevent conflict resolution dialogs in this case. Client frontends will have to reload the document afterwards though. Signed-off-by: Jonas <[email protected]>
- Loading branch information
Showing
5 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2024 Jonas <[email protected]> | ||
* | ||
* @author Jonas <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OCA\Text\Listeners; | ||
|
||
use OCA\Text\Service\DocumentService; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
use OCP\Files\Events\Node\BeforeNodeWrittenEvent; | ||
use OCP\Files\File; | ||
|
||
/** | ||
* @template-implements IEventListener<Event|BeforeNodeWrittenEvent> | ||
*/ | ||
class BeforeNodeWrittenListener implements IEventListener { | ||
private DocumentService $documentService; | ||
|
||
public function __construct(DocumentService $documentService) { | ||
$this->documentService = $documentService; | ||
} | ||
|
||
public function handle(Event $event): void { | ||
if (!$event instanceof BeforeNodeWrittenEvent) { | ||
return; | ||
} | ||
$node = $event->getNode(); | ||
if ($node instanceof File && $node->getMimeType() === 'text/markdown') { | ||
if (!$this->documentService->isSaveFromText()) { | ||
// Reset document session to avoid manual conflict resolution if there's no unsaved steps | ||
$this->documentService->resetDocument($node->getId()); | ||
} | ||
} | ||
} | ||
} |
This file contains 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