queryLocationByProtocol method

Future<List<Location>> queryLocationByProtocol(
  1. String protocol, {
  2. Map<String, String>? fields,
})

Requesting this endpoint with a valid protocol name results in a list of successful mapping results in a JSON array. Each result contains objects to represent the Matrix room or rooms that represent a portal to this third-party network. Each has the Matrix room alias string, an identifier for the particular third-party network protocol, and an object containing the network-specific fields that comprise this identifier. It should attempt to canonicalise the identifier as much as reasonably possible given the network type.

protocol The protocol used to communicate to the third-party network.

fields One or more custom fields to help identify the third-party location.

Implementation

Future<List<Location>> queryLocationByProtocol(String protocol,
    {Map<String, String>? fields}) async {
  final requestUri = Uri(
      path:
          '_matrix/client/v3/thirdparty/location/${Uri.encodeComponent(protocol)}',
      queryParameters: {
        if (fields != null) ...fields,
      });
  final request = Request('GET', baseUri!.resolveUri(requestUri));
  request.headers['authorization'] = 'Bearer ${bearerToken!}';
  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 (json as List)
      .map((v) => Location.fromJson(v as Map<String, Object?>))
      .toList();
}