39 $previousStatus = Array(
44 'MOBILE_LAST_DATE' =>
false,
45 'DESKTOP_LAST_DATE' =>
false,
47 $needToUpdate =
false;
54 $status[
'MOBILE_LAST_DATE'] ??=
false;
55 $status[
'DESKTOP_LAST_DATE'] ??=
false;
57 $previousStatus = Array(
58 'USER_ID' =>
$status[
'USER_ID'],
59 'STATUS' => (
string)
$status[
'STATUS'],
60 'COLOR' => (
string)
$status[
'COLOR'],
62 'MOBILE_LAST_DATE' =>
$status[
'MOBILE_LAST_DATE'],
63 'DESKTOP_LAST_DATE' =>
$status[
'DESKTOP_LAST_DATE'],
69 $newValue = is_object($value)? $value->toString(): $value;
70 if ($oldValue != $newValue)
86 IM\Model\StatusTable::merge(
$params, $update);
92 $cache = \Bitrix\Main\Data\Cache::createInstance();
93 $cache->cleanDir(self::CACHE_PATH.
$userId.
'/');
96 if ($needToUpdate && self::Enable())
107 $cache->CleanDir(self::CACHE_ONLINE_PATH);
109 $event = new \Bitrix\Main\Event(
"im",
"onStatusSet",
array(
114 'MOBILE_LAST_DATE' =>
$status[
'MOBILE_LAST_DATE'] instanceof \
Bitrix\Main\Type\DateTime?
$status[
'MOBILE_LAST_DATE']:
false,
115 'DESKTOP_LAST_DATE' =>
$status[
'DESKTOP_LAST_DATE'] instanceof \
Bitrix\Main\Type\DateTime?
$status[
'DESKTOP_LAST_DATE']:
false,
116 'PREVIOUS_VALUES' => $previousStatus
126 'module_id' =>
'online',
127 'command' =>
'userStatus',
133 'status' =>
$status[
'STATUS'] ??
null,
134 'color' => (
$status[
'COLOR'] ??
null)
138 'idle' =>
$status[
'IDLE'] instanceof \Bitrix\Main\Type\DateTime
139 ? date(
'c',
$status[
'IDLE']->getTimestamp())
142 'mobile_last_date' => (
$status[
'MOBILE_LAST_DATE'] ?? null) instanceof \
Bitrix\Main\Type\DateTime
143 ? date(
'c',
$status[
'MOBILE_LAST_DATE']->getTimestamp())
146 'desktop_last_date' =>
$status[
'DESKTOP_LAST_DATE'] instanceof \
Bitrix\Main\Type\DateTime
147 ? date(
'c',
$status[
'DESKTOP_LAST_DATE']->getTimestamp())
150 'last_activity_date' => date(
'c', time())
159 return "IM_USER_ONLINE_{$userId}";
169 $date->add(
'-'.$ago.
' MINUTE');
189 if(defined(
"BX_COMP_MANAGED_CACHE"))
197 private static function PrepareToPush(
$params)
201 if (
$key ==
'STATUS')
203 $params[
$key] = in_array($value, self::$AVAILABLE_STATUSES)? $value:
'online';
205 else if (in_array(
$key, Array(
'IDLE',
'DESKTOP_LAST_DATE',
'MOBILE_LAST_DATE',
'EVENT_UNTIL_DATE')))
209 else if (
$key ==
'COLOR')
226 private static function PrepareFields(
$params)
230 $arFields = IM\Model\StatusTable::getMap();
236 if (
$key ==
'STATUS')
240 else if (
$key ==
'COLOR')
242 $colors = IM\Color::getSafeColors();
243 if (isset($colors[$value]))
267 $userIds[] = intval($value);
272 $userIds[] = intval(
$params[
'ID']);
275 if (isset(
$params[
'CLEAR_CACHE']) &&
$params[
'CLEAR_CACHE'] ==
'Y')
277 $obCache =
new CPHPCache();
278 $obCache->CleanDir(self::CACHE_ONLINE_PATH);
290 if (!is_null(self::$CACHE_RECENT))
293 $users = self::$CACHE_RECENT;
296 else if (!empty($userIds))
298 foreach($userIds as $id =>
$uid)
300 if (isset(self::$CACHE_USERS[
$uid]))
302 unset($userIds[$id]);
303 $users[
$uid] = self::$CACHE_USERS[
$uid];
316 $orm = \Bitrix\Im\Model\RecentTable::getList(
array(
319 'EXTERNAL_AUTH_ID' =>
'U.EXTERNAL_AUTH_ID',
320 'LAST_ACTIVITY_DATE' =>
'U.LAST_ACTIVITY_DATE',
321 'PERSONAL_GENDER' =>
'U.PERSONAL_GENDER',
322 'COLOR' =>
'ST.COLOR',
323 'STATUS' =>
'ST.STATUS',
325 'MOBILE_LAST_DATE' =>
'ST.MOBILE_LAST_DATE',
326 'DESKTOP_LAST_DATE' =>
'ST.DESKTOP_LAST_DATE',
329 new \
Bitrix\Main\Entity\ReferenceField(
331 '\Bitrix\Im\Model\StatusTable',
332 array(
"=ref.USER_ID" =>
"this.ITEM_ID",),
333 array(
"join_type"=>
"LEFT")
335 new \
Bitrix\Main\Entity\ReferenceField(
337 '\Bitrix\Main\UserTable',
338 array(
"=ref.ID" =>
"this.ITEM_ID",),
339 array(
"join_type"=>
"LEFT")
354 'LAST_ACTIVITY_DATE',
356 'COLOR' =>
'ST.COLOR',
357 'STATUS' =>
'ST.STATUS',
359 'MOBILE_LAST_DATE' =>
'ST.MOBILE_LAST_DATE',
360 'DESKTOP_LAST_DATE' =>
'ST.DESKTOP_LAST_DATE',
363 new \
Bitrix\Main\Entity\ReferenceField(
365 '\Bitrix\Im\Model\StatusTable',
367 "=ref.USER_ID" =>
"this.ID",
369 array(
"join_type"=>
"LEFT")
378 while ($user = $orm->fetch())
381 if (isset($user[
'COLOR']) && $user[
'COLOR'] <>
'')
383 $color = IM\Color::getColor($user[
'COLOR']);
387 $color = \CIMContactList::GetUserColor($user[
"ID"], $user[
'PERSONAL_GENDER'] ==
'M'?
'M':
'F');
390 $user[
'LAST_ACTIVITY_DATE'] = $user[
'LAST_ACTIVITY_DATE'] instanceof \Bitrix\Main\Type\DateTime? $user[
'LAST_ACTIVITY_DATE']:
false;
393 $users[$user[
"ID"]] = Array(
396 'status' =>
'online',
400 'last_activity_date' => $user[
'LAST_ACTIVITY_DATE']?:
false,
402 'mobile_last_date' =>
false,
403 'absent' => \CIMContactList::formatAbsentResult($user[
"ID"]),
406 self::$CACHE_USERS[$user[
"ID"]] = $users[$user[
"ID"]];
411 self::$CACHE_RECENT = self::$CACHE_USERS;
415 return Array(
'users' => $users);
423 $obCLCache =
new CPHPCache;
424 $cache_id =
'im_user_online_v1';
425 $cache_dir = self::CACHE_ONLINE_PATH.$userId.
'/';
426 if($obCLCache->InitCache(self::CACHE_ONLINE_TTL, $cache_id, $cache_dir))
428 $arOnline = $obCLCache->GetVars();
432 $arOnline = self::GetList();
434 if($obCLCache->StartDataCache())
436 $obCLCache->EndDataCache($arOnline);
452 $cache = \Bitrix\Main\Data\Cache::createInstance();
454 if (isset(self::$status[
$userId]))
456 return self::getStatusFromStaticCache(
$userId);
459 if($cache->initCache(self::CACHE_TTL,
'list_v2', self::CACHE_PATH.$userId.
'/'))
461 $userStatus = $cache->getVars();
465 $res = IM\Model\StatusTable::getList(Array(
471 'EXTERNAL_AUTH_ID' =>
'USER.EXTERNAL_AUTH_ID'
474 new \
Bitrix\Main\Entity\ReferenceField(
476 '\Bitrix\Main\UserTable',
477 array(
"=ref.ID" =>
"this.USER_ID",),
478 array(
"join_type"=>
"LEFT")
481 'filter' => Array(
'=USER_ID' =>
$userId),
486 $cache->startDataCache();
487 $cache->endDataCache($userStatus);
491 self::$status[
$userId] = $userStatus ?? [];
503 if (!empty(self::$status[
$userId]))
505 return self::prepareLastDate(self::$status[
$userId]);
511 public static function OnUserOnlineStatusGetCustomStatus(
$userId, $lastseen, $now, $mode)
521 $externalUser = \Bitrix\Main\UserTable::getExternalUserTypes();
522 $externalUser[] =
'network';
524 if (in_array(
$status[
'EXTERNAL_AUTH_ID'], $externalUser))
528 $result[
'LAST_SEEN_TEXT'] =
'';
534 $mobileLastDate =
$status[
'MOBILE_LAST_DATE'];
538 $now - $mobileLastDate->getTimestamp() < CUser::GetSecondsForLimitOnline()
539 && $lastseen - $mobileLastDate->getTimestamp() < 300
544 $result[
'LAST_SEEN'] = $mobileLastDate->getTimestamp();
549 if ($mode == CUser::STATUS_OFFLINE)
557 else if (in_array(
$status[
'STATUS'], Array(
'dnd',
'away',
'break',
'video')))
569 $result[
'LAST_SEEN'] = $idleDate->getTimestamp();
583 if (!($dates[
'DESKTOP_LAST_DATE'] instanceof \
Bitrix\Main\Type\DateTime))
588 $maxOnlineTime = 120;
589 if (\
Bitrix\Main\Loader::includeModule(
'pull') && CPullOptions::GetNginxStatus())
591 $maxOnlineTime = CIMMessenger::GetSessionLifeTime();
594 if ($dates[
'DESKTOP_LAST_DATE']->getTimestamp()+$maxOnlineTime+60 > time())
605 $dates[
'IDLE'] instanceof \
Bitrix\Main\Type\DateTime
606 && $dates[
'IDLE']->getTimestamp() > 0
617 if (!($dates[
'MOBILE_LAST_DATE'] instanceof \
Bitrix\Main\Type\DateTime))
619 $dates[
'MOBILE_LAST_DATE'] =
false;
622 if (!($dates[
'DESKTOP_LAST_DATE'] instanceof \
Bitrix\Main\Type\DateTime))
624 $dates[
'DESKTOP_LAST_DATE'] =
false;
627 $status = self::getDesktopStatus($dates);
630 $dates[
'IDLE'] =
false;
638 return CModule::IncludeModule(
'pull') && CPullOptions::GetNginxStatus()?
true:
false;
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static getColorByNumber($number)
static getList(array $parameters=array())
static add($recipient, array $parameters, $channelType=\CPullChannel::TYPE_PRIVATE)
static FormatLastActivityDate($timestamp, $now=false)
static SetColor($userId, $color)
static getDesktopStatus($dates)
static GetList($params=Array())
static GetStatus($userId=null)
static SetIdle($userId, $result=true, $ago=10)
static Set($userId, $params)
static getPushTag(int $userId)
static $AVAILABLE_STATUSES
static getStatusFromStaticCache(int $userId)
static prepareLastDate($dates)
static SetMobile($userId, $result=true)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
GetMessage($name, $aReplace=null)
if(empty($signedUserToken)) $key
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']