1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
UpdateStatus.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2\Controller\Filter;
4
5use Bitrix\Im\V2\Application\Context;
6use Bitrix\Im\V2\Controller\Chat;
7use Bitrix\Im\V2\Controller\UpdateState;
8use Bitrix\Main\Engine\ActionFilter\Base;
9use Bitrix\Main\Engine\CurrentUser;
10use Bitrix\Main\Event;
11use Bitrix\Main\Loader;
12
13class UpdateStatus extends Base
14{
19 private const METHODS_REQUIRING_PREFILTER = [
20 Chat::class => [
21 'load' => true,
22 'loadincontext' => true,
23 'read' => true,
24 'readall' => true,
25 ],
26 UpdateState::class => [
27 'getstatedata' => true,
28 ],
29 Chat\Message::class => [
30 'read' => true,
31 'list' => true,
32 'getcontext' => true,
33 'tail' => true,
34 ],
35 ];
36
37 public function onBeforeAction(Event $event)
38 {
39 $this->updateStatus();
40 }
41
42 private function updateStatus(): void
43 {
44 if (!$this->shouldUpdateByAction())
45 {
46 return;
47 }
48
49 $userId = (int)CurrentUser::get()->getId();
50 if (!$userId)
51 {
52 return;
53 }
54
55 \CIMContactList::SetOnline($userId);
56 $context = Context::getCurrent();
57
58 if ($context->isMobile() && Loader::includeModule('mobile'))
59 {
60 \Bitrix\Mobile\User::setOnline($userId);
61 }
62
63 if (!$context->isMobile())
64 {
65 \CIMStatus::Set($userId, Array('IDLE' => null));
66 }
67
68 if ($context->isDesktop())
69 {
70 \CIMMessenger::SetDesktopStatusOnline($userId);
71 }
72 }
73
74 private function shouldUpdateByAction(): bool
75 {
76 $className = $this->getAction()->getController()::class;
77 $methodName = mb_strtolower($this->getAction()->getName());
78
79 return isset(self::METHODS_REQUIRING_PREFILTER[$className][$methodName]);
80 }
81}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
$context
Определения csv_new_setup.php:223
getName()
Определения Param.php:99
$event
Определения prolog_after.php:141