diff options
Diffstat (limited to 'apps/files_reminders/lib/Dav/PropFindPlugin.php')
-rw-r--r-- | apps/files_reminders/lib/Dav/PropFindPlugin.php | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/apps/files_reminders/lib/Dav/PropFindPlugin.php b/apps/files_reminders/lib/Dav/PropFindPlugin.php index 8bb88170013..7fa45a4b854 100644 --- a/apps/files_reminders/lib/Dav/PropFindPlugin.php +++ b/apps/files_reminders/lib/Dav/PropFindPlugin.php @@ -10,11 +10,13 @@ declare(strict_types=1); namespace OCA\FilesReminders\Dav; use DateTimeInterface; +use OCA\DAV\Connector\Sabre\Directory; use OCA\DAV\Connector\Sabre\Node; use OCA\FilesReminders\Service\ReminderService; -use OCP\AppFramework\Db\DoesNotExistException; +use OCP\Files\Folder; use OCP\IUser; use OCP\IUserSession; +use Sabre\DAV\ICollection; use Sabre\DAV\INode; use Sabre\DAV\PropFind; use Sabre\DAV\Server; @@ -31,9 +33,22 @@ class PropFindPlugin extends ServerPlugin { } public function initialize(Server $server): void { + $server->on('preloadCollection', $this->preloadCollection(...)); $server->on('propFind', [$this, 'propFind']); } + private function preloadCollection( + PropFind $propFind, + ICollection $collection, + ): void { + if ($collection instanceof Directory && $propFind->getStatus( + static::REMINDER_DUE_DATE_PROPERTY + ) !== null) { + $folder = $collection->getNode(); + $this->cacheFolder($folder); + } + } + public function propFind(PropFind $propFind, INode $node) { if (!in_array(static::REMINDER_DUE_DATE_PROPERTY, $propFind->getRequestedProperties())) { return; @@ -52,9 +67,8 @@ class PropFindPlugin extends ServerPlugin { } $fileId = $node->getId(); - try { - $reminder = $this->reminderService->getDueForUser($user, $fileId); - } catch (DoesNotExistException $e) { + $reminder = $this->reminderService->getDueForUser($user, $fileId, false); + if ($reminder === null) { return ''; } @@ -62,4 +76,12 @@ class PropFindPlugin extends ServerPlugin { }, ); } + + private function cacheFolder(Folder $folder): void { + $user = $this->userSession->getUser(); + if (!($user instanceof IUser)) { + return; + } + $this->reminderService->cacheFolder($user, $folder); + } } |