searchUserDirectory method

Future<SearchUserDirectoryResponse> searchUserDirectory(
  1. String searchTerm, {
  2. int? limit,
})
inherited

Performs a search for users. The node may determine which subset of users are searched, however the node MUST at a minimum consider the users the requesting user shares a room with and those who reside in public rooms (known to the node). The search MUST consider local users to the node, and SHOULD query remote users as part of the search.

The search is performed case-insensitively on user IDs and display names preferably using a collation determined based upon the Accept-Language header provided in the request, if present.

limit The maximum number of results to return. Defaults to 10.

searchTerm The term to search for

Implementation

Future<SearchUserDirectoryResponse> searchUserDirectory(String searchTerm,
    {int? limit}) async {
  final requestUri = Uri(path: '_api/client/v3/user_directory/search');
  final request = Request('POST', baseUri!.resolveUri(requestUri));
  request.headers['authorization'] = 'Bearer ${bearerToken!}';
  request.headers['content-type'] = 'application/json';
  request.bodyBytes = utf8.encode(jsonEncode({
    if (limit != null) 'limit': limit,
    'search_term': searchTerm,
  }));
  final response = await httpClient.send(request);
  final responseBody = await response.stream.toBytes();
  if (response.statusCode != 200) unexpectedResponse(response, responseBody);
  final responseString = utf8.decode(responseBody);
  final json = jsonDecode(responseString);
  return SearchUserDirectoryResponse.fromJson(json as Map<String, Object?>);
}