- Модуль: imopenlines
- Путь к файлу: ~/bitrix/modules/imopenlines/lib/chat.php
- Класс: BitrixImOpenLinesChat
- Вызов: Chat::finish
public function finish($userId = 0, bool $permissionOtherClose = true, bool $skipSendSystemMessage = false, bool $forcedSendVote = false): Result
{
$result = new Result();
$session = new Session();
$session->setChat($this);
if (
$this->isDataLoaded() &&
$session->load([
'USER_CODE' => $this->chat['ENTITY_ID'],
'SKIP_CREATE' => 'Y'
])
)
{
if($this->validationAction($session->getData('CHAT_ID')))
{
if(
$permissionOtherClose === true ||
(
$userId > 0 &&
$session->getData('OPERATOR_ID') == $userId
)
)
{
$queueManager = Queue::initialization($session);
if($queueManager && $queueManager->startLock())
{
if($userId > 0)
{
if(
$this->chat['AUTHOR_ID'] <= 0 &&
!User::getInstance($userId)->isConnector()
)
{
$this->answer($userId);
$session->load([
'USER_CODE' => $this->chat['ENTITY_ID'],
'SKIP_CREATE' => 'Y'
]);
}
elseif(
$permissionOtherClose === true &&
$session->getData('OPERATOR_ID') != $userId
)
{
$user = User::getInstance($userId);
$message = Loc::getMessage('IMOL_CHAT_CLOSE_'.$user->getGender(), [
'#USER#' => '[USER=' . $user->getId() . '][/USER]',
]);
Im::addMessage([
'TO_CHAT_ID' => $this->chat['ID'],
'MESSAGE' => $message,
'SYSTEM' => 'Y',
]);
}
}
if($skipSendSystemMessage === true)
{
$session->setDisabledSendSystemMessage(true);
}
if($forcedSendVote === true)
{
$session->setForcedSendVote(true);
}
$eventData = [
'RUNTIME_SESSION' => $session
];
$event = new Event('imopenlines', 'OnChatFinish', $eventData);
$event->send();
$session->finish();
if($skipSendSystemMessage === true)
{
$session->setDisabledSendSystemMessage(false);
}
if($forcedSendVote === true)
{
$session->setForcedSendVote(false);
}
$queueManager->stopLock();
$result->setResult(true);
}
}
else
{
$result->addError(new Error('Attempt to close the dialog by a user who is not an operator', self::ERROR_USER_NOT_OPERATOR, __METHOD__, ['USER_ID' => $userId, 'PERMISSION_OTHER_CLOSE' => $permissionOtherClose]));
}
}
else
{
$result->addError(new Error(Loc::getMessage('IMOL_CHAT_ERROR_NOT_LOAD_DATA'), 'IMOL_CHAT_ERROR_NOT_LOAD_DATA', __METHOD__, ['chat' => $this->chat]));
}
}
else
{
$result->addError(new Error('Session or chat failed to load', 'NOT_LOAD_SESSION_OR_CHAT', __METHOD__, ['USER_ID' => $userId, 'PERMISSION_OTHER_CLOSE' => $permissionOtherClose]));
}
return $result;
}