- Модуль: im
- Путь к файлу: ~/bitrix/modules/im/lib/V2/Chat.php
- Класс: BitrixImV2Chat
- Вызов: Chat::removeUsers
public function removeUsers(array $userIds): self
{
if (!$this->getChatId() || empty($userIds) || !count($userIds))
{
return $this;
}
$userIds = filter_var(
$userIds,
FILTER_VALIDATE_INT,
[
'flags' => FILTER_REQUIRE_ARRAY,
'options' => ['min_range' => 1],
]
);
foreach ($userIds as $key => $userId)
{
if (!is_int($userId))
{
unset($userIds[$key]);
}
}
$relations = $this->getRelations([
'CHAT_ID' => $this->getChatId(),
]);
$removedCount = RelationTable::deleteBatch([
['=USER_ID' => $userIds],
['=CHAT_ID' => $this->getChatId()]
]);
if (!$removedCount)
{
return $this;
}
$relations = $this->getRelations();
if ($extranetFlag = $this->getExtranet() ?? false)
{
$extranetFlag = false;
foreach ($relations as $relation)
{
if ($extranetFlag = $relation->getUser()->isExtranet())
{
break;
}
}
}
$this
->setExtranet($extranetFlag)
->setUserCount($relations->count())
->save();
if (BitrixMainLoader::includeModule('pull'))
{
$pushMessage = [
'module_id' => 'im',
'command' => 'chatUsersRemove',
'params' => [
'chatId' => $this->getChatId(),
'dialogId' => 'chat' . $this->getChatId(),
'chatExtranet' => $extranetFlag,
'userCount' => $relations->count()
],
'extra' => BitrixImCommon::getPullExtra()
];
$allUsersIds = $relations->getUserIds();
if ($this->getEntityType() === self::ENTITY_TYPE_LINE)
{
foreach ($relations as $relation)
{
if ($relation->getUser()->getExternalAuthId() === 'imconnector')
{
unset($allUsersIds[$relation['userId']]);
}
}
}
BitrixPullEvent::add(array_values($allUsersIds), $pushMessage);
if ($this->getType() === self::IM_TYPE_OPEN || $this->getType() === self::IM_TYPE_OPEN_LINE)
{
CPullWatch::AddToStack('IM_PUBLIC_' . $this->getChatId(), $pushMessage);
}
}
return $this;
}