Skip to content

Commit 8cb70f3

Browse files
committed
Conversations in Unified Search
Signed-off-by: Joas Schilling <[email protected]>
1 parent 9f46cbd commit 8cb70f3

File tree

5 files changed

+226
-0
lines changed

5 files changed

+226
-0
lines changed

css/unified-search.scss

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.unified-search {
2+
.conversation-icon {
3+
background-color: var(--color-background-darker);
4+
background-size: 22px !important;
5+
6+
// We always want to use the white icons, this is why we don't use var(--color-white) here.
7+
&.icon-public {
8+
background-image: url(icon-color-path('public', 'actions', 'fff', 1, true));
9+
}
10+
&.icon-contacts {
11+
background-image: url(icon-color-path('contacts', 'places', 'fff', 1, true));
12+
}
13+
&.icon-password {
14+
background-image: url(icon-color-path('password', 'actions', 'fff', 1, true));
15+
}
16+
&.icon-file {
17+
background-image: url(icon-color-path('text', 'filetypes', 'fff', 1, true));
18+
}
19+
&.icon-mail {
20+
background-image: url(icon-color-path('mail', 'actions', 'fff', 1, true));
21+
}
22+
}
23+
}

lib/AppInfo/Application.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
namespace OCA\Talk\AppInfo;
2525

26+
use OC\Core\Controller\UnifiedSearchController;
2627
use OCA\Files_Sharing\Event\BeforeTemplateRenderedEvent;
2728
use OCA\Talk\Activity\Listener as ActivityListener;
2829
use OCA\Talk\Capabilities;
@@ -53,6 +54,8 @@
5354
use OCA\Talk\PublicShareAuth\Listener as PublicShareAuthListener;
5455
use OCA\Talk\PublicShareAuth\TemplateLoader as PublicShareAuthTemplateLoader;
5556
use OCA\Talk\Room;
57+
use OCA\Talk\Search\ConversationSearch;
58+
use OCA\Talk\Search\UnifiedSearchCSSLoader;
5659
use OCA\Talk\Settings\Personal;
5760
use OCA\Talk\Share\Listener as ShareListener;
5861
use OCA\Talk\Share\RoomShareProvider;
@@ -90,6 +93,9 @@ public function register(IRegistrationContext $context): void {
9093
$context->registerEventListener(BeforeUserLoggedOutEvent::class, BeforeUserLoggedOutListener::class);
9194
$context->registerEventListener(BeforeTemplateRenderedEvent::class, PublicShareTemplateLoader::class);
9295
$context->registerEventListener(BeforeTemplateRenderedEvent::class, PublicShareAuthTemplateLoader::class);
96+
$context->registerEventListener(\OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent::class, UnifiedSearchCSSLoader::class);
97+
98+
$context->registerSearchProvider(ConversationSearch::class);
9399
}
94100

95101
public function boot(IBootContext $context): void {

lib/Search/ConversationSearch.php

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2020 Joas Schilling <[email protected]>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
namespace OCA\Talk\Search;
25+
26+
use OCA\Talk\Manager;
27+
use OCA\Talk\Room;
28+
use OCP\IL10N;
29+
use OCP\IURLGenerator;
30+
use OCP\IUser;
31+
use OCP\Search\IProvider;
32+
use OCP\Search\ISearchQuery;
33+
use OCP\Search\SearchResult;
34+
35+
class ConversationSearch implements IProvider {
36+
37+
/** @var Manager */
38+
protected $manager;
39+
/** @var IURLGenerator */
40+
protected $url;
41+
/** @var IL10N */
42+
protected $l;
43+
44+
public function __construct(
45+
Manager $manager,
46+
IURLGenerator $url,
47+
IL10N $l
48+
) {
49+
$this->manager = $manager;
50+
$this->url = $url;
51+
$this->l = $l;
52+
}
53+
54+
/**
55+
* @inheritDoc
56+
*/
57+
public function getId(): string {
58+
return 'talk_conversations';
59+
}
60+
61+
/**
62+
* @inheritDoc
63+
*/
64+
public function getName(): string {
65+
return $this->l->t('Conversations');
66+
}
67+
68+
/**
69+
* @inheritDoc
70+
*/
71+
public function search(IUser $user, ISearchQuery $query): SearchResult {
72+
$rooms = $this->manager->getRoomsForParticipant($user->getUID());
73+
74+
$result = [];
75+
foreach ($rooms as $room) {
76+
if (
77+
$room->getType() === Room::CHANGELOG_CONVERSATION || (
78+
stripos($room->getName(), $query->getTerm()) === false &&
79+
stripos($room->getDisplayName($user->getUID()), $query->getTerm()) === false
80+
)
81+
) {
82+
continue;
83+
}
84+
85+
$icon = '';
86+
$iconClass = '';
87+
if ($room->getType() === Room::ONE_TO_ONE_CALL) {
88+
$users = $room->getParticipantUserIds();
89+
foreach ($users as $participantId) {
90+
if ($participantId !== $user->getUID()) {
91+
$icon = $this->url->linkToRouteAbsolute('core.avatar.getAvatar', [
92+
'userId' => $participantId,
93+
'size' => 128,
94+
]);
95+
}
96+
}
97+
} else if ($room->getObjectType() === 'file') {
98+
$iconClass = 'conversation-icon icon-file';
99+
} else if ($room->getObjectType() === 'share:password') {
100+
$iconClass = 'conversation-icon icon-password';
101+
} else if ($room->getObjectType() === 'emails') {
102+
$iconClass = 'conversation-icon icon-mail';
103+
} else if ($room->getType() === Room::PUBLIC_CALL) {
104+
$iconClass = 'conversation-icon icon-public';
105+
} else{
106+
$iconClass = 'conversation-icon icon-contacts';
107+
}
108+
109+
$result[] = new ConversationSearchResult(
110+
$icon,
111+
$room->getDisplayName($user->getUID()),
112+
'',
113+
$this->url->linkToRouteAbsolute('spreed.Page.showCall', ['token' => $room->getToken()]),
114+
$iconClass,
115+
true
116+
);
117+
}
118+
119+
return SearchResult::complete(
120+
$this->l->t('Conversations'),
121+
$result
122+
);
123+
}
124+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2020 Joas Schilling <[email protected]>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
namespace OCA\Talk\Search;
25+
26+
use OCP\Search\ASearchResultEntry;
27+
28+
class ConversationSearchResult extends ASearchResultEntry {
29+
30+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2020 Joas Schilling <[email protected]>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
namespace OCA\Talk\Search;
25+
26+
use OCA\Talk\AppInfo\Application;
27+
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
28+
use OCP\EventDispatcher\Event;
29+
use OCP\EventDispatcher\IEventListener;
30+
use OCP\Util;
31+
32+
class UnifiedSearchCSSLoader implements IEventListener {
33+
34+
public function handle(Event $event): void {
35+
if (!$event instanceof BeforeTemplateRenderedEvent) {
36+
return;
37+
}
38+
39+
if ($event->isLoggedIn()) {
40+
Util::addStyle(Application::APP_ID, 'unified-search');
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)