- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/integration/im/chat.php
- Класс: Bitrix\Crm\Integration\Im\Chat
- Вызов: Chat::onEntityModification
static function onEntityModification($entityTypeID, $entityID, array $params)
{
if (!Main\Loader::includeModule('im'))
{
return;
}
$chatID = self::getChatId($entityTypeID, $entityID);
if($chatID <= 0)
{
return;
}
$currentFields = isset($params['CURRENT_FIELDS']) && is_array($params['CURRENT_FIELDS'])
? $params['CURRENT_FIELDS'] : [];
$previousFields = isset($params['PREVIOUS_FIELDS']) && is_array($params['PREVIOUS_FIELDS'])
? $params['PREVIOUS_FIELDS'] : [];
$removedObserverIDs = isset($params['REMOVED_OBSERVER_IDS']) && is_array($params['REMOVED_OBSERVER_IDS'])
? $params['REMOVED_OBSERVER_IDS'] : [];
$currentOwnerID = 0;
$currentTitle = '';
if (static::isEntitySupported((int)$entityTypeID))
{
$previousResponsibleID = $previousFields['ASSIGNED_BY_ID'] ?? 0;
if(isset($currentFields['ASSIGNED_BY_ID']) && $currentFields['ASSIGNED_BY_ID'] != $previousResponsibleID)
{
$currentOwnerID = (int)$currentFields['ASSIGNED_BY_ID'];
}
$previousTitle = $previousFields['TITLE'] ?? '';
if(isset($currentFields['TITLE']) && $currentFields['TITLE'] != $previousTitle)
{
$currentTitle = $currentFields['TITLE'];
}
}
if($currentOwnerID > 0 || $currentTitle !== '' || !empty($removedObserverIDs))
{
$chat = new \CIMChat(0);
if($currentOwnerID > 0)
{
$chat->AddUser($chatID, [ $currentOwnerID ], false, false);
$chat->SetOwner($chatID, $currentOwnerID, false);
}
if($currentTitle !== '')
{
$currentTitle = self::buildChatName(
[
'ENTITY_TYPE' => \CCrmOwnerType::ResolveName($entityTypeID),
'ENTITY_TITLE' => $currentTitle,
]
);
$chat->Rename($chatID, $currentTitle, false, false);
}
foreach($removedObserverIDs as $removedObserverID)
{
$chat->DeleteUser($chatID, $removedObserverID, false, false);
}
}
}