• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/lib/V2/Chat.php
  • Класс: BitrixImV2Chat
  • Вызов: Chat::deleteChat
public function deleteChat(): Result
{
	$result = new Result();

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

	$this->hideChat();

	$this->getRelations()->delete();

	$chatId = $this->getChatId();
	$chatFolderId = $this->getDiskFolderId();
	$this->delete();

	$messageCollection = MessageCollection::find(['CHAT_ID' => $chatId], []);
	$messageIds = $messageCollection->getIds();
	$messageCollection->delete();

	foreach (array_chunk($messageIds, self::CHUNK_SIZE) as $messageIdsChunk)
	{
		ImModelMessageParamTable::deleteBatch([
			'=MESSAGE_ID' => $messageIdsChunk,
		]);
	}

	ImV2LinkUrlUrlCollection::deleteByChatsIds([$chatId]);
	ImV2Chat::cleanCache($chatId);

	if ($chatFolderId)
	{
		$folderModel = BitrixDiskFolder::getById($chatFolderId);
		if ($folderModel)
		{
			$folderModel->deleteTree(BitrixDiskSystemUser::SYSTEM_USER_ID);
		}
	}

	return $result;
}