blockUser method

  1. @override
Future<void> blockUser(
  1. UserId id,
  2. BlocklistReason? reason
)
override

Blocks the specified User for the authenticated MyUser.

Implementation

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

  final RxUser? user = users[id];
  final BlocklistRecord? record = user?.user.value.isBlocked;

  if (user?.user.value.isBlocked == null) {
    user?.user.value.isBlocked = BlocklistRecord(
      userId: id,
      reason: reason,
      at: PreciseDateTime.now(),
    );
    user?.user.refresh();
  }

  try {
    await _graphQlProvider.blockUser(id, reason);
  } catch (_) {
    if (user != null && user.user.value.isBlocked != record) {
      user.user.value.isBlocked = record ?? user.user.value.isBlocked;
      user.user.refresh();
    }
    rethrow;
  }
}