• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/lib/call/integration/chat.php
  • Класс: BitrixImCallIntegrationChat
  • Вызов: Chat::onStateChange
public function onStateChange($state, $prevState)
{
	$initiatorId = $this->call->getInitiatorId();
	$initiator = BitrixImUser::getInstance($initiatorId);
	if($state === Call::STATE_INVITING && $prevState === Call::STATE_NEW)
	{
		$this->sendMessageDeferred(Loc::getMessage("IM_CALL_INTEGRATION_CHAT_CALL_STARTED", [
			"#ID#" => '[B]'.$this->call->getId().'[/B]'
		]), self::MUTE_MESSAGE);
	}
	else if($state === Call::STATE_FINISHED)
	{
		$message = Loc::getMessage("IM_CALL_INTEGRATION_CHAT_CALL_FINISHED");
		$mute = true;

		$userIds = array_values(array_filter($this->call->getUsers(), function($userId) use ($initiatorId)
		{
			return $userId != $initiatorId;
		}));

		if(count($userIds) == 1)
		{
			$otherUser = BitrixImUser::getInstance($userIds[0]);
			$otherUserState = $this->call->getUser($userIds[0]) ? $this->call->getUser($userIds[0])->getState() : '';
			if ($otherUserState == CallUser::STATE_DECLINED)
			{
				$message = Loc::getMessage("IM_CALL_INTEGRATION_CHAT_CALL_USER_DECLINED_" . $otherUser->getGender(), [
					'#NAME#' => $otherUser->getFullName(false)
				]);
			}
			else if ($otherUserState == CallUser::STATE_BUSY)
			{
				$message = Loc::getMessage("IM_CALL_INTEGRATION_CHAT_CALL_USER_BUSY_" . $otherUser->getGender(), [
					'#NAME#' => $otherUser->getFullName(false)
				]);
				$mute = false;
			}
			else if ($otherUserState == CallUser::STATE_UNAVAILABLE || $otherUserState == CallUser::STATE_CALLING)
			{
				$message = Loc::getMessage("IM_CALL_INTEGRATION_CHAT_CALL_MISSED_" . $initiator->getGender(), [
					'#NAME#' => $initiator->getFullName(false)
				]);
				$mute = false;
			}
		}

		$this->sendMessageDeferred($message, $mute);
	}
}