10 public static function getTitle($dialogId, $userId =
null):? string
21 $chatData = ChatTable::getRow([
22 'select' => [
'TITLE'],
23 'filter' => [
'=ID' => $chatId],
30 return $chatData[
'TITLE'];
34 $chatId = \CIMMessage::GetChatId($dialogId, $userId);
45 return implode(
" - ", $userNames);
48 public static function getDialogId(
int $chatId, $userId =
null): string
50 $userId = \Bitrix\Im\Common::getUserId($userId);
56 $chat = \Bitrix\Im\Chat::getById($chatId);
65 return "chat{$chat['ID']}";
68 $query = ChatTable::query()
69 ->setSelect([
'DIALOG_ID' =>
'RELATION.USER_ID'])
70 ->registerRuntimeField(
73 new OneToMany(
'RELATION', RelationTable::class,
'CHAT')
74 )->configureJoinType(
'inner')
76 ->where(
'ID', (
int)$chatId)
78 ->whereNot(
'RELATION.USER_ID', $userId)
82 $queryResult = $query->fetch();
88 return $queryResult[
'DIALOG_ID'];
91 public static function getChatId($dialogId, $userId =
null)
93 if (preg_match(
'/^chat[0-9]{1,}$/i', $dialogId))
95 $chatId = (int)mb_substr($dialogId, 4);
97 else if (preg_match(
'/^\d{1,}$/i', $dialogId))
99 $dialogId = intval($dialogId);
105 $userId = \Bitrix\Im\Common::getUserId($userId);
111 $chatId = \CIMMessage::GetChatId($dialogId, $userId);
117 else if (preg_match(
'/^crm\|\w+?\|\d+?$/i', $dialogId))
119 $chatId = \CIMChat::GetCrmChatId(mb_substr($dialogId, 4));
121 else if (preg_match(
'/^sg[0-9]{1,}$/i', $dialogId))
123 $chatId = \CIMChat::GetSonetGroupChatId(mb_substr($dialogId, 2));
133 public static function getLink($dialogId, $userId =
null):? string
140 return '/online/?IM_DIALOG='.$dialogId;
143 public static function hasAccess($dialogId, $userId =
null)
145 $userId = \Bitrix\Im\Common::getUserId($userId);
155 return \Bitrix\Im\V2\Chat::getInstance($chatId)->hasAccess($userId);
158 return \Bitrix\Im\V2\Entity\User\User::getInstance($dialogId)->hasAccess($userId);
161 public static function read($dialogId, $messageId =
null, $userId =
null)
163 $userId = \Bitrix\Im\Common::getUserId($userId);
173 $chat = new \CIMChat($userId);
174 $result = $chat->SetReadMessage($chatId, $messageId);
176 else if ($dialogId ===
'notify')
178 $notify = new \CIMNotify();
179 $notify->MarkNotifyRead(0,
true);
185 $CIMMessage = new \CIMMessage($userId);
186 $result = $CIMMessage->SetReadMessage($dialogId, $messageId);
192 public static function readAll($userId =
null)
194 $userId = \Bitrix\Im\Common::getUserId($userId);
200 \Bitrix\Im\V2\Chat::readAllChats($userId);
205 public static function unread($dialogId, $messageId =
null, $userId =
null)
207 $userId = \Bitrix\Im\Common::getUserId($userId);
217 $chat = new \CIMChat($userId);
218 $chat->SetUnReadMessage($chatId, $messageId);
222 $CIMMessage = new \CIMMessage($userId);
223 $CIMMessage->SetUnReadMessage($dialogId, $messageId);
229 public static function getRelation($userId1, $userId2, $params = array())
231 $userId1 = intval($userId1);
232 $userId2 = intval($userId2);
234 if ($userId1 <= 0 || $userId2 <= 0)
239 $chatId = \CIMMessage::GetChatId($userId1, $userId2);
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 unread($dialogId, $messageId=null, $userId=null)
static getTitle($dialogId, $userId=null)
static read($dialogId, $messageId=null, $userId=null)
static getInstance($userId=null)