17 $userId = (int)$user->
getId();
18 $eventParams = $this->getEventParams();
21 ? $mainCounters = CUserCounter::GetValues($userId, $siteId)
22 : $mainCounters = CUserCounter::GetValues($userId)
25 $chatCounters = \Bitrix\Im\Counter::get(
null, [
'JSON' =>
'Y']);
28 'revision' => \Bitrix\Im\Revision::getWeb(),
29 'mobileRevision' => \Bitrix\Im\Revision::getMobile(),
30 'counters' => $mainCounters,
31 'chatCounters' => $chatCounters,
32 'notifyLastId' => (new \Bitrix\Im\Notify())->getLastId(),
33 'desktopStatus' => $this->CheckDesktopStatusOnline($userId),
34 'serverTime' => time(),
35 'lastUpdate' => (new \Bitrix\Main\Type\DateTime())->format(DateTimeInterface::RFC3339),
36 'eventParams' => $eventParams,
40 private function getEventParams(): array
42 $event =
new Event(
'im',
'OnUpdateState');
47 if ($event->getResults())
49 foreach($event->getResults() as $eventResult)
51 if (\
Bitrix\Main\EventResult::SUCCESS)
53 $result[$eventResult->getModuleId()] = $eventResult->getParameters();
61 private function checkDesktopStatusOnline(
int $userId): bool
64 if ($this->isPullEnable() && CPullOptions::GetNginxStatus())
66 $maxOnlineTime = $this->GetSessionLifeTime();
69 $status = CIMStatus::GetStatus($userId);
70 $desktopLastDateStatus = $status[
'DESKTOP_LAST_DATE'] ??
null;
73 $desktopLastDateStatus instanceof \
Bitrix\Main\
Type\DateTime
74 && $desktopLastDateStatus->getTimestamp() + $maxOnlineTime + 60 > time()
85 $updateStateInterval = $this->getSessionLifeTime() - 60;
87 if ($updateStateInterval < 100)
89 $updateStateInterval = 100;
91 elseif ($updateStateInterval > 3600)
93 $updateStateInterval = 3600;
96 return $updateStateInterval;
99 private function getSessionLifeTime(): int
103 $sessTimeout = CUser::GetSecondsForLimitOnline();
105 if ($USER instanceof CUser)
107 $arPolicy = $USER->GetSecurityPolicy();
109 if($arPolicy[
"SESSION_TIMEOUT"] > 0)
111 $sessTimeout = min($arPolicy[
"SESSION_TIMEOUT"] * 60, $sessTimeout);
115 $sessTimeout = (int)$sessTimeout;
117 if ($sessTimeout <= 120)
125 private function isPullEnable(): bool
127 return \Bitrix\Main\Loader::includeModule(
'pull');