3030 */
3131namespace OC \Core \Controller ;
3232
33+ use OCA \Core \ResponseDefinitions ;
34+ use OCP \AppFramework \Http ;
3335use OCP \AppFramework \Http \DataResponse ;
3436use OCP \AppFramework \OCSController ;
3537use OCP \Collaboration \AutoComplete \AutoCompleteEvent ;
3941use OCP \IRequest ;
4042use OCP \Share \IShare ;
4143
44+ /**
45+ * @psalm-import-type CoreAutocompleteResult from ResponseDefinitions
46+ */
4247class AutoCompleteController extends OCSController {
4348 public function __construct (
4449 string $ appName ,
@@ -52,7 +57,17 @@ public function __construct(
5257
5358 /**
5459 * @NoAdminRequired
60+ *
61+ * Autocomplete a query
62+ *
63+ * @param string $search Text to search for
64+ * @param string|null $itemType Type of the items to search for
65+ * @param string|null $itemId ID of the items to search for
5566 * @param string|null $sorter can be piped, top prio first, e.g.: "commenters|share-recipients"
67+ * @param int[] $shareTypes Types of shares to search for
68+ * @param int $limit Maximum number of results to return
69+ *
70+ * @return DataResponse<Http::STATUS_OK, CoreAutocompleteResult[], array{}>
5671 */
5772 public function get (string $ search , ?string $ itemType , ?string $ itemId , ?string $ sorter = null , array $ shareTypes = [IShare::TYPE_USER ], int $ limit = 10 ): DataResponse {
5873 // if enumeration/user listings are disabled, we'll receive an empty
@@ -89,18 +104,37 @@ public function get(string $search, ?string $itemType, ?string $itemId, ?string
89104 return new DataResponse ($ results );
90105 }
91106
107+ /**
108+ * @return CoreAutocompleteResult[]
109+ */
92110 protected function prepareResultArray (array $ results ): array {
93111 $ output = [];
112+ /** @var string $type */
94113 foreach ($ results as $ type => $ subResult ) {
95114 foreach ($ subResult as $ result ) {
115+ /** @var ?string $icon */
116+ $ icon = array_key_exists ('icon ' , $ result ) ? $ result ['icon ' ] : null ;
117+
118+ /** @var string $label */
119+ $ label = $ result ['label ' ];
120+
121+ /** @var ?string $subline */
122+ $ subline = array_key_exists ('subline ' , $ result ) ? $ result ['subline ' ] : null ;
123+
124+ /** @var ?string $status */
125+ $ status = array_key_exists ('status ' , $ result ) && is_string ($ result ['status ' ]) ? $ result ['status ' ] : null ;
126+
127+ /** @var ?string $shareWithDisplayNameUnique */
128+ $ shareWithDisplayNameUnique = array_key_exists ('shareWithDisplayNameUnique ' , $ result ) ? $ result ['shareWithDisplayNameUnique ' ] : null ;
129+
96130 $ output [] = [
97131 'id ' => (string ) $ result ['value ' ]['shareWith ' ],
98- 'label ' => $ result [ ' label ' ] ,
99- 'icon ' => $ result [ ' icon ' ] ?? '' ,
132+ 'label ' => $ label ,
133+ 'icon ' => $ icon ?? '' ,
100134 'source ' => $ type ,
101- 'status ' => $ result [ ' status ' ] ?? '' ,
102- 'subline ' => $ result [ ' subline ' ] ?? '' ,
103- 'shareWithDisplayNameUnique ' => $ result [ ' shareWithDisplayNameUnique ' ] ?? '' ,
135+ 'status ' => $ status ?? '' ,
136+ 'subline ' => $ subline ?? '' ,
137+ 'shareWithDisplayNameUnique ' => $ shareWithDisplayNameUnique ?? '' ,
104138 ];
105139 }
106140 }
0 commit comments