getUrlPreview method

  1. @deprecated
Future<PreviewForUrl> getUrlPreview(
  1. Uri url, {
  2. int? ts,
})

{{% boxes/note %}} Replaced by GET /_matrix/client/v1/media/preview_url. {{% /boxes/note %}}

Get information about a URL for the client. Typically this is called when a client sees a URL in a message and wants to render a preview for the user.

Note: Clients should consider avoiding this endpoint for URLs posted in encrypted rooms. Encrypted rooms often contain more sensitive information the users do not want to share with the homeserver, and this can mean that the URLs being shared should also not be shared with the homeserver.

url The URL to get a preview of.

ts The preferred point in time to return a preview for. The server may return a newer version if it does not have the requested version available.

Implementation

@deprecated
Future<PreviewForUrl> getUrlPreview(Uri url, {int? ts}) async {
  final requestUri = Uri(
    path: '_matrix/media/v3/preview_url',
    queryParameters: {
      'url': url.toString(),
      if (ts != null) 'ts': ts.toString(),
    },
  );
  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 PreviewForUrl.fromJson(json as Map<String, Object?>);
}