1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
LazyCleaner.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2\Relation;
4
5use Bitrix\Im\V2\Chat;
6use Bitrix\Main\Application;
7
9{
10 private const MAX_DELETIONS_PER_HIT = 20;
11
12 private static self $instance;
13
14 private array $toDelete = [];
15 private int $deletionCount = 0;
16 private bool $isScheduled = false;
17
18 private function __construct()
19 {
20 }
21
22 public static function getInstance(): static
23 {
24 self::$instance ??= new static();
25
26 return self::$instance;
27 }
28
29 public function canMarkForDeletion(): bool
30 {
31 return $this->deletionCount < self::MAX_DELETIONS_PER_HIT;
32 }
33
34 public function markForDeletion(int $chatId, int $userId): bool
35 {
36 if (!$this->canMarkForDeletion())
37 {
38 return false;
39 }
40
41 if (isset($this->toDelete[$chatId][$userId]))
42 {
43 return true;
44 }
45
46 $this->deletionCount++;
47 $this->toDelete[$chatId][$userId] = $userId;
48 $this->schedule();
49
50 return true;
51 }
52
53 private function schedule(): void
54 {
55 if ($this->isScheduled)
56 {
57 return;
58 }
59
60 $this->isScheduled = true;
61 Application::getInstance()->addBackgroundJob(fn () => $this->delete());
62 }
63
64 private function delete(): void
65 {
66 $this->isScheduled = false;
67
68 foreach ($this->toDelete as $chatId => $userIds)
69 {
70 $chat = Chat::getInstance($chatId);
71 foreach ($userIds as $userId)
72 {
73 $chat->deleteUser($userId, new DeleteUserConfig(withMessage: false, withNotification: false));
74 }
75 }
76
77 $this->toDelete = [];
78 }
79}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
markForDeletion(int $chatId, int $userId)
Определения LazyCleaner.php:34
static getInstance()
Определения LazyCleaner.php:22
static getInstance()
Определения application.php:98
static getInstance()
Определения servicelocator.php:33
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804