diff options
Diffstat (limited to 'core/Controller/AutoCompleteController.php')
-rw-r--r-- | core/Controller/AutoCompleteController.php | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/core/Controller/AutoCompleteController.php b/core/Controller/AutoCompleteController.php index 29a0788ad57..15b78e53dc0 100644 --- a/core/Controller/AutoCompleteController.php +++ b/core/Controller/AutoCompleteController.php @@ -30,6 +30,8 @@ declare(strict_types=1); */ namespace OC\Core\Controller; +use OCA\Core\ResponseDefinitions; +use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCSController; use OCP\Collaboration\AutoComplete\AutoCompleteEvent; @@ -39,6 +41,9 @@ use OCP\EventDispatcher\IEventDispatcher; use OCP\IRequest; use OCP\Share\IShare; +/** + * @psalm-import-type CoreAutocompleteResult from ResponseDefinitions + */ class AutoCompleteController extends OCSController { public function __construct( string $appName, @@ -52,7 +57,17 @@ class AutoCompleteController extends OCSController { /** * @NoAdminRequired + * + * Autocomplete a query + * + * @param string $search Text to search for + * @param string|null $itemType Type of the items to search for + * @param string|null $itemId ID of the items to search for * @param string|null $sorter can be piped, top prio first, e.g.: "commenters|share-recipients" + * @param int[] $shareTypes Types of shares to search for + * @param int $limit Maximum number of results to return + * + * @return DataResponse<Http::STATUS_OK, CoreAutocompleteResult[], array{}> */ public function get(string $search, ?string $itemType, ?string $itemId, ?string $sorter = null, array $shareTypes = [IShare::TYPE_USER], int $limit = 10): DataResponse { // if enumeration/user listings are disabled, we'll receive an empty @@ -89,18 +104,37 @@ class AutoCompleteController extends OCSController { return new DataResponse($results); } + /** + * @return CoreAutocompleteResult[] + */ protected function prepareResultArray(array $results): array { $output = []; + /** @var string $type */ foreach ($results as $type => $subResult) { foreach ($subResult as $result) { + /** @var ?string $icon */ + $icon = array_key_exists('icon', $result) ? $result['icon'] : null; + + /** @var string $label */ + $label = $result['label']; + + /** @var ?string $subline */ + $subline = array_key_exists('subline', $result) ? $result['subline'] : null; + + /** @var ?string $status */ + $status = array_key_exists('status', $result) && is_string($result['status']) ? $result['status'] : null; + + /** @var ?string $shareWithDisplayNameUnique */ + $shareWithDisplayNameUnique = array_key_exists('shareWithDisplayNameUnique', $result) ? $result['shareWithDisplayNameUnique'] : null; + $output[] = [ 'id' => (string) $result['value']['shareWith'], - 'label' => $result['label'], - 'icon' => $result['icon'] ?? '', + 'label' => $label, + 'icon' => $icon ?? '', 'source' => $type, - 'status' => $result['status'] ?? '', - 'subline' => $result['subline'] ?? '', - 'shareWithDisplayNameUnique' => $result['shareWithDisplayNameUnique'] ?? '', + 'status' => $status ?? '', + 'subline' => $subline ?? '', + 'shareWithDisplayNameUnique' => $shareWithDisplayNameUnique ?? '', ]; } } |