diff --git a/CHANGELOG.md b/CHANGELOG.md index 75e9c01b9d..357ab6cd19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ All notable changes to this project will be documented in this file. - Delete polls without the need to archive them first - Collapsible poll description - Transfer polls to another owner by the current poll owner or the administration - - Added reference provider for link previews + - Added reference provider for link previews and smart picker ## [7.4.1] - 2024-03-07 ### New diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index b6bb3b2605..d92633f54e 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -48,6 +48,7 @@ use OCA\Polls\Listener\GroupDeletedListener; use OCA\Polls\Listener\OptionListener; use OCA\Polls\Listener\PollListener; +use OCA\Polls\Listener\PollsReferenceListener; use OCA\Polls\Listener\ShareListener; use OCA\Polls\Listener\UserDeletedListener; use OCA\Polls\Listener\VoteListener; @@ -55,13 +56,14 @@ use OCA\Polls\Model\Settings\AppSettings; use OCA\Polls\Model\Settings\SystemSettings; use OCA\Polls\Notification\Notifier; +use OCA\Polls\Provider\ReferenceProvider; use OCA\Polls\Provider\SearchProvider; -use OCA\Polls\Reference\PollReferenceProvider; use OCA\Polls\UserSession; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; +use OCP\Collaboration\Reference\RenderReferenceEvent; use OCP\Group\Events\GroupDeletedEvent; use OCP\IAppConfig; use OCP\IDBConnection; @@ -89,6 +91,7 @@ public function register(IRegistrationContext $context): void { include_once __DIR__ . '/../../vendor/autoload.php'; $this->registerServices($context); + $context->registerEventListener(RenderReferenceEvent::class, PollsReferenceListener::class); $context->registerMiddleWare(RequestAttributesMiddleware::class); $context->registerNotifierService(Notifier::class); @@ -128,7 +131,8 @@ public function register(IRegistrationContext $context): void { $context->registerSearchProvider(SearchProvider::class); $context->registerDashboardWidget(PollWidget::class); - $context->registerReferenceProvider(PollReferenceProvider::class); + $context->registerReferenceProvider(ReferenceProvider::class); + } /** diff --git a/lib/Listener/PollsReferenceListener.php b/lib/Listener/PollsReferenceListener.php new file mode 100644 index 0000000000..4fbb07ee36 --- /dev/null +++ b/lib/Listener/PollsReferenceListener.php @@ -0,0 +1,28 @@ + + */ +class PollsReferenceListener implements IEventListener { + public function handle(Event $event): void { + if (!$event instanceof RenderReferenceEvent) { + return; + } + + Util::addScript(Application::APP_ID, 'polls-reference'); + } +} diff --git a/lib/Reference/PollReferenceProvider.php b/lib/Provider/ReferenceProvider.php similarity index 75% rename from lib/Reference/PollReferenceProvider.php rename to lib/Provider/ReferenceProvider.php index a043d9722d..501fe606ee 100644 --- a/lib/Reference/PollReferenceProvider.php +++ b/lib/Provider/ReferenceProvider.php @@ -6,20 +6,21 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace OCA\Polls\Reference; +namespace OCA\Polls\Provider; use Exception; use OCA\Polls\AppInfo\Application; use OCA\Polls\Exceptions\ForbiddenException; use OCA\Polls\Exceptions\NotFoundException; use OCA\Polls\Service\PollService; +use OCP\Collaboration\Reference\ADiscoverableReferenceProvider; use OCP\Collaboration\Reference\IReference; -use OCP\Collaboration\Reference\IReferenceProvider; +use OCP\Collaboration\Reference\ISearchableReferenceProvider; use OCP\Collaboration\Reference\Reference; use OCP\IL10N; use OCP\IURLGenerator; -class PollReferenceProvider implements IReferenceProvider { +class ReferenceProvider extends ADiscoverableReferenceProvider implements ISearchableReferenceProvider { /** @psalm-suppress PossiblyUnusedMethod */ public function __construct( @@ -38,7 +39,7 @@ public function matchReference(string $referenceText): bool { return ($this->extractPollId($referenceText) !== 0); } - private function extractPollId($referenceText): int { + public function extractPollId(string $referenceText): int { $matchingUrls = [ $this->urlGenerator->getAbsoluteURL('/apps/' . Application::APP_ID . '/vote'), // poll url base without index.php $this->urlGenerator->getAbsoluteURL('/index.php/apps/' . Application::APP_ID . '/vote'), // poll url base with index.php @@ -60,6 +61,10 @@ private function extractPollId($referenceText): int { public function resolveReference(string $referenceText): ?IReference { if ($this->matchReference($referenceText)) { $pollId = $this->extractPollId($referenceText); + $expired = false; + $expiry = 0; + $participated = false; + if ($pollId) { try { @@ -69,6 +74,9 @@ public function resolveReference(string $referenceText): ?IReference { $ownerId = $poll->getUser()->getId(); $ownerDisplayName = $poll->getUser()->getDisplayName(); $url = $poll->getVoteUrl(); + $expired = $poll->getExpired(); + $expiry = $poll->getExpire(); + $participated = $poll->getCurrentUserVotes() ? true : false; } catch (NotFoundException $e) { $pollId = 0; @@ -91,15 +99,11 @@ public function resolveReference(string $referenceText): ?IReference { return null; } - $imageUrl = $this->urlGenerator->getAbsoluteURL( - $this->urlGenerator->imagePath(Application::APP_ID, 'polls.svg') - ); - $reference = new Reference($referenceText); $reference->setTitle($title); $reference->setDescription($description ? $description : $this->l10n->t('No description available.')); - $reference->setImageUrl($imageUrl); - $reference->setRichObject(Application::APP_ID . '_poll_widget', [ + $reference->setImageUrl($this->getIconUrl()); + $reference->setRichObject(Application::APP_ID . '_reference_widget', [ 'id' => $pollId, 'poll' => [ 'id' => $pollId, @@ -108,6 +112,9 @@ public function resolveReference(string $referenceText): ?IReference { 'ownerDisplayName' => $ownerDisplayName, 'ownerId' => $ownerId, 'url' => $url, + 'expired' => $expired, + 'expiry' => $expiry, + 'participated' => $participated, ], ]); return $reference; @@ -129,4 +136,22 @@ public function getCachePrefix(string $referenceId): string { public function getCacheKey(string $referenceId): ?string { return $this->userId ?? ''; } + public function getId(): string { + return Application::APP_ID; + } + public function getTitle(): string { + return $this->l10n->t('Poll'); + } + + public function getIconUrl(): string { + return $this->urlGenerator->imagePath(Application::APP_ID, 'polls.svg'); + } + + public function getOrder(): int { + return 51; + } + + public function getSupportedSearchProviderIds(): array { + return ['search-poll']; + } } diff --git a/lib/Provider/SearchProvider.php b/lib/Provider/SearchProvider.php index b09d9cd27d..eafb65814a 100644 --- a/lib/Provider/SearchProvider.php +++ b/lib/Provider/SearchProvider.php @@ -31,7 +31,7 @@ public function __construct( } public function getId(): string { - return 'poll'; + return 'search-poll'; } public function getName(): string { diff --git a/src/components/PollList/PollItem.vue b/src/components/PollList/PollItem.vue index 219a5b7185..cbb5f707c0 100644 --- a/src/components/PollList/PollItem.vue +++ b/src/components/PollList/PollItem.vue @@ -6,7 +6,7 @@ + + + + diff --git a/vite.config.js b/vite.config.js index d337c0a1e9..346f90c681 100644 --- a/vite.config.js +++ b/vite.config.js @@ -25,6 +25,7 @@ export default createAppConfig( userSettings: resolve(join('src', 'userSettings.ts')), adminSettings: resolve(join('src', 'adminSettings.ts')), dashboard: resolve(join('src', 'dashboard.ts')), + reference: resolve(join('src', 'polls-reference.ts')), }, { inlineCSS: { relativeCSSInjection: true },