delete3pidFromAccount method

Future<IdServerUnbindResult> delete3pidFromAccount(
  1. String address,
  2. ThirdPartyIdentifierMedium medium, {
  3. String? idServer,
})
inherited

Removes a third party identifier from the user's account. This might not cause an unbind of the identifier from the identity server.

Unlike other endpoints, this endpoint does not take an id_access_token parameter because the node is expected to sign the request to the identity server instead.

address The third party address being removed.

idServer The identity server to unbind from. If not provided, the node MUST use the id_server the identifier was added through. If the node does not know the original id_server, it MUST return a id_server_unbind_result of no-support.

medium The medium of the third party identifier being removed.

returns id_server_unbind_result: An indicator as to whether or not the node was able to unbind the 3PID from the identity server. success indicates that the identity server has unbound the identifier whereas no-support indicates that the identity server refuses to support the request or the node was not able to determine an identity server to unbind from.

Implementation

Future<IdServerUnbindResult> delete3pidFromAccount(
    String address, ThirdPartyIdentifierMedium medium,
    {String? idServer}) async {
  final requestUri = Uri(path: '_api/client/v3/account/3pid/delete');
  final request = Request('POST', baseUri!.resolveUri(requestUri));
  request.headers['authorization'] = 'Bearer ${bearerToken!}';
  request.headers['content-type'] = 'application/json';
  request.bodyBytes = utf8.encode(jsonEncode({
    'address': address,
    if (idServer != null) 'id_server': idServer,
    'medium': medium.name,
  }));
  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 IdServerUnbindResult.values
      .fromString(json['id_server_unbind_result'] as String)!;
}