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

	$id = (int)$id;
	$notification = self::getNotificationById($id);
	if (!$notification)
	{
		return false;
	}

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

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

	self::updateStateAfterDelete($chatId, $notification['RELATION_USER_ID'], $needToUpdateRecent);

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

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

	return true;
}