blockUser method

Future<BlocklistEventsVersionedMixin?> blockUser(
  1. UserId id,
  2. BlocklistReason? reason
)

Blocks the specified User for the authenticated MyUser.

Blocked Users are not able to communicate with the authenticated MyUser directly (in Chat-dialogs) and add him to Chat-groups.

MyUser's blocklist can be obtained via getBlocklist.

Authentication

Mandatory.

Result

Only the following BlocklistEvent may be produced on success:

Idempotent

Succeeds as no-op (and returns no BlocklistEvent) if the specified User is blocked by the authenticated MyUser already with the same BlocklistReason.

Implementation

Future<BlocklistEventsVersionedMixin?> blockUser(
  UserId id,
  BlocklistReason? reason,
) async {
  Log.debug('blockUser($id, $reason)', '$runtimeType');

  final variables = BlockUserArguments(id: id, reason: reason);
  final QueryResult result = await client.mutate(
    MutationOptions(
      operationName: 'BlockUser',
      document: BlockUserMutation(variables: variables).document,
      variables: variables.toJson(),
    ),
    onException:
        (data) => BlockUserException(
          BlockUser$Mutation.fromJson(data).blockUser as BlockUserErrorCode,
        ),
  );
  return BlockUser$Mutation.fromJson(result.data!).blockUser
      as BlocklistEventsVersionedMixin?;
}