Skip to content

Commit 2b8114d

Browse files
committed
feat(events): Add typed event for filtering autocompletion suggestions
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent d779092 commit 2b8114d

File tree

5 files changed

+123
-0
lines changed

5 files changed

+123
-0
lines changed

core/Controller/AutoCompleteController.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use OCP\AppFramework\Http\DataResponse;
3636
use OCP\AppFramework\OCSController;
3737
use OCP\Collaboration\AutoComplete\AutoCompleteEvent;
38+
use OCP\Collaboration\AutoComplete\AutoCompleteFilterEvent;
3839
use OCP\Collaboration\AutoComplete\IManager;
3940
use OCP\Collaboration\Collaborators\ISearch;
4041
use OCP\EventDispatcher\IEventDispatcher;
@@ -88,6 +89,18 @@ public function get(string $search, ?string $itemType, ?string $itemId, ?string
8889
$this->dispatcher->dispatch(IManager::class . '::filterResults', $event);
8990
$results = $event->getResults();
9091

92+
$event = new AutoCompleteFilterEvent(
93+
$results,
94+
$search,
95+
$itemType,
96+
$itemId,
97+
$sorter,
98+
$shareTypes,
99+
$limit,
100+
);
101+
$this->dispatcher->dispatchTyped($event);
102+
$results = $event->getResults();
103+
91104
$exactMatches = $results['exact'];
92105
unset($results['exact']);
93106
$results = array_merge_recursive($exactMatches, $results);

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@
169169
'OCP\\Capabilities\\IInitialStateExcludedCapability' => $baseDir . '/lib/public/Capabilities/IInitialStateExcludedCapability.php',
170170
'OCP\\Capabilities\\IPublicCapability' => $baseDir . '/lib/public/Capabilities/IPublicCapability.php',
171171
'OCP\\Collaboration\\AutoComplete\\AutoCompleteEvent' => $baseDir . '/lib/public/Collaboration/AutoComplete/AutoCompleteEvent.php',
172+
'OCP\\Collaboration\\AutoComplete\\AutoCompleteFilterEvent' => $baseDir . '/lib/public/Collaboration/AutoComplete/AutoCompleteFilterEvent.php',
172173
'OCP\\Collaboration\\AutoComplete\\IManager' => $baseDir . '/lib/public/Collaboration/AutoComplete/IManager.php',
173174
'OCP\\Collaboration\\AutoComplete\\ISorter' => $baseDir . '/lib/public/Collaboration/AutoComplete/ISorter.php',
174175
'OCP\\Collaboration\\Collaborators\\ISearch' => $baseDir . '/lib/public/Collaboration/Collaborators/ISearch.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
202202
'OCP\\Capabilities\\IInitialStateExcludedCapability' => __DIR__ . '/../../..' . '/lib/public/Capabilities/IInitialStateExcludedCapability.php',
203203
'OCP\\Capabilities\\IPublicCapability' => __DIR__ . '/../../..' . '/lib/public/Capabilities/IPublicCapability.php',
204204
'OCP\\Collaboration\\AutoComplete\\AutoCompleteEvent' => __DIR__ . '/../../..' . '/lib/public/Collaboration/AutoComplete/AutoCompleteEvent.php',
205+
'OCP\\Collaboration\\AutoComplete\\AutoCompleteFilterEvent' => __DIR__ . '/../../..' . '/lib/public/Collaboration/AutoComplete/AutoCompleteFilterEvent.php',
205206
'OCP\\Collaboration\\AutoComplete\\IManager' => __DIR__ . '/../../..' . '/lib/public/Collaboration/AutoComplete/IManager.php',
206207
'OCP\\Collaboration\\AutoComplete\\ISorter' => __DIR__ . '/../../..' . '/lib/public/Collaboration/AutoComplete/ISorter.php',
207208
'OCP\\Collaboration\\Collaborators\\ISearch' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Collaborators/ISearch.php',

lib/public/Collaboration/AutoComplete/AutoCompleteEvent.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
/**
3131
* @since 16.0.0
32+
* @deprecated Use {@see AutoCompleteFilterEvent} instead
3233
*/
3334
class AutoCompleteEvent extends GenericEvent {
3435
/**
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2023 Joas Schilling <coding@schilljs.com>
7+
*
8+
* @author Joas Schilling <coding@schilljs.com>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
namespace OCP\Collaboration\AutoComplete;
27+
28+
use OCP\EventDispatcher\Event;
29+
30+
/**
31+
* @since 28.0.0
32+
*/
33+
class AutoCompleteFilterEvent extends Event {
34+
/**
35+
* @since 28.0.0
36+
*/
37+
public function __construct(
38+
protected array $results,
39+
protected string $search,
40+
protected ?string $itemType,
41+
protected ?string $itemId,
42+
protected ?string $sorter,
43+
protected array $shareTypes,
44+
protected int $limit,
45+
) {
46+
parent::__construct();
47+
}
48+
49+
/**
50+
* @since 28.0.0
51+
*/
52+
public function getResults(): array {
53+
return $this->results;
54+
}
55+
56+
/**
57+
* @param array $results
58+
* @since 28.0.0
59+
*/
60+
public function setResults(array $results): void {
61+
$this->results = $results;
62+
}
63+
64+
/**
65+
* @since 28.0.0
66+
*/
67+
public function getSearchTerm(): string {
68+
return $this->search;
69+
}
70+
71+
/**
72+
* @return int[] List of `\OCP\Share\IShare::TYPE_*` constants
73+
* @since 28.0.0
74+
*/
75+
public function getShareTypes(): array {
76+
return $this->shareTypes;
77+
}
78+
79+
/**
80+
* @since 28.0.0
81+
*/
82+
public function getItemType(): ?string {
83+
return $this->itemType;
84+
}
85+
86+
/**
87+
* @since 28.0.0
88+
*/
89+
public function getItemId(): ?string {
90+
return $this->itemId;
91+
}
92+
93+
/**
94+
* @return ?string List of desired sort identifiers, top priority first. When multiple are given they are joined with a pipe: `commenters|share-recipients`
95+
* @since 28.0.0
96+
*/
97+
public function getSorter(): ?string {
98+
return $this->sorter;
99+
}
100+
101+
/**
102+
* @since 28.0.0
103+
*/
104+
public function getLimit(): int {
105+
return $this->limit;
106+
}
107+
}

0 commit comments

Comments
 (0)