• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/classes/general/im_notify.php
  • Класс: CIMNotify
  • Вызов: CIMNotify::deleteList
static function deleteList(array $ids): bool
{
	global $DB;

	$cnt = count($ids);
	if ($cnt <= 0)
	{
		return false;
	}

	if ($cnt === 1)
	{
		self::Delete($ids[0]);

		return true;
	}

	$chatId = null;
	$relationUserId = null;
	$resultDataForPushAndPull = [];

	foreach ($ids as $id)
	{
		$arRes = self::getNotificationById($id);
		if (!$arRes)
		{
			continue;
		}

		self::deleteInternal($id, (int)$arRes['RELATION_USER_ID']);

		foreach(GetModuleEvents("im", "OnAfterDeleteNotify", true) as $arEvent)
		{
			ExecuteModuleEventEx($arEvent, [$id, $arRes]);
		}

		if (!$chatId)
		{
			$chatId = $arRes['CHAT_ID'];
		}
		if (!$relationUserId)
		{
			$relationUserId = $arRes['RELATION_USER_ID'];
		}
		$resultDataForPushAndPull[$id] = $arRes['NOTIFY_TYPE'];
	}

	if (!$chatId || !$relationUserId || count($resultDataForPushAndPull) === 0)
	{
		return false;
	}

	$recentRow = BitrixImModelRecentTable::getRow([
		'select' => ['ITEM_MID'],
		'filter' => [
			'=USER_ID' => $relationUserId,
			'=ITEM_TYPE' => IM_MESSAGE_SYSTEM,
			'=ITEM_ID' => $relationUserId,
		],
		'limit' => 1
	]);
	if (!$recentRow)
	{
		$needToUpdateRecent = false;
	}
	else
	{
		$lastIdFromRecent = (int)$recentRow['ITEM_MID'];
		$needToUpdateRecent = $lastIdFromRecent === max($ids);
	}

	$chatId = (int)$chatId;
	$counter = self::GetRealCounter($chatId);
	$time = microtime(true);
	if (Loader::includeModule('pull'))
	{
		BitrixPullEvent::add((int)$relationUserId, [
			'module_id' => 'im',
			'command' => 'chatCounterChange',
			'params' => [
				'chatId' => $chatId,
				'counter' => $counter,
				'time' => $time
			],
			'extra' => BitrixImCommon::getPullExtra()
		]);
	}
	// update unread counter
	//$DB->Query("UPDATE b_im_relation SET COUNTER = {$counter} WHERE CHAT_ID = ".$chatId);
	BitrixImCounter::clearCache($relationUserId);

	self::updateStateAfterDelete($chatId, $relationUserId, $needToUpdateRecent);

	if (CModule::IncludeModule("pull"))
	{
		BitrixPullEvent::add(
			$relationUserId,
			[
				'module_id' => 'im',
				'command' => 'notifyDelete',
				'params' => [
					'id' => $resultDataForPushAndPull,
					'counter' => $counter
				],
				'extra' => BitrixImCommon::getPullExtra()
			]
		);
		BitrixPullEvent::send();
	}

	return true;
}