setTyping method

Future<void> setTyping(
  1. String userId,
  2. String roomId,
  3. bool typing, {
  4. int? timeout,
})
inherited

This tells the server that the user is typing for the next N milliseconds where N is the value specified in the timeout key. Alternatively, if typing is false, it tells the server that the user has stopped typing.

userId The user who has started to type.

roomId The room in which the user is typing.

timeout The length of time in milliseconds to mark this user as typing.

typing Whether the user is typing or not. If false, the timeout key can be omitted.

Implementation

Future<void> setTyping(String userId, String roomId, bool typing,
    {int? timeout}) async {
  final requestUri = Uri(
      path:
          '_api/client/v3/rooms/${Uri.encodeComponent(roomId)}/typing/${Uri.encodeComponent(userId)}');
  final request = Request('PUT', baseUri!.resolveUri(requestUri));
  request.headers['authorization'] = 'Bearer ${bearerToken!}';
  request.headers['content-type'] = 'application/json';
  request.bodyBytes = utf8.encode(jsonEncode({
    if (timeout != null) 'timeout': timeout,
    'typing': typing,
  }));
  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 ignore(json);
}