4use Bitrix\Im\Model\ChatTable;
5use Bitrix\Im\Model\RelationTable;
6use Bitrix\Main\ORM\Fields\Relations\OneToMany;
7use Bitrix\Main\ORM\Fields\Relations\Reference;
8use Bitrix\Main\ORM\Query\Join;
23 $chatData = ChatTable::getRow([
24 'select' => [
'TITLE'],
25 'filter' => [
'=ID' => $chatId],
32 return $chatData[
'TITLE'];
47 return implode(
" - ", $userNames);
67 return "chat{$chat['ID']}";
70 $query = ChatTable::query()
71 ->setSelect([
'DIALOG_ID' =>
'RELATION.USER_ID'])
72 ->registerRuntimeField(
75 new OneToMany(
'RELATION', RelationTable::class,
'CHAT')
76 )->configureJoinType(
'inner')
78 ->where(
'ID', (
int)$chatId)
80 ->whereNot(
'RELATION.USER_ID',
$userId)
84 $queryResult =
$query->fetch();
90 return $queryResult[
'DIALOG_ID'];
95 if (preg_match(
'/^chat[0-9]{1,}$/i', $dialogId))
97 $chatId = (int)mb_substr($dialogId, 4);
99 else if (preg_match(
'/^\d{1,}$/i', $dialogId))
101 $dialogId = intval($dialogId);
119 else if (preg_match(
'/^crm\|\w+?\|\d+?$/i', $dialogId))
121 $chatId = \CIMChat::GetCrmChatId(mb_substr($dialogId, 4));
123 else if (preg_match(
'/^sg[0-9]{1,}$/i', $dialogId))
125 $chatId = \CIMChat::GetSonetGroupChatId(mb_substr($dialogId, 2));
137 $dialogIds = array_filter($dialogIds,
function($dialogId) use ($currentUserId) {
138 return (
int)$dialogId !== $currentUserId;
141 if (empty($dialogIds))
148 $query = RelationTable::query()
149 ->setSelect([
'CHAT_ID',
'USER_ID'])
150 ->registerRuntimeField(
154 RelationTable::class,
155 Join::on(
'this.CHAT_ID',
'ref.CHAT_ID')
156 ->where(
'ref.USER_ID', $currentUserId)
158 [
'join_type' => Join::TYPE_INNER]
161 ->whereIn(
'USER_ID', $dialogIds)
166 while ($row =
$query->Fetch())
168 $chatIds[(int)$row[
'USER_ID']] = (
int)$row[
'CHAT_ID'];
181 return '/online/?IM_DIALOG='.$dialogId;
196 return \Bitrix\Im\V2\Chat::getInstance($chatId)->checkAccess(
$userId)->isSuccess();
199 return \Bitrix\Im\V2\Entity\User\User::getInstance($dialogId)->checkAccess(
$userId)->isSuccess();
217 else if ($dialogId ===
'notify')
219 $notify = new \CIMNotify();
220 $notify->MarkNotifyRead(0,
true);
226 $CIMMessage = new \CIMMessage(
$userId);
241 \Bitrix\Im\V2\Chat::readAllChats(
$userId);
263 $CIMMessage = new \CIMMessage(
$userId);
264 $CIMMessage->SetUnReadMessage($dialogId,
$messageId);
272 $userId1 = intval($userId1);
273 $userId2 = intval($userId2);
275 if ($userId1 <= 0 || $userId2 <= 0)
if(! $messageFields||!isset($messageFields['message_id'])||!isset($messageFields['status'])||!CModule::IncludeModule("messageservice")) $messageId
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static getById($id, $params=array())
static getRelation($chatId, $params=[])
static getUserId($userId=null)
static getLink($dialogId, $userId=null)
static getChatId($dialogId, $userId=null)
static getRelation($userId1, $userId2, $params=array())
static getDialogId(int $chatId, $userId=null)
static hasAccess($dialogId, $userId=null)
static readAll($userId=null)
static getChatIds(array $dialogIds, int $currentUserId)
static unread($dialogId, $messageId=null, $userId=null)
static getTitle($dialogId, $userId=null)
static read($dialogId, $messageId=null, $userId=null)
static getInstance($userId=null)
static GetChatId($fromUserId, $toUserId, $createIfNotExists=true)
</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']