• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/lib/V2/Chat/CommentChat.php
  • Класс: BitrixImV2ChatCommentChat
  • Вызов: CommentChat::add
public function add(array $params, ?Context $context = null): Result
{
	$result = new Result;

	$paramsResult = $this->prepareParams($params);
	if ($paramsResult->isSuccess())
	{
		$params = $paramsResult->getResult();
	}
	else
	{
		return $result->addErrors($paramsResult->getErrors());
	}

	$chat = new static($params);
	$chat->setParentChatId($params['PARENT_ID']);
	if (!$chat->getParent())
	{
		return $result->addError(new ChatError(ChatError::WRONG_PARENT_CHAT));
	}
	$chat
		->setExtranet($chat->getParent()->getExtranet())
		->setManageUsers($chat->getParent()->getManageUsers())
		->setManageUI($chat->getParent()->getManageUI())
		->setParentMessageId($params['PARENT_MID'])
	;
	if (!$chat->getParentMessageId())
	{
		return $result->addError(new ChatError(ChatError::WRONG_PARENT_MESSAGE));
	}
	$chat->save();

	if (!$chat->getChatId())
	{
		return $result->addError(new ChatError(ChatError::CREATION_ERROR));
	}

	$result->setResult([
		'CHAT_ID' => $chat->getChatId(),
		'CHAT' => $chat,
	]);

	return $result;
}