1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Limit.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2\TariffLimit;
4
5use Bitrix\Bitrix24\Feature;
6use Bitrix\Im\V2\Chat;
7use Bitrix\Im\V2\Integration\AiAssistant\AiAssistantService;
8use Bitrix\Main\DI\ServiceLocator;
9use Bitrix\Main\Loader;
10use Bitrix\Main\Type\DateTime;
11
12class Limit
13{
14 private const DAYS_LIMIT_HISTORY_VARIABLE = 'im_history_days_limit';
15 private const HISTORY_LIMIT_ID = 'im_history_limit';
16 private const CHAT_TYPE_BLACKLIST = [
17 Chat\ChannelChat::class,
18 Chat\CommentChat::class,
19 Chat\CollabChat::class,
20 Chat\ExternalChat::class
21 ];
22
23 private static ?self $instance;
24
25 private AiAssistantService $aiAssistantService;
26
27 private function __construct()
28 {
29 $this->aiAssistantService = ServiceLocator::getInstance()->get(AiAssistantService::class);
30 }
31
32 public static function getInstance(): static
33 {
34 if (!isset(static::$instance))
35 {
36 static::$instance = new static();
37 }
38
39 return static::$instance;
40 }
41
42 public static function onLicenseHasChanged(): void
43 {
44 if (Loader::includeModule('pull'))
45 {
46 \CPullStack::AddShared([
47 'module_id' => 'im',
48 'command' => 'changeTariff',
49 'params' => [
50 'tariffRestrictions' => self::getInstance()->getRestrictions(),
51 ],
52 'extra' => \Bitrix\Im\Common::getPullExtra()
53 ]);
54 }
55 }
56
57 public function getRestrictions(): array
58 {
59 return [
60 'fullChatHistory' => [
61 'isAvailable' => !$this->hasRestrictions(),
62 'limitDays' => $this->getLimitDays(),
63 ],
64 ];
65 }
66
67 protected function getLimitDays(): ?int
68 {
69 if (!Loader::includeModule('bitrix24'))
70 {
71 return null;
72 }
73
74 if (Feature::isFeatureEnabled(self::HISTORY_LIMIT_ID))
75 {
76 return null;
77 }
78
79 $limitDays = Feature::getVariable(self::DAYS_LIMIT_HISTORY_VARIABLE);
80
81 return $limitDays === null ? null : (int)$limitDays;
82 }
83
84 public function hasAccessByDate(DateFilterable $item, DateTime $date): bool
85 {
86 if (!$this->shouldFilterByDate($item))
87 {
88 return true;
89 }
90
91 return $this->getLimitDate()->getTimestamp() <= $date->getTimestamp();
92 }
93
94 public function hasRestrictions(): bool
95 {
96 return $this->getLimitDays() !== null;
97 }
98
99 public function shouldFilterByDate(DateFilterable $item): bool
100 {
101 if (!$this->hasRestrictions())
102 {
103 return false;
104 }
105
106 $chatId = $item->getRelatedChatId();
107
108 if (!$chatId)
109 {
110 return false;
111 }
112
113 return $this->isChatTypeAllowed($chatId);
114 }
115
116 public function getLimitDate(): DateTime
117 {
118 Loader::requireModule('bitrix24');
119 $days = $this->getLimitDays();
120
121 return (new DateTime())->add("-{$days} days");
122 }
123
124 private function isChatTypeAllowed(int $chatId): bool
125 {
126 $chat = Chat::getInstance($chatId);
127 foreach (self::CHAT_TYPE_BLACKLIST as $type)
128 {
129 if ($chat instanceof $type)
130 {
131 return false;
132 }
133 }
134
135 if ($this->aiAssistantService->isAiAssistantChat($chat))
136 {
137 return false;
138 }
139
140 return true;
141 }
142}
$type
Определения options.php:106
static getPullExtra()
Определения common.php:127
Определения limit.php:5
static onLicenseHasChanged()
Определения Limit.php:42
shouldFilterByDate(DateFilterable $item)
Определения Limit.php:99
hasRestrictions()
Определения Limit.php:94
getLimitDays()
Определения Limit.php:67
getRestrictions()
Определения Limit.php:57
static getInstance()
Определения Limit.php:32
hasAccessByDate(DateFilterable $item, DateTime $date)
Определения Limit.php:84
static getInstance()
Определения application.php:98
getTimestamp()
Определения date.php:218
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804