- Модуль: imopenlines
- Путь к файлу: ~/bitrix/modules/imopenlines/lib/session.php
- Класс: BitrixImOpenLinesSession
- Вызов: Session::prepareUserChat
private function prepareUserChat($params, $count = 0)
{
$result = false;
$resultUserRelation = BitrixImopenlinesModelUserRelationTable::getByPrimary($params['USER_CODE'])->fetch();
if ($resultUserRelation)
{
if ($resultUserRelation['CHAT_ID'])
{
if (
!($this->chat instanceof Chat)
|| ($this->chat->getData('ID') != $resultUserRelation['CHAT_ID'])
)
{
$this->chat = new Chat($resultUserRelation['CHAT_ID'], $params);
}
if ($this->chat->isDataLoaded())
{
$this->user = $resultUserRelation;
$result = true;
}
}
elseif ($count <= 20)
{
usleep(500);
$result = $this->prepareUserChat($params, ++$count);
}
}
elseif ($params['SKIP_CREATE'] != 'Y')
{
$params['USER_ID'] = intval($params['USER_ID']);
BitrixImopenlinesModelUserRelationTable::add([
'USER_CODE' => $params['USER_CODE'],
'USER_ID' => $params['USER_ID']
]);
$this->chat = new Chat();
$this->chat->load([
'USER_CODE' => $params['USER_CODE'],
'USER_ID' => $params['USER_ID'],
'LINE_NAME' => $this->config['LINE_NAME'],
'CONNECTOR' => $params['CONNECTOR'],
]);
if ($this->chat->isDataLoaded())
{
BitrixImopenlinesModelUserRelationTable::update($params['USER_CODE'], ['CHAT_ID' => $this->chat->getData('ID')]);
$resultUserRelation = [
'USER_CODE' => $params['USER_CODE'],
'USER_ID' => $params['USER_ID'],
'CHAT_ID' => $this->chat->getData('ID'),
'AGREES' => 'N',
];
$this->user = $resultUserRelation;
$result = true;
}
else
{
BitrixImopenlinesModelUserRelationTable::delete($params['USER_CODE']);
}
}
return $result;
}