diff --git a/appinfo/routes.php b/appinfo/routes.php index 86ca86b23..df2e44067 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -130,8 +130,8 @@ return [ ], ], [ - 'name' => 'Chat#autoComplete', - 'url' => '/api/{apiVersion}/chat/{token}/autocomplete', + 'name' => 'Chat#mentions', + 'url' => '/api/{apiVersion}/chat/{token}/mentions', 'verb' => 'GET', 'requirements' => [ 'apiVersion' => 'v1', diff --git a/docs/api-v1.md b/docs/api-v1.md index 278ba9c6d..559cf5235 100644 --- a/docs/api-v1.md +++ b/docs/api-v1.md @@ -489,6 +489,31 @@ Base endpoint is: `/ocs/v2.php/apps/spreed/api/v1` - Header: + `201 Created` + `404 Not Found` When the room could not be found for the participant + +### Get mention autocomplete suggestions + +* Method: `GET` +* Endpoint: `/chat/{token}/mentions` +* Data: + + field | type | Description + ------|------|------------ + `search` | string | Search term for name suggestions (should at least be 1 character) + `limit` | int | Number of suggestions to receive (20 by default) + +* Response: + - Status code: + + `200 OK` + + `404 Not Found` When the room could not be found for the participant + + - Data: + Array of suggestions, each suggestion has at least: + + field | type | Description + ------|------|------------ + `id` | string | The user id which should be sent as `@` in the message + `label` | string | The displayname of the user + `source` | string | The type of the user, currently only `user` ## Guests diff --git a/js/views/chatview.js b/js/views/chatview.js index f96b76099..526e0fbd8 100644 --- a/js/views/chatview.js +++ b/js/views/chatview.js @@ -119,8 +119,8 @@ }, displayTpl: '
  • ' + '' - + '
    ' + ' ${label}' @@ -145,7 +145,7 @@ this._autoCompleteRequestCall.abort(); } this._autoCompleteRequestCall = $.ajax({ - url: OC.linkToOCS('apps/spreed/api/v1/chat', 2) + self.collection.token + '/autocomplete', + url: OC.linkToOCS('apps/spreed/api/v1/chat', 2) + self.collection.token + '/mentions', data: { search: query }, diff --git a/lib/Chat/AutoComplete/SearchPlugin.php b/lib/Chat/AutoComplete/SearchPlugin.php index 51eff373b..a380771ab 100644 --- a/lib/Chat/AutoComplete/SearchPlugin.php +++ b/lib/Chat/AutoComplete/SearchPlugin.php @@ -58,11 +58,9 @@ class SearchPlugin implements ISearchPlugin { * @since 13.0.0 */ public function search($search, $limit, $offset, ISearchResult $searchResult) { - $participants = $this->room->getParticipants(); $this->searchUsers($search, array_map('strval', array_keys($participants['users'])), $searchResult); - // FIXME Handle guests return false; diff --git a/lib/Controller/ChatController.php b/lib/Controller/ChatController.php index 0b108bddc..90453b4ab 100644 --- a/lib/Controller/ChatController.php +++ b/lib/Controller/ChatController.php @@ -308,7 +308,7 @@ class ChatController extends OCSController { * @param int $limit * @return DataResponse */ - public function autoComplete($token, $search, $limit = 20) { + public function mentions($token, $search, $limit = 20) { $room = $this->getRoom($token); if ($room === null) { return new DataResponse([], Http::STATUS_NOT_FOUND);