3namespace Bitrix\Im\V2\Chat;
6use Bitrix\Im\Model\ChatTable;
9use Bitrix\Im\V2\Message\Send\MentionService;
10use Bitrix\Im\V2\Message\Send\SendingConfig;
11use Bitrix\Im\V2\Message\Send\SendingService;
12use Bitrix\Im\V2\MessageCollection;
13use Bitrix\Im\V2\Relation;
14use Bitrix\Im\V2\RelationCollection;
15use Bitrix\Im\V2\Result;
16use Bitrix\Im\V2\Message;
17use Bitrix\Main\Application;
18use Bitrix\Main\Loader;
19use Bitrix\Main\Localization\Loc;
20use Bitrix\Main\Type\DateTime;
37 $chatId = static::getIdByMessage(
$message);
43 if ($chat instanceof
self)
47 return $result->setResult($chat);
50 if (!$createIfNotExists)
68 $chatIds = static::getIdsByMessages(
$messages);
76 foreach ($chatIds as $chatInfo)
79 if ($chat instanceof
self)
81 $chat->parentMessage =
$messages[(int)$chatInfo[
'PARENT_MID']];
86 return $result->setResult($chats);
104 $isLocked = Application::getConnection()->lock(self::getLockName(
$message->getId()), self::LOCK_TIMEOUT);
111 if ($chat instanceof
self)
113 Application::getConnection()->unlock(self::getLockName(
$message->getId()));
116 return $result->setResult($chat);
119 $createResult = static::createInternal(
$message);
120 Application::getConnection()->unlock(self::getLockName(
$message->getId()));
122 return $createResult;
135 public function join(
bool $withMessage =
true):
Chat
139 return parent::join(
false);
144 if (isset($this->role))
149 $role = parent::getRole();
151 if ($role === self::ROLE_MEMBER)
177 if (!$sendingService->
getConfig()->skipCounterIncrements())
182 parent::onAfterMessageSend(
$message, $sendingService);
187 return $this->
getParentChat()->filterUsersToMention($userIds);
192 $relations = parent::getRelations();
193 $userIds = $relations->getUserIds();
199 $parentRelations = $this->
getParentChat()->getRelationsByUserIds($userIds);
201 return $relations->filter(
202 fn (
Relation $relation) => $parentRelations->getByUserId($relation->getUserId(), $this->getParentChatId())
215 return $this->
getParentChat()->getRelationsByUserIds($userIds);
220 $userId ??= $this->getContext()->getUserId();
223 $relation = $this->getRelationByUserId(
$userId);
225 if ($relation ===
null)
230 $relation->setNotifyBlock(!$subscribe)->save();
243 $userIds = parent::getValidUsersToAdd($userIds);
245 return $this->
getParentChat()->getRelationsByUserIds($userIds)->getUserIds();
259 $subscribedUsers = [];
262 $relation = $relations->getByUserId(
$userId, $this->getId());
263 if ($relation ===
null || !$relation->getNotifyBlock())
267 $relation->setNotifyBlock(
false);
275 $relations->save(
true);
283 if (!Loader::includeModule(
'pull') || empty($userIds))
291 'command' =>
'commentSubscribe',
293 'dialogId' => $this->getDialogId(),
294 'subscribe' => $subscribe,
295 'messageId' => $this->getParentMessageId(),
304 $parentFolder = $this->
getParentChat()->getOrCreateDiskFolder();
310 $folder = $parentFolder->addSubFolder(
312 'NAME' =>
"chat{$this->getId()}",
313 'CREATED_BY' => $this->getContext()->getUserId(),
321 $this->setDiskFolderId($folder->getId())->save();
331 return parent::createRelation(
$userId,
$config)->setLastId(0)->setNotifyBlock($notifyBlock);
336 return self::IM_TYPE_COMMENT;
341 $this->parentChat = $chat;
362 $this->parentMessage ??=
new Message($this->getParentMessageId());
384 $messageText = Loc::getMessage(
'IM_COMMENT_CREATE_V2');
387 'MESSAGE_TYPE' => $this->
getType(),
388 'TO_CHAT_ID' => $this->getChatId(),
390 'MESSAGE' => $messageText,
394 'SKIP_COUNTER_INCREMENTS' =>
'Y',
408 $result = parent::mirrorDataEntityFields();
410 'set' =>
'setParentMessage',
414 'set' =>
'setParentChat',
439 return parent::prepareParams(
$params);
449 'TYPE' => self::IM_TYPE_COMMENT,
456 if (!$addResult->isSuccess())
462 $chat = $addResult->getResult()[
'CHAT'];
464 $chat->sendPushChatCreate();
466 return $result->setResult($chat);
471 $row = ChatTable::query()
473 ->where(
'PARENT_ID',
$message->getChatId())
474 ->where(
'PARENT_MID',
$message->getId())
478 return (
int)($row[
'ID'] ?? 0);
491 ->setSelect([
'ID',
'PARENT_MID'])
492 ->where(
'PARENT_ID', $chatId)
493 ->whereIn(
'PARENT_MID',
$messages->getIds())
506 'command' =>
'chatCreate',
508 'id' => $this->getId(),
509 'parentChatId' => $this->getParentChatId(),
510 'parentMessageId' => $this->getParentMessageId(),
if(! $messageFields||!isset($messageFields['message_id'])||!isset($messageFields['status'])||!CModule::IncludeModule("messageservice")) $messageId
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static getType($chatData, bool $camelCase=true)
static raiseChat(\Bitrix\Im\V2\Chat $chat, RelationCollection $relations, ?DateTime $lastActivity=null)
const WRONG_PARENT_MESSAGE
static insert(Message $message)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']