diff options
author | Julien Veyssier <julien-nc@posteo.net> | 2023-01-12 15:47:20 +0100 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2023-01-27 11:10:56 +0100 |
commit | 946a1af9fd20d12a2ee6240ad2ae24827a22278c (patch) | |
tree | d7add9a58d1d7830d3c6948c167b32902a52b5ec /lib/private/Collaboration | |
parent | 6431c5a559a1361ae9148adf22b21630b8a37431 (diff) | |
download | nextcloud-server-946a1af9fd20d12a2ee6240ad2ae24827a22278c.tar.gz nextcloud-server-946a1af9fd20d12a2ee6240ad2ae24827a22278c.zip |
add 'last used timestamp' management for reference providers
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
Diffstat (limited to 'lib/private/Collaboration')
3 files changed, 58 insertions, 5 deletions
diff --git a/lib/private/Collaboration/Reference/File/FileReferenceEventListener.php b/lib/private/Collaboration/Reference/File/FileReferenceEventListener.php index 6ccae9903dc..ae50f769665 100644 --- a/lib/private/Collaboration/Reference/File/FileReferenceEventListener.php +++ b/lib/private/Collaboration/Reference/File/FileReferenceEventListener.php @@ -31,6 +31,7 @@ use OCP\Files\Events\Node\NodeDeletedEvent; use OCP\Share\Events\ShareCreatedEvent; use OCP\Share\Events\ShareDeletedEvent; +/** @psalm-implements IEventDispatcher<Event|NodeDeletedEvent|ShareDeletedEvent|ShareCreatedEvent> */ class FileReferenceEventListener implements \OCP\EventDispatcher\IEventListener { private IReferenceManager $manager; diff --git a/lib/private/Collaboration/Reference/ReferenceManager.php b/lib/private/Collaboration/Reference/ReferenceManager.php index 1b00b9325ca..381f3aea8f4 100644 --- a/lib/private/Collaboration/Reference/ReferenceManager.php +++ b/lib/private/Collaboration/Reference/ReferenceManager.php @@ -33,7 +33,9 @@ use OCP\Collaboration\Reference\IReferenceProvider; use OCP\Collaboration\Reference\Reference; use OCP\ICache; use OCP\ICacheFactory; +use OCP\IConfig; use OCP\IURLGenerator; +use OCP\IUserSession; use Psr\Container\ContainerInterface; use Psr\Log\LoggerInterface; use Throwable; @@ -48,13 +50,23 @@ class ReferenceManager implements IReferenceManager { private ContainerInterface $container; private LinkReferenceProvider $linkReferenceProvider; private LoggerInterface $logger; + private IConfig $config; + private IUserSession $userSession; - public function __construct(LinkReferenceProvider $linkReferenceProvider, ICacheFactory $cacheFactory, Coordinator $coordinator, ContainerInterface $container, LoggerInterface $logger) { + public function __construct(LinkReferenceProvider $linkReferenceProvider, + ICacheFactory $cacheFactory, + Coordinator $coordinator, + ContainerInterface $container, + LoggerInterface $logger, + IConfig $config, + IUserSession $userSession) { $this->linkReferenceProvider = $linkReferenceProvider; $this->cache = $cacheFactory->createDistributed('reference'); $this->coordinator = $coordinator; $this->container = $container; $this->logger = $logger; + $this->config = $config; + $this->userSession = $userSession; } /** @@ -216,10 +228,7 @@ class ReferenceManager implements IReferenceManager { } /** - * Get information on discoverable reference providers (id, title, icon and order) - * If the provider is searchable, also get the list of supported unified search providers - * - * @return IDiscoverableReferenceProvider[] + * @inheritDoc */ public function getDiscoverableProviders(): array { // preserve 0 based index to avoid returning an object in data responses @@ -229,4 +238,44 @@ class ReferenceManager implements IReferenceManager { }) ); } + + /** + * @inheritDoc + */ + public function touchProvider(string $userId, string $providerId, ?int $timestamp = null): void { + $providers = $this->getDiscoverableProviders(); + $providerIds = array_map(static function (IDiscoverableReferenceProvider $provider) { + return $provider->getId(); + }, $providers); + if (array_search($providerId, $providerIds, true) !== false) { + $configKey = 'provider-last-use_' . $providerId; + if ($timestamp === null) { + $timestamp = time(); + } + + $this->config->setUserValue($userId, 'references', $configKey, (string) $timestamp); + } + } + + /** + * @inheritDoc + */ + public function getUserProviderTimestamps(): array { + $user = $this->userSession->getUser(); + if ($user === null) { + return []; + } + $userId = $user->getUID(); + $keys = $this->config->getUserKeys($userId, 'references'); + $keys = array_filter($keys, static function (string $key) { + return preg_match('/^provider-last-use_/', $key) !== false; + }); + $timestamps = []; + foreach ($keys as $key) { + $providerId = preg_replace('/^provider-last-use_/', '', $key); + $timestamp = (int) $this->config->getUserValue($userId, 'references', $key); + $timestamps[$providerId] = $timestamp; + } + return $timestamps; + } } diff --git a/lib/private/Collaboration/Reference/RenderReferenceEventListener.php b/lib/private/Collaboration/Reference/RenderReferenceEventListener.php index 172dca3d7f2..f23aae92afa 100644 --- a/lib/private/Collaboration/Reference/RenderReferenceEventListener.php +++ b/lib/private/Collaboration/Reference/RenderReferenceEventListener.php @@ -58,5 +58,8 @@ class RenderReferenceEventListener implements IEventListener { return $provider->jsonSerialize(); }, $providers); $this->initialStateService->provideInitialState('core', 'reference-provider-list', $jsonProviders); + + $timestamps = $this->manager->getUserProviderTimestamps(); + $this->initialStateService->provideInitialState('core', 'reference-provider-timestamps', $timestamps); } } |