Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
UpdateStatus.php
1<?php
2
4
11
12class UpdateStatus extends Base
13{
14 public function onAfterAction(Event $event): void
15 {
16 $userId = (int)CurrentUser::get()->getId();
17 if (!$userId)
18 {
19 return;
20 }
21
22 \CIMContactList::SetOnline($userId);
23
24 if ($this->isMobile() && Loader::includeModule('mobile'))
25 {
26 \Bitrix\Mobile\User::setOnline($userId);
27 }
28
29 if (!$this->isMobile())
30 {
31 \CIMStatus::Set($userId, Array('IDLE' => null));
32 }
33
34 if ($this->isDesktop())
35 {
36 \CIMMessenger::SetDesktopStatusOnline($userId);
37 }
38 }
39
40 private function isDesktop(): bool
41 {
42 return $this->containInUserAgent('BitrixDesktop');
43 }
44
45 private function isMobile(): bool
46 {
47 return $this->containInUserAgent('BitrixMobile');
48 }
49
50 private function containInUserAgent(string $userAgent): bool
51 {
52 $context = Context::getCurrent();
53
54 if ($context === null)
55 {
56 return false;
57 }
58
59 return false !== stripos($context->getRequest()->getUserAgent(), $userAgent);
60 }
61}
static getCurrent()
Definition context.php:241