leave method

Future<void> leave(
  1. ChatId chatId, [
  2. ChatCallDeviceId? deviceId
])

Leaves or declines an OngoingCall identified by the given chatId.

Implementation

Future<void> leave(ChatId chatId, [ChatCallDeviceId? deviceId]) async {
  Log.debug('leave($chatId, $deviceId)', '$runtimeType');

  Rx<OngoingCall>? call = _callRepository[chatId];
  if (call != null) {
    deviceId ??= call.value.deviceId;
    call.value.state.value = OngoingCallState.ended;
    call.value.dispose();
  }

  deviceId ??= WebUtils.getCall(chatId)?.deviceId;

  if (deviceId != null) {
    await _callRepository.leave(chatId, deviceId);
  } else {
    await _callRepository.decline(chatId);
  }

  _callRepository.remove(chatId);
  WebUtils.removeCall(chatId);

  // Try to mark the `Chat` this call is taking place it as read, in case that
  // thus `leave()` method is called from a separate window.
  await _maybeMarkAsRead(chatId);
}