1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
UpdateState.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2;
4
5use Bitrix\Main\Engine\CurrentUser;
6use Bitrix\Main\Event;
7use CIMStatus;
8use CPullOptions;
9use CUser;
10use CUserCounter;
11use DateTimeInterface;
12
14{
15 public function getUpdateStateData(CurrentUser $user, ?string $siteId = null): array
16 {
17 $userId = (int)$user->getId();
18 $eventParams = $this->getEventParams();
19
20 isset($siteId)
21 ? $mainCounters = CUserCounter::GetValues($userId, $siteId)
22 : $mainCounters = CUserCounter::GetValues($userId)
23 ;
24
25 $chatCounters = \Bitrix\Im\Counter::get(null, ['JSON' => 'Y']);
26
27 return [
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,
37 ];
38 }
39
40 private function getEventParams(): array
41 {
42 $event = new Event('im', 'OnUpdateState');
43 $event->send();
44
45 $result = [];
46
47 if ($event->getResults())
48 {
49 foreach($event->getResults() as $eventResult)
50 {
51 if (\Bitrix\Main\EventResult::SUCCESS)
52 {
53 $result[$eventResult->getModuleId()] = $eventResult->getParameters();
54 }
55 }
56 }
57
58 return $result;
59 }
60
61 private function checkDesktopStatusOnline(int $userId): bool
62 {
63 $maxOnlineTime = 120;
64 if ($this->isPullEnable() && CPullOptions::GetNginxStatus())
65 {
66 $maxOnlineTime = $this->GetSessionLifeTime();
67 }
68
70 $desktopLastDateStatus = $status['DESKTOP_LAST_DATE'] ?? null;
71
72 if (
73 $desktopLastDateStatus instanceof \Bitrix\Main\Type\DateTime
74 && $desktopLastDateStatus->getTimestamp() + $maxOnlineTime + 60 > time()
75 )
76 {
77 return true;
78 }
79
80 return false;
81 }
82
83 public function getInterval(): ?int
84 {
85 $updateStateInterval = $this->getSessionLifeTime() - 60;
86
87 if ($updateStateInterval < 100)
88 {
89 $updateStateInterval = 100;
90 }
91 elseif ($updateStateInterval > 3600)
92 {
93 $updateStateInterval = 3600;
94 }
95
96 return $updateStateInterval;
97 }
98
99 private function getSessionLifeTime(): int
100 {
101 global $USER;
102
103 $sessTimeout = CUser::GetSecondsForLimitOnline();
104
105 if ($USER instanceof CUser)
106 {
107 $arPolicy = $USER->GetSecurityPolicy();
108
109 if($arPolicy["SESSION_TIMEOUT"] > 0)
110 {
111 $sessTimeout = min($arPolicy["SESSION_TIMEOUT"] * 60, $sessTimeout);
112 }
113 }
114
115 $sessTimeout = (int)$sessTimeout;
116
117 if ($sessTimeout <= 120)
118 {
119 $sessTimeout = 100;
120 }
121
122 return $sessTimeout;
123 }
124
125 private function isPullEnable(): bool
126 {
127 return \Bitrix\Main\Loader::includeModule('pull');
128 }
129}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static get($userId=null, $options=[])
Определения counter.php:18
static getMobile()
Определения revision.php:47
static getWeb()
Определения revision.php:42
getUpdateStateData(CurrentUser $user, ?string $siteId=null)
Определения UpdateState.php:15
getInterval()
Определения UpdateState.php:83
static GetStatus($userId=null)
Определения im_status.php:443
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
global $USER
Определения csv_new_run.php:40
$arPolicy
Определения include.php:194
$status
Определения session.php:10
$siteId
Определения ajax.php:8
$user
Определения mysql_to_pgsql.php:33
$event
Определения prolog_after.php:141
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393