3namespace Bitrix\Im\V2\Chat;
6use Bitrix\Im\V2\Entity\User\User;
7use Bitrix\Im\V2\Message;
8use Bitrix\Im\V2\Message\Send\SendingConfig;
9use Bitrix\Im\V2\MessageCollection;
10use Bitrix\Im\V2\Relation\AddUsersConfig;
11use Bitrix\Im\V2\Relation\DeleteUserConfig;
12use Bitrix\Im\V2\RelationCollection;
13use Bitrix\Im\V2\Result;
14use Bitrix\ImOpenLines\Config;
15use Bitrix\ImOpenLines\Model\ChatIndexTable;
16use Bitrix\ImOpenLines;
17use Bitrix\Main\Application;
18use Bitrix\Main\Loader;
60 protected ?ImOpenLines\V2\Session\Session
$session =
null;
67 public function read(
bool $onlyRecent =
false,
bool $byEvent =
false,
bool $forceRead =
false):
Result
69 Recent::unread($this->getDialogId(),
false, $this->getContext()->getUserId());
73 $lastId = $this->getReadService()->getLastMessageIdInChat($this->chatId);
75 return (
new Result())->setResult([
76 'CHAT_ID' => $this->chatId,
78 'COUNTER' => $this->getReadService()->getCounterService()->getByChat($this->chatId),
79 'VIEWED_MESSAGES' => [],
90 $userId = $this->getContext()->getUserId();
92 $chat = $this->withContextUser(
$userId);
94 if ($chat->getSelfRelation() ===
null)
96 $chat->readMessages(
null, $byEvent, $forceRead);
105 if (!$forceRead && $this->getAuthorId() === 0)
110 return parent::readMessages(
$messages, $byEvent);
115 if (isset($this->fakeRelation))
120 return parent::getRelations();
132 $this->fakeRelation =
null;
143 elseif (Loader::includeModule(
'imopenlines'))
145 $userIds = (
new ImOpenLines\Relation($this->getId()))->getRelationUserIds();
146 if (!empty($userIds))
167 'date_create' =>
$session->getDateCreate(),
168 'statusGroup' =>
$session->getStatusGroup(),
169 'queueId' =>
$session->getConfigId(),
172 'operatorId' =>
$session->getOperatorId(),
178 if (!isset($this->session))
180 return $this->
getSession()?->getSessionId() ?? 0;
183 return $this->session->getSessionId();
188 if ($this->getEntityData1())
190 return (
int)(explode(
'|', $this->getEntityData1())[5] ?? 0);
198 if (isset($this->session))
203 if (!Loader::includeModule(
'imopenlines'))
210 $this->session = ImOpenLines\V2\Session\Session::getInstance($sessionId);
214 $this->session = ImOpenLines\V2\Session\Session::getInstanceByChatId($this->chatId);
222 return self::IM_TYPE_OPEN_LINE;
227 return self::ENTITY_TYPE_LINE;
232 $checkResult = parent::checkAccessInternal(
$userId);
234 if ($checkResult->isSuccess())
241 if (!Loader::includeModule(
'imopenlines'))
247 $canJoin = Config::canJoin(
263 $result = ImOpenLines\Model\RecentTable::query()
264 ->setSelect([
'USER_ID'])
265 ->where(
'CHAT_ID', $this->getChatId())
276 if (!Loader::includeModule(
'imopenlines'))
281 [$connectorType] = explode(
"|", $this->getEntityId() ??
'');
283 return in_array($connectorType, \
Bitrix\ImOpenlines\Connector::getListCanUpdateOwnMessage(),
true);
288 if (!Loader::includeModule(
'imopenlines'))
293 [$connectorType] = explode(
"|", $this->getEntityId() ??
'');
295 return in_array($connectorType, \
Bitrix\ImOpenlines\Connector::getListCanDeleteOwnMessage(),
true);
300 if (!Loader::includeModule(
'imopenlines'))
305 [$connectorType] = explode(
"|", $this->getEntityId() ??
'');
307 return in_array($connectorType, \
Bitrix\ImOpenlines\Connector::getListCanDeleteMessage(),
true);
317 return parent::validateAuthorId($authorId);
323 return parent::prepareParams(
$params);
328 if (Loader::includeModule(
'pull'))
330 \CPullWatch::Add($this->getContext()->getUserId(),
"IM_PUBLIC_{$this->getId()}",
true);
342 && Loader::includeModule(
'imopenlines')
343 && ImOpenLines\Recent::isRecentAvailableByStatus($this->
getSession()?->getStatus())
361 if (!Loader::includeModule(
'imopenlines'))
366 foreach ($this->getRelationsForSendMessage() as $relation)
368 ImOpenLines\Recent::setRecent(
369 $relation->getUserId(),
372 $this->getSessionId()
386 return parent::updateRelationsAfterMessageSend(
$message);
408 return parent::updateCountersAfterMessageSend(
$message, $sendingConfig);
435 if(!parent::isValidToAdd(
$userId))
442 return $user->isConnector() || (!
$user->isExtranet() && !
$user->isConnector());
457 parent::updateStateAfterRelationsAdd($usersToAdd);
459 if (Loader::includeModule(
'pull'))
461 foreach ($usersToAdd as
$userId)
463 \CPullWatch::Delete(
$userId,
'IM_PUBLIC_' . $this->getId());
477 $lastMessageId = $this->getLastMessageId();
480 ImOpenLines\Recent::setRecent(
$userId, $this->getId(), $lastMessageId, $this->
getSessionId());
489 parent::addUsersToRelation($usersToAdd,
$config);
494 if (!Loader::includeModule(
'imopenlines'))
499 ChatIndexTable::addIndex($this->getId(), $this->getTitle());
506 if (!Loader::includeModule(
'imopenlines'))
511 ChatIndexTable::updateIndex($this->getId(), $this->getTitle());
518 return isset($this->fakeRelation);
523 $popupData = parent::getPopupData($excludedList);
537 'TO_CHAT_ID' => $this->getId(),
539 'FROM_USER_ID' => $this->getContext()->getUserId(),
541 'RECENT_ADD' => $skipRecent ?
'N' :
'Y',
542 'PARAMS' => [
'CODE' =>
'CHAT_LEAVE',
'NOTIFY' =>
'Y'],
544 'SKIP_USER_CHECK' =>
'Y',
545 'SKIP_COUNTER_INCREMENTS' =>
'Y',
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static unread($dialogId, $unread, $userId=null, ?int $markedId=null, ?string $itemTypes=null)
getEntityData(bool $force=false)
updateCountersAfterMessageSend(Message $message, SendingConfig $sendingConfig)
sendNotificationUserDelete(int $userId, DeleteUserConfig $config)
checkAccessInternal(int $userId)
getFieldsForRecent(int $userId, Message $message)
setFakeRelation(array $userIds)
getUpdatedFieldsForRecent(Message $message)
setExtranet(?bool $extranet)
updateStateAfterRelationsAdd(array $usersToAdd)
getPopupData(array $excludedList=[])
validateAuthorId(int $authorId)
updateOpenlinesRecentAfterMessageSend(Message $message)
read(bool $onlyRecent=false, bool $byEvent=false, bool $forceRead=false)
onBeforeMessageSend(Message $message, SendingConfig $config)
setEntityMap(array $entityMap)
isValidToAdd(int $userId)
const EXTRANET_CAN_SEE_HISTORY
ImOpenLines V2 Session Session $session
readAllMessages(bool $byEvent=false, bool $forceRead=false)
prepareParams(array $params=[])
readMessages(?MessageCollection $messages, bool $byEvent=false, bool $forceRead=false)
addUsersToOpenlinesRecent(array $userIds)
RelationCollection $fakeRelation
updateRecentAfterMessageSend(Message $message, SendingConfig $config)
prepareMessageParamsFromUserDelete(string $message, bool $skipRecent)
needToUpdateOpenlinesRecent()
addUsersToRelation(array $usersToAdd, AddUsersConfig $config)
updateRelationsAfterMessageSend(Message $message)
checkAccessByRecentTable(int $userId)
getSessionIdByEntityData()
static createFake(array $userIds, Chat $chat)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']