setAccountDataPerRoom method

Future<void> setAccountDataPerRoom(
  1. String userId,
  2. String roomId,
  3. String type,
  4. Map<String, Object?> content,
)
inherited

Set some account data for the client on a given room. This config is only visible to the user that set the account data. The config will be delivered to clients in the per-room entries via /sync.

userId The ID of the user to set account data for. The access token must be authorized to make requests for this user ID.

roomId The ID of the room to set account data on.

type The event type of the account data to set. Custom types should be namespaced to avoid clashes.

content The content of the account data.

Implementation

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