• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/lib/componenthelper.php
  • Класс: BitrixSocialnetworkComponentHelper
  • Вызов: ComponentHelper::userLogSubscribe
static function userLogSubscribe($params = array())
{
	static
		$logAuthorList = array(),
		$logDestUserList = array();

	$userId = (isset($params['userId']) ? (int)$params['userId'] : 0);
	$logId = (isset($params['logId']) ? (int)$params['logId'] : 0);
	$typeList = ($params['typeList'] ?? []);
	$siteId = (isset($params['siteId']) ? (int)$params['siteId'] : SITE_ID);
	$followByWF = !empty($params['followByWF']);

	if (!is_array($typeList))
	{
		$typeList = array($typeList);
	}

	if (
		$userId <= 0
		|| $logId <= 0
	)
	{
		return false;
	}

	$followRes = false;

	if (in_array('FOLLOW', $typeList))
	{
		$followRes = CSocNetLogFollow::set(
			$userId,
			"L".$logId,
			"Y",
			(
				!empty($params['followDate'])
					? (
						mb_strtoupper($params['followDate']) === 'CURRENT'
							? ConvertTimeStamp(time() + CTimeZone::getOffset(), "FULL", $siteId)
							: $params['followDate']
					)
					: false
			),
			$siteId,
			$followByWF
		);
	}

	if (in_array('COUNTER_COMMENT_PUSH', $typeList))
	{
		if (!isset($logAuthorList[$logId]))
		{
			$res = LogTable::getList(array(
				'filter' => array(
					'=ID' => $logId
				),
				'select' => array('USER_ID')
			));
			if ($logFields = $res->fetch())
			{
				$logAuthorList[$logId] = $logFields['USER_ID'];
			}
		}

		if (!isset($logDestUserList[$logId]))
		{
			$logDestUserList[$logId] = array();
			$res = LogRightTable::getList(array(
				'filter' => array(
					'=LOG_ID' => $logId
				),
				'select' => array('GROUP_CODE')
			));
			while ($logRightFields = $res->fetch())
			{
				if (preg_match('/^U(d+)$/', $logRightFields['GROUP_CODE'], $matches))
				{
					$logDestUserList[$logId][] = $matches[1];
				}
			}
		}

		if (
			$userId != $logAuthorList[$logId]
			&& !in_array($userId, $logDestUserList[$logId])
		)
		{
			LogSubscribeTable::set(array(
				'userId' => $userId,
				'logId' => $logId,
				'type' => LogSubscribeTable::TYPE_COUNTER_COMMENT_PUSH,
				'ttl' => true
			));
		}
	}

	return (
		in_array('FOLLOW', $typeList)
			? $followRes
			: true
	);
}