3namespace Bitrix\Im\V2\Relation;
5use Bitrix\Im\V2\Entity\User\User;
6use Bitrix\Im\V2\Relation;
7use Bitrix\Im\V2\RelationCollection;
16 private static array $instances = [];
22 private array $relationByUserId = [];
26 private array $relationsByUserIds = [];
30 private function __construct(
int $chatId)
39 return self::$instances[
$chatId];
45 $this->fullRelations = $relations;
55 if (!static::NEED_ADDITIONAL_FILTER_BY_ACCESS)
62 return $relations->
filter(fn (
Relation $relation) => in_array($relation->getUserId(), $usersWithAccess,
true));
67 $this->relationByUserId[
$userId] = $relation ??
false;
72 if (!isset($this->fullRelations))
77 return $this->fullRelations;
84 return $this->rawFullRelations;
94 if (isset($this->fullRelations))
96 return $this->fullRelations->filter(fn (
Relation $relation) => $relation->getManager());
109 if (isset($this->relationByUserId[
$userId]))
111 return $this->relationByUserId[
$userId] ?:
null;
114 if (isset($this->fullRelations))
116 return $this->fullRelations->getByUserId(
$userId, $this->chatId);
120 $this->relationByUserId[
$userId] = $relations->getByUserId(
$userId, $this->chatId) ??
false;
122 return $this->relationByUserId[
$userId] ?:
null;
139 $userIdsString = implode(
'|', $userIds);
141 if (isset($this->relationsByUserIds[$userIdsString]))
143 return $this->relationsByUserIds[$userIdsString];
146 if (isset($this->fullRelations))
148 return $this->fullRelations->filter(fn (
Relation $relation) => in_array($relation->getUserId(), $userIds,
true));
151 $this->relationsByUserIds[$userIdsString] = $this->
loadByUserIds($userIds);
153 return $this->relationsByUserIds[$userIdsString];
168 if (isset($this->fullRelations))
170 return $this->fullRelations->filter(fn (
Relation $relation) => $relation->getReason() === $reason);
183 unset($this->fullRelations, $this->rawFullRelations);
184 $this->relationByUserId = [];
185 $this->relationsByUserIds = [];
196 $this->fullRelations->onAfterRelationDelete($this->chatId, $deletedUserId);
197 $this->rawFullRelations->onAfterRelationDelete($this->chatId, $deletedUserId);
198 unset($this->relationsByUserIds[$deletedUserId]);
199 $this->relationsByUserIds = [];
204 $fullRelations = $this->
get();
207 foreach ($fullRelations as $relation)
209 if (!$relation->isHidden() && $relation->getUser()->isActive())
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
filter(callable $predicate)
filterRelationsByAccess(RelationCollection $relations)
getByUserIds(array $userIds)
onAfterRelationAdd(array $usersToAdd)
loadByReason(Reason $reason)
preloadUserRelation(int $userId, ?Relation $relation)
loadByUserIds(array $userIds)
onAfterRelationDelete(int $deletedUserId)
const NEED_ADDITIONAL_FILTER_BY_ACCESS
loadByUserId(int $userId)
filterUserIdsByAccess(array $userIds)
getByReason(Reason $reason)
static getInstance(int $chatId)
forceRelations(RelationCollection $relations)
static find(array $filter, array $order=[], ?int $limit=null, ?Context $context=null, array $select=self::COMMON_FIELDS)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)