diff options
author | Joas Schilling <coding@schilljs.com> | 2020-07-30 17:01:33 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2020-08-03 16:43:37 +0300 |
commit | f89c938663f0391968dd8e9fdadd62f43e66d3d3 (patch) | |
tree | d92a3d50af35d4528bb8cd5c3cf9f674d6361e70 /lib | |
parent | 9f46cbd00afb136de66297d6beb292e338e6d799 (diff) |
Conversations in Unified Search
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AppInfo/Application.php | 5 | ||||
-rw-r--r-- | lib/Search/ConversationSearch.php | 124 | ||||
-rw-r--r-- | lib/Search/ConversationSearchResult.php | 29 | ||||
-rw-r--r-- | lib/Search/UnifiedSearchCSSLoader.php | 42 |
4 files changed, 200 insertions, 0 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index ade710667..d7d3be81a 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -53,6 +53,8 @@ use OCA\Talk\PublicShare\TemplateLoader as PublicShareTemplateLoader; use OCA\Talk\PublicShareAuth\Listener as PublicShareAuthListener; use OCA\Talk\PublicShareAuth\TemplateLoader as PublicShareAuthTemplateLoader; use OCA\Talk\Room; +use OCA\Talk\Search\ConversationSearch; +use OCA\Talk\Search\UnifiedSearchCSSLoader; use OCA\Talk\Settings\Personal; use OCA\Talk\Share\Listener as ShareListener; use OCA\Talk\Share\RoomShareProvider; @@ -90,6 +92,9 @@ class Application extends App implements IBootstrap { $context->registerEventListener(BeforeUserLoggedOutEvent::class, BeforeUserLoggedOutListener::class); $context->registerEventListener(BeforeTemplateRenderedEvent::class, PublicShareTemplateLoader::class); $context->registerEventListener(BeforeTemplateRenderedEvent::class, PublicShareAuthTemplateLoader::class); + $context->registerEventListener(\OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent::class, UnifiedSearchCSSLoader::class); + + $context->registerSearchProvider(ConversationSearch::class); } public function boot(IBootContext $context): void { diff --git a/lib/Search/ConversationSearch.php b/lib/Search/ConversationSearch.php new file mode 100644 index 000000000..040e60ef1 --- /dev/null +++ b/lib/Search/ConversationSearch.php @@ -0,0 +1,124 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com> + * + * @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\Talk\Search; + +use OCA\Talk\Manager; +use OCA\Talk\Room; +use OCP\IL10N; +use OCP\IURLGenerator; +use OCP\IUser; +use OCP\Search\IProvider; +use OCP\Search\ISearchQuery; +use OCP\Search\SearchResult; + +class ConversationSearch implements IProvider { + + /** @var Manager */ + protected $manager; + /** @var IURLGenerator */ + protected $url; + /** @var IL10N */ + protected $l; + + public function __construct( + Manager $manager, + IURLGenerator $url, + IL10N $l + ) { + $this->manager = $manager; + $this->url = $url; + $this->l = $l; + } + + /** + * @inheritDoc + */ + public function getId(): string { + return 'talk_conversations'; + } + + /** + * @inheritDoc + */ + public function getName(): string { + return $this->l->t('Conversations'); + } + + /** + * @inheritDoc + */ + public function search(IUser $user, ISearchQuery $query): SearchResult { + $rooms = $this->manager->getRoomsForParticipant($user->getUID()); + + $result = []; + foreach ($rooms as $room) { + if ( + $room->getType() === Room::CHANGELOG_CONVERSATION || ( + stripos($room->getName(), $query->getTerm()) === false && + stripos($room->getDisplayName($user->getUID()), $query->getTerm()) === false + ) + ) { + continue; + } + + $icon = ''; + $iconClass = ''; + if ($room->getType() === Room::ONE_TO_ONE_CALL) { + $users = $room->getParticipantUserIds(); + foreach ($users as $participantId) { + if ($participantId !== $user->getUID()) { + $icon = $this->url->linkToRouteAbsolute('core.avatar.getAvatar', [ + 'userId' => $participantId, + 'size' => 128, + ]); + } + } + } elseif ($room->getObjectType() === 'file') { + $iconClass = 'conversation-icon icon-file'; + } elseif ($room->getObjectType() === 'share:password') { + $iconClass = 'conversation-icon icon-password'; + } elseif ($room->getObjectType() === 'emails') { + $iconClass = 'conversation-icon icon-mail'; + } elseif ($room->getType() === Room::PUBLIC_CALL) { + $iconClass = 'conversation-icon icon-public'; + } else { + $iconClass = 'conversation-icon icon-contacts'; + } + + $result[] = new ConversationSearchResult( + $icon, + $room->getDisplayName($user->getUID()), + '', + $this->url->linkToRouteAbsolute('spreed.Page.showCall', ['token' => $room->getToken()]), + $iconClass, + true + ); + } + + return SearchResult::complete( + $this->l->t('Conversations'), + $result + ); + } +} diff --git a/lib/Search/ConversationSearchResult.php b/lib/Search/ConversationSearchResult.php new file mode 100644 index 000000000..86dfca62a --- /dev/null +++ b/lib/Search/ConversationSearchResult.php @@ -0,0 +1,29 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com> + * + * @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\Talk\Search; + +use OCP\Search\ASearchResultEntry; + +class ConversationSearchResult extends ASearchResultEntry { +} diff --git a/lib/Search/UnifiedSearchCSSLoader.php b/lib/Search/UnifiedSearchCSSLoader.php new file mode 100644 index 000000000..ebacc7673 --- /dev/null +++ b/lib/Search/UnifiedSearchCSSLoader.php @@ -0,0 +1,42 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com> + * + * @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\Talk\Search; + +use OCA\Talk\AppInfo\Application; +use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\Util; + +class UnifiedSearchCSSLoader implements IEventListener { + public function handle(Event $event): void { + if (!$event instanceof BeforeTemplateRenderedEvent) { + return; + } + + if ($event->isLoggedIn()) { + Util::addStyle(Application::APP_ID, 'unified-search'); + } + } +} |