13use Bitrix\ImOpenLines\Config;
14use Bitrix\ImOpenLines\Model\ChatIndexTable;
61 public function read(
bool $onlyRecent =
false,
bool $byEvent =
false,
bool $forceRead =
false):
Result
63 Recent::unread($this->getDialogId(),
false, $this->getContext()->getUserId());
67 $lastId = $this->getReadService()->getLastMessageIdInChat($this->chatId);
69 return (
new Result())->setResult([
70 'CHAT_ID' => $this->chatId,
72 'COUNTER' => $this->getReadService()->getCounterService()->getByChat($this->chatId),
73 'VIEWED_MESSAGES' => [],
82 $result = $this->
readMessages(
null, $byEvent, $forceRead);
84 $userId = $this->getContext()->getUserId();
86 $chat = $this->withContextUser($userId);
88 if ($chat->getSelfRelation() ===
null)
90 $chat->readMessages(
null, $byEvent, $forceRead);
99 if (!$forceRead && $this->getAuthorId() === 0)
104 return parent::readMessages($messages, $byEvent);
109 return self::IM_TYPE_OPEN_LINE;
114 return self::ENTITY_TYPE_LINE;
119 $inChat = parent::checkAccessWithoutCaching($userId);
126 if (!Loader::includeModule(
'imopenlines'))
132 return Config::canJoin(
141 if (!Loader::includeModule(
'imopenlines'))
146 [$connectorType] = explode(
"|", $this->getEntityId() ??
'');
148 return in_array($connectorType, \
Bitrix\ImOpenlines\Connector::getListCanUpdateOwnMessage(),
true);
153 $params[
'AUTHOR_ID'] = 0;
154 return parent::prepareParams($params);
159 if (Loader::includeModule(
'pull'))
161 \CPullWatch::Add($this->getContext()->getUserId(),
"IM_PUBLIC_{$this->getId()}",
true);
169 public function riseInRecent(
Message $message): void
172 foreach ($this->getRelations() as $relation)
180 if ($this->getEntityType() == self::ENTITY_TYPE_LINE)
182 if (
User::getInstance($relation->getUserId())->getExternalAuthId() ==
'imconnector')
187 if ($this->getEntityData1())
190 $fieldData = explode(
"|", $this->getEntityData1());
191 $sessionId = (int)$fieldData[5];
195 \CIMContactList::SetRecent([
196 'ENTITY_ID' => $this->getChatId(),
198 'CHAT_TYPE' => $this->getType(),
199 'USER_ID' => $relation->getUserId(),
200 'CHAT_ID' => $relation->getChatId(),
201 'RELATION_ID' => $relation->getId(),
202 'SESSION_ID' => $sessionId,
205 if ($relation->getUserId() == $message->
getAuthorId())
216 $filteredUsers = parent::filterUsersToAdd($userIds);
218 foreach ($filteredUsers as $key => $userId)
220 $user = \Bitrix\Im\V2\Entity\User\User::getInstance($userId);
221 if (!$user->isConnector() && ($user->isExtranet() || $user->isNetwork()))
223 unset($filteredUsers[$key]);
227 return $filteredUsers;
242 parent::updateStateAfterUsersAdd($usersToAdd);
244 if (Loader::includeModule(
'pull'))
246 foreach ($usersToAdd as $userId)
248 \CPullWatch::Delete($userId,
'IM_PUBLIC_' . $this->getId());
257 $pushMessage = parent::sendPushUsersAdd($usersToAdd, $oldRelations);
259 if (Loader::includeModule(
'pull'))
261 \CPullWatch::AddToStack(
'IM_PUBLIC_' . $this->getId(), $pushMessage);
267 protected function addUsersToRelation(array $usersToAdd, array $managerIds = [], ?
bool $hideHistory =
null)
269 parent::addUsersToRelation($usersToAdd, $managerIds,
false);
274 if (!Loader::includeModule(
'pull'))
279 parent::startRecordVoice();
281 \CPullWatch::AddToStack(
'IM_PUBLIC_'.$this->getId(), $pushFormatter->formatStartRecordVoice($this));
286 if (!Loader::includeModule(
'imopenlines'))
291 ChatIndexTable::addIndex($this->getId(), $this->getTitle());
298 if (!Loader::includeModule(
'imopenlines'))
303 ChatIndexTable::updateIndex($this->getId(), $this->getTitle());
310 parent::sendPushUpdateMessage($message);
312 $push = $pushFormat->formatMessageUpdate($message);
313 $push[
'params'][
'dialogId'] = $this->getDialogId();
314 \CPullWatch::AddToStack(
'IM_PUBLIC_' . $message->
getChatId(), $push);
static unread($dialogId, $unread, $userId=null, ?int $markedId=null)
getEntityData(bool $force=false)
setExtranet(?bool $extranet)
sendPushUpdateMessage(Message $message)
read(bool $onlyRecent=false, bool $byEvent=false, bool $forceRead=false)
setEntityMap(array $entityMap)
filterUsersToAdd(array $userIds)
addUsersToRelation(array $usersToAdd, array $managerIds=[], ?bool $hideHistory=null)
const EXTRANET_CAN_SEE_HISTORY
readAllMessages(bool $byEvent=false, bool $forceRead=false)
prepareParams(array $params=[])
readMessages(?MessageCollection $messages, bool $byEvent=false, bool $forceRead=false)
sendPushUsersAdd(array $usersToAdd, RelationCollection $oldRelations)
checkAccessWithoutCaching(int $userId)
updateStateAfterUsersAdd(array $usersToAdd)