• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/classes/general/im_messenger.php
  • Класс: CIMMessenger
  • Вызов: CIMMessenger::SetDesktopStatusOnline
static function SetDesktopStatusOnline($userId = null, $cache = true)
{
	global $USER;

	if (is_null($userId))
		$userId = $USER->GetId();

	$userId = intval($userId);
	if ($userId <= 0)
		return false;

	if ($cache && $userId == $USER->GetId())
	{
		if (
			isset(BitrixMainApplication::getInstance()->getKernelSession()['IM']['SET_DESKTOP_ACTIVITY'])
			&& intval(BitrixMainApplication::getInstance()->getKernelSession()['IM']['SET_DESKTOP_ACTIVITY'])+300 > time()
		)
		{
			return false;
		}

		BitrixMainApplication::getInstance()->getKernelSession()['IM']['SET_DESKTOP_ACTIVITY'] = time();
	}

	$userAgent = BitrixMainContext::getCurrent()->getRequest()->getUserAgent();
	if (mb_strpos(mb_strtolower($userAgent), "windows") !== false)
	{
		$deviceType = IM_DESKTOP_WINDOWS;
	}
	elseif (mb_strpos(mb_strtolower($userAgent), "macintosh") !== false)
	{
		$deviceType = IM_DESKTOP_MAC;
	}
	elseif (mb_strpos(mb_strtolower($userAgent), "linux") !== false)
	{
		$deviceType = IM_DESKTOP_LINUX;
	}

	$time = time();
	CIMMessenger::SetDesktopLastActivityDate($time, $deviceType, $userId);

	if (CModule::IncludeModule("pull"))
	{
		if ($cache && $userId == $USER->GetId())
		{
			if (
				isset(BitrixMainApplication::getInstance()->getKernelSession()['IM']['SET_DESKTOP_ACTIVITY_PULL'])
				&& intval(BitrixMainApplication::getInstance()->getKernelSession()['IM']['SET_DESKTOP_ACTIVITY_PULL'])+3600 > $time
			)
			{
				return false;
			}

			BitrixMainApplication::getInstance()->getKernelSession()['IM']['SET_DESKTOP_ACTIVITY_PULL'] = $time;
		}

		BitrixPullEvent::add($userId, Array(
			'module_id' => 'im',
			'expiry' => 3600,
			'command' => 'desktopOnline',
			'params' => Array(
				'version' => CIMMessenger::GetDesktopVersion()
			),
			'extra' => BitrixImCommon::getPullExtra()
		));
	}

	return $time;
}