- Модуль: mail
- Путь к файлу: ~/bitrix/modules/mail/lib/controller/secretary.php
- Класс: BitrixMailControllerSecretary
- Вызов: Secretary::createChatFromMessageAction
public function createChatFromMessageAction(int $messageId): ?int
{
if (!Loader::includeModule('im'))
{
return null;
}
global $USER;
$userId = $USER->GetID();
if (!$this->canBindEntities($messageId, (int)$userId))
{
$this->addError(new Error(Loc::getMessage('MAIL_SECRETARY_ACCESS_DENIED')));
return null;
}
$message = BitrixMailIntegrationIntranetSecretary::getMessage($messageId);
$messageData = $message->toArray();
$messageData['USER_IDS'] = [$USER->GetID()];
if ($chatId = BitrixIntranetSecretary::getChatIdIfExists($messageId, 'MAIL'))
{
// get back to chat if user left in past
if (! BitrixIntranetSecretary::isUserInChat($chatId, $userId))
{
BitrixIntranetSecretary::addUserToChat($chatId, $userId, false);
// // post welcome message again because it was hidden
// BitrixIntranetSecretary::postMailChatWelcomeMessage($message, $chatId, $userId);
}
}
else
{
$lockName = "chat_create_mail_{$messageId}";
if (!Application::getConnection()->lock($lockName))
{
$this->addError(new Error(
Loc::getMessage('MAIL_SECRETARY_CREATE_CHAT_LOCK_ERROR'), 'lock_error')
);
return null;
}
$chatId = BitrixIntranetSecretary::createMailChat($messageData, $userId);
Application::getConnection()->unlock($lockName);
}
if (Loader::includeModule('pull'))
{
$mailboxId = BitrixMailIntegrationIntranetSecretary::getMailboxIdForMessage($messageId);
if($mailboxId)
{
CPullWatch::addToStack(
'mail_mailbox_' . $mailboxId,
[
'module_id' => 'mail',
'command' => 'messageBindingCreated',
'params' => [
'messageId' => $messageId,
'mailboxId' => $mailboxId,
'entityType' => Message::ENTITY_TYPE_IM_CHAT,
'entityId' => $chatId,
'bindingEntityLink' =>
CComponentEngine::makePathFromTemplate(
'/online/?IM_DIALOG=chat#chat_id#',
[
'chat_id' => $chatId,
]
),
],
]
);
}
}
return $chatId;
}