setAccountData method

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

Set some account data for the client. This config is only visible to the user that set the account data. The config will be available to clients through the top-level account_data field in the node response to /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.

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> setAccountData(
    String userId, String type, Map<String, Object?> content) async {
  final requestUri = Uri(
      path:
          '_api/client/v3/user/${Uri.encodeComponent(userId)}/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);
}