1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
chat.php
См. документацию.
1<?php
2namespace Bitrix\Im;
3
4use Bitrix\Im\Model\BlockUserTable;
5use Bitrix\Im\V2\Chat\Background\Background;
6use Bitrix\Im\V2\Chat\EntityLink;
7use Bitrix\Im\V2\Chat\ExtendedType;
8use Bitrix\Im\V2\Chat\GeneralChannel;
9use Bitrix\Im\V2\Chat\GeneralChat;
10use Bitrix\Im\V2\Chat\TextField\TextFieldEnabled;
11use Bitrix\Im\V2\Message\CounterService;
12use Bitrix\Im\V2\Message\Delete\DisappearService;
13use Bitrix\Im\V2\Message\ReadService;
14use Bitrix\Main\Application;
15use Bitrix\Main\Engine\Response\Converter;
16use Bitrix\Main\Loader;
17use Bitrix\Main\Localization\Loc;
18use Bitrix\Main\Type\DateTime;
19
20Loc::loadMessages(__FILE__);
21
22class Chat
23{
24 const TYPE_SYSTEM = 'S';
25 const TYPE_PRIVATE = 'P';
26 const TYPE_OPEN = 'O';
27 const TYPE_THREAD = 'T';
28 const TYPE_GROUP = 'C';
29 const TYPE_CHANNEL = 'N';
30 const TYPE_OPEN_LINE = 'L';
31
32 const STATUS_UNREAD = 0;
33 const STATUS_NOTIFY = 1;
34 const STATUS_READ = 2;
35
36 const LIMIT_SEND_EVENT = 30;
37
38 const FILTER_LIMIT = 50;
39
40 public static function getTypes()
41 {
42 return \CIMChat::getGroupTypes();
43 }
44
45 public static function getType($chatData, bool $camelCase = true)
46 {
47 $messageType = $chatData["TYPE"] ?? $chatData["CHAT_TYPE"] ?? '';
48 $entityType = $chatData["ENTITY_TYPE"] ?? $chatData["CHAT_ENTITY_TYPE"] ?? '';
49 $chatId = $chatData['ID'] ?? $chatData['CHAT_ID'] ?? null;
50
51 $messageType = trim($messageType);
52 $entityType = trim($entityType);
53
54 $type = ExtendedType::tryFromTypeLiteral($messageType);
55
56 $result = match (true)
57 {
58 self::isGeneralChannel($chatId, $messageType, $entityType) => ExtendedType::GeneralChannel->value,
59 self::isGeneralChat($chatId, $messageType, $entityType) => ExtendedType::General->value,
60 !in_array($type, [ExtendedType::Chat, ExtendedType::OpenChat], true) => $type->value,
61 !empty($entityType) => $entityType,
62 default => $type->value,
63 };
64
65 if ($camelCase)
66 {
67 $result = Converter::toJson()->process($result);
68 }
69
71 }
72
73 protected static function isGeneralChat(?int $chatId, string $typeLiteral, string $entityType): bool
74 {
75 return (
76 ExtendedType::tryFromTypeLiteral($typeLiteral) === ExtendedType::OpenChat
77 && ExtendedType::tryFromEntityType($entityType) === ExtendedType::General
78 )
79 || $chatId === (int)GeneralChat::getGeneralChatId()
80 ;
81 }
82
83 protected static function isGeneralChannel(?int $chatId, string $typeLiteral, string $entityType): bool
84 {
85 return (
86 ExtendedType::tryFromTypeLiteral($typeLiteral) === ExtendedType::OpenChannel
87 && ExtendedType::tryFromEntityType($entityType) === ExtendedType::GeneralChannel
88 )
89 || $chatId === (int)GeneralChannel::getGeneralChannelId()
90 ;
91 }
92
93 public static function getRelation($chatId, $params = [])
94 {
95 $chatId = intval($chatId);
96 if ($chatId <= 0)
97 {
98 return false;
99 }
100
101 $connection = Application::getInstance()->getConnection();
102
103 $selectFields = '';
104 if (isset($params['SELECT']))
105 {
106 $params['SELECT'][] = 'ID';
107 $params['SELECT'][] = 'USER_ID';
109 foreach ($params['SELECT'] as $key => $value)
110 {
111 if (is_int($key) && isset($map[$value]))
112 {
113 $selectFields .= "R.{$value}, ";
114 unset($map[$value]);
115 }
116 else if (!is_int($key) && isset($map[$key]))
117 {
118 $value = (string)$value;
119 $selectFields .= "R.{$key} '{$connection->getSqlHelper()->forSql($value)}', ";
120 unset($map[$value]);
121 }
122 }
123 }
124 if (!$selectFields)
125 {
126 $selectFields = 'R.*, ';
127 }
128
129 $withUserFields = false;
130 if (isset($params['USER_DATA']) && $params['USER_DATA'] == 'Y')
131 {
132 $withUserFields = true;
133 $list = Array('ACTIVE', 'EXTERNAL_AUTH_ID');
134 foreach ($list as $key)
135 {
136 $selectFields .= "U.{$key} USER_DATA_{$key}, ";
137 }
138 }
139 $skipUsers = false;
140 $skipUserInactiveSql = '';
141 if (isset($params['SKIP_INACTIVE_USER']) && $params['SKIP_INACTIVE_USER'] === 'Y')
142 {
143 $skipUsers = true;
144 $skipUserInactiveSql = "AND U.ACTIVE = 'Y'";
145 }
146
147 $skipUserTypes = $params['SKIP_USER_TYPES'] ?? [];
148 if (isset($params['SKIP_CONNECTOR']) && $params['SKIP_CONNECTOR'] === 'Y')
149 {
150 $skipUserTypes[] = 'imconnector';
151 }
152
153 $skipUserTypesSql = '';
154 if (!empty($skipUserTypes))
155 {
156 $skipUsers = true;
157 if (count($skipUserTypes) === 1)
158 {
159 $skipUserTypesSql = "AND (U.EXTERNAL_AUTH_ID != '".$connection->getSqlHelper()->forSql($skipUserTypes[0])."' OR U.EXTERNAL_AUTH_ID IS NULL)";
160 }
161 else
162 {
163 $skipUserTypes = array_map(function($type) use ($connection) {
164 return $connection->getSqlHelper()->forSql($type);
165 }, $skipUserTypes);
166
167 $skipUserTypesSql = "AND (U.EXTERNAL_AUTH_ID NOT IN ('".implode("','", $skipUserTypes)."') OR U.EXTERNAL_AUTH_ID IS NULL)";
168 }
169 }
170
171 $whereFields = '';
172 if (isset($params['FILTER']))
173 {
175 foreach ($params['FILTER'] as $key => $value)
176 {
177 if (!isset($map[$key]))
178 {
179 continue;
180 }
181
182 if (is_int($value))
183 {
184 }
185 else if (is_bool($value))
186 {
187 $value = $value? "'Y'": "'N'";
188 }
189 else if (is_string($value))
190 {
191 $value = "'{$connection->getSqlHelper()->forSql($value)}'";
192 }
193 else
194 {
195 continue;
196 }
197
198 $whereFields .= " AND R.{$key} = {$value}";
199 }
200 }
201
202 $limit = '';
203 if (isset($params['LIMIT']))
204 {
205 $limit = 'LIMIT '.(int)$params['LIMIT'];
206 }
207
208 $offset = '';
209 if (isset($params['OFFSET']))
210 {
211 $offset = 'OFFSET '.(int)$params['OFFSET'];
212 }
213
214 $orderField = 'R.ID';
215
216 if (isset($params['LAST_USER_ID']) && (int)$params['LAST_USER_ID'] >= 0)
217 {
218 $lastUserId = (int)$params['LAST_USER_ID'];
219 $whereFields .= " AND R.USER_ID > {$lastUserId}";
220 $orderField = 'R.USER_ID';
221 }
222
223 $selectFields = rtrim($selectFields, ', ');
224 $sql = "
225 SELECT {$selectFields}
226 FROM b_im_relation R
227 ".($withUserFields && !$skipUsers? "LEFT JOIN b_user U ON R.USER_ID = U.ID": "")."
228 ".($skipUsers? "INNER JOIN b_user U ON R.USER_ID = U.ID {$skipUserInactiveSql} {$skipUserTypesSql}": "")."
229 WHERE R.CHAT_ID = {$chatId} {$whereFields}
230 ORDER BY {$orderField} ASC
231 {$limit} {$offset}
232 ";
233 $relations = array();
234 $query = $connection->query($sql);
235 while ($row = $query->fetch())
236 {
237 foreach ($row as $key => $value)
238 {
239 if (mb_strpos($key, 'USER_DATA_') === 0)
240 {
241 $row['USER_DATA'][mb_substr($key, 10)] = $value;
242 unset($row[$key]);
243 }
244 }
245
246 $relations[$row['USER_ID']] = $row;
247 }
248
249 $userIds = array_keys($relations);
250
251 if (($params['RAW_RELATIONS'] ?? 'N') === 'N')
252 {
253 $relations = self::filterRelationsByAccess($chatId, $relations);
254 }
255
256 // region New counter
257 // todo: select counter only if it's need
258 if (!isset($params['WITHOUT_COUNTERS']) || $params['WITHOUT_COUNTERS'] !== 'Y')
259 {
260
261 $readService = new ReadService();
262 $counters = $readService->getCounterService()->getByChatForEachUsers($chatId, $userIds);
263 $lastIdInChat = $readService->getLastMessageIdInChat($chatId);
264 $lastReads = $readService->getViewedService()->getDateViewedByMessageIdForEachUser($lastIdInChat, $userIds);
265 foreach ($relations as $userId => $relation)
266 {
267 $counter = $counters[$userId] ?? 0;
268 $counter = $counter > 99 ? 100 : $counter;
269 $relations[$userId]['COUNTER'] = $counter;
270 $relations[$userId]['LAST_READ'] = $lastReads[$userId] ?? null;
271 }
272 }
273 // endregion
274
275 return $relations;
276 }
277
278 public static function mute($chatId, $action, $userId = null)
279 {
281 if (!$userId)
282 {
283 return false;
284 }
285
286 $chatId = intval($chatId);
287 if (!$chatId)
288 {
289 return false;
290 }
291
292 $action = $action === true? 'Y': 'N';
293
294 (new CounterService())->withContextUser($userId)->updateIsMuted($chatId, $action);
295
296 $relation = self::getRelation($chatId, Array(
297 'SELECT' => Array('ID', 'MESSAGE_TYPE', 'NOTIFY_BLOCK', 'COUNTER'),
298 'FILTER' => Array(
299 'USER_ID' => $userId
300 ),
301 ));
302 if (!$relation)
303 {
304 return false;
305 }
306
307 if ($relation[$userId]['NOTIFY_BLOCK'] == $action)
308 {
309 return true;
310 }
311
312 \Bitrix\Im\Model\RelationTable::update($relation[$userId]['ID'], array('NOTIFY_BLOCK' => $action));
313
315 $chat = \Bitrix\Im\Chat::getById($chatId);
316 //Counter::clearCache($userId);
317
318 if (\Bitrix\Main\Loader::includeModule('pull'))
319 {
320 $element = \Bitrix\Im\Model\RecentTable::getList([
321 'select' => ['USER_ID', 'ITEM_TYPE', 'ITEM_ID', 'UNREAD'],
322 'filter' => [
323 '=USER_ID' => $userId,
324 '=ITEM_TYPE' => $relation[$userId]['MESSAGE_TYPE'],
325 '=ITEM_ID' => $chatId
326 ]
327 ])->fetch();
328
329 $counter = $relation[$userId]['COUNTER'];
330 $chatObject = \Bitrix\Im\V2\Chat::getInstance($chatId);
331
333 'module_id' => 'im',
334 'command' => 'chatMuteNotify',
335 'params' => Array(
336 'chatId' => $chatId,
337 'dialogId' => 'chat'.$chatId,
338 'muted' => $action == 'Y',
339 'mute' => $action == 'Y', // TODO remove this later
340 'counter' => $counter,
341 'lines' => $element['ITEM_TYPE'] === self::TYPE_OPEN_LINE,
342 'unread' => ($element['UNREAD'] ?? 'N') === 'Y',
343 'counterType' => $chatObject->getCounterType()->value,
344 'recentConfig' => $chatObject->getRecentConfig()->toPullFormat(),
345 ),
346 'extra' => \Bitrix\Im\Common::getPullExtra()
347 ));
348 }
349
350 foreach(\Bitrix\Main\EventManager::getInstance()->findEventHandlers("im", "OnAfterChatMuteNotify") as $event)
351 {
353 'CHAT_ID' => $chatId,
354 'USER_ID' => $userId,
355 'MUTE' => $action == 'Y',
356 'CHAT' => $chat,
357 ]]);
358 }
359
360 return true;
361 }
362
363 public static function getMessageCount($chatId, $userId = null)
364 {
365 $chatId = intval($chatId);
366 if (!$chatId)
367 {
368 return false;
369 }
370
372 if (!$userId)
373 {
374 return false;
375 }
376
377 $relationData = \Bitrix\Im\Model\RelationTable::getList(Array(
378 'select' => Array('START_ID'),
379 'filter' => Array('=CHAT_ID' => $chatId, '=USER_ID' => $userId)
380 ))->fetch();
381
382 if (!$relationData || $relationData['START_ID'] == 0)
383 {
384 $counter = \Bitrix\Im\Model\MessageTable::getCount(['=CHAT_ID' => $chatId]);
385 }
386 else
387 {
388 $counter = \Bitrix\Im\Model\MessageTable::getCount(['=CHAT_ID' => $chatId, '>=ID' => $relationData['START_ID']]);
389 }
390
391 return $counter > 0 ? $counter : 0;
392 }
393
394 public static function hasAccess($chatId)
395 {
396 $chatId = intval($chatId);
397 if (!$chatId)
398 {
399 return false;
400 }
401
402 return \Bitrix\Im\Dialog::hasAccess('chat'.$chatId);
403 }
404
411 public static function getMessages($chatId, $userId = null, $options = Array())
412 {
414 if (!$userId)
415 {
416 return false;
417 }
418
419 $chatData = \Bitrix\Im\Model\ChatTable::getList(Array(
420 'select' => Array(
421 'CHAT_ID' => 'ID',
422 'CHAT_TYPE' => 'TYPE',
423 'CHAT_ENTITY_TYPE' => 'ENTITY_TYPE',
424 'CHAT_ENTITY_ID' => 'ENTITY_ID',
425 'RELATION_USER_ID' => 'RELATION.USER_ID',
426 'RELATION_START_ID' => 'RELATION.START_ID',
427 //'RELATION_UNREAD_ID' => 'RELATION.UNREAD_ID',
428 'RELATION_LAST_ID' => 'RELATION.LAST_ID',
429 //'RELATION_STATUS' => 'RELATION.STATUS',
430 //'RELATION_COUNTER' => 'RELATION.COUNTER'
431 ),
432 'filter' => Array('=ID' => $chatId),
433 'runtime' => Array(
434 new \Bitrix\Main\Entity\ReferenceField(
435 'RELATION',
436 '\Bitrix\Im\Model\RelationTable',
437 array(
438 "=ref.CHAT_ID" => "this.ID",
439 "=ref.USER_ID" => new \Bitrix\Main\DB\SqlExpression('?i', $userId)
440 ),
441 array("join_type"=>"LEFT")
442 )
443 )
444 ))->fetch();
445 if (!$chatData)
446 {
447 return false;
448 }
449
450 $readService = new ReadService($userId);
451
452 $chatData['RELATION_UNREAD_ID'] = $readService->getCounterService()->getIdFirstUnreadMessage($chatId) ?? 0;
453 $chatData['RELATION_COUNTER'] = $readService->getCounterService()->getByChat($chatId);
454 $chatData['RELATION_START_ID'] = (int)$chatData['RELATION_START_ID'];
455
456 if (isset($options['LIMIT']))
457 {
458 $options['LIMIT'] = intval($options['LIMIT']);
459 $limit = $options['LIMIT'] >= 100? 100: $options['LIMIT'];
460 }
461 else
462 {
463 $limit = 50;
464 }
465
466 $filter = Array(
467 '=CHAT_ID' => $chatId
468 );
469
470 $fileSort = 'ASC';
471 $startFromUnread = false;
472 if (
473 !isset($options['LAST_ID'])
474 && !isset($options['FIRST_ID'])
475 //&& $chatData['RELATION_STATUS'] != \Bitrix\Im\Chat::STATUS_READ
476 && $chatData['RELATION_COUNTER'] > 0
477 )
478 {
479 if ($chatData['RELATION_COUNTER'] > $limit)
480 {
481 $startFromUnread = true;
482 $options['FIRST_ID'] = $chatData['RELATION_LAST_ID'];
483 }
484 else
485 {
486 $limit += $chatData['RELATION_COUNTER'];
487 }
488 }
489
490 if (isset($options['FIRST_ID']))
491 {
492 $orderId = [];
493 $orderResult = [];
494
495 if ($chatData['RELATION_START_ID'] > 0 && intval($options['FIRST_ID']) < $chatData['RELATION_START_ID'])
496 {
497 $filter['>=ID'] = $chatData['RELATION_START_ID'];
498 }
499 else
500 {
501 if (intval($options['FIRST_ID']) > 0)
502 {
503 $filter['>ID'] = $options['FIRST_ID'];
504 }
505 }
506 }
507 else
508 {
509 $fileSort = 'DESC';
510 $orderId = Array('CHAT_ID' => 'ASC', 'ID' => 'DESC');
511 $orderResult = Array('ID' => 'DESC');
512
513 if ($chatData['RELATION_START_ID'] > 0)
514 {
515 $filter['>=ID'] = $chatData['RELATION_START_ID'];
516 }
517
518 if (isset($options['LAST_ID']) && intval($options['LAST_ID']) > 0)
519 {
520 $filter['<ID'] = intval($options['LAST_ID']);
521 }
522 }
523
524 $orm = \Bitrix\Im\Model\MessageTable::getList(array(
525 'select' => ['ID'],
526 'filter' => $filter,
527 'order' => $orderId,
528 'limit' => $limit
529 ));
530 $ids = array_map(fn ($item) => $item['ID'], $orm->fetchAll());
531 if (empty($ids))
532 {
533 $result = [
534 'CHAT_ID' => (int)$chatId,
535 'MESSAGES' => [],
536 'USERS' => [],
537 'FILES' => [],
538 ];
539 if ($options['JSON'])
540 {
541 $result = array_change_key_case($result, CASE_LOWER);
542 }
543 return $result;
544 }
545
546 $orm = \Bitrix\Im\Model\MessageTable::getList(array(
547 'select' => [
548 'ID', 'AUTHOR_ID', 'DATE_CREATE', 'NOTIFY_EVENT', 'MESSAGE',
549 'USER_LAST_ACTIVITY_DATE' => 'AUTHOR.LAST_ACTIVITY_DATE',
550 /*'USER_IDLE' => 'STATUS.IDLE',
551 'USER_MOBILE_LAST_DATE' => 'STATUS.MOBILE_LAST_DATE',
552 'USER_DESKTOP_LAST_DATE' => 'STATUS.DESKTOP_LAST_DATE',*/
553 'MESSAGE_UUID' => 'UUID.UUID',
554 ],
555 'filter' => ['=ID' => $ids],
556 'order' => $orderResult,
557 ));
558
559 $users = Array();
560
561 $userOptions = ['SKIP_ONLINE' => 'Y'];
562 if ($options['JSON'] == 'Y')
563 {
564 $userOptions['JSON'] = 'Y';
565 }
566 if ($chatData['CHAT_ENTITY_TYPE'] == 'LIVECHAT')
567 {
568 [$lineId] = explode('|', $chatData['CHAT_ENTITY_ID']);
569 $userOptions['LIVECHAT'] = $lineId;
570 $userOptions['USER_CODE'] = 'livechat|' . $lineId . '|' . $chatData['CHAT_ID'] . '|' . $userId;
571 }
572
573 $messages = Array();
574 while($message = $orm->fetch())
575 {
576 if ($message['NOTIFY_EVENT'] == 'private_system')
577 {
578 $message['AUTHOR_ID'] = 0;
579 }
580
581 if (isset($options['USER_TAG_SPREAD']) && $options['USER_TAG_SPREAD'] === 'Y')
582 {
583 $message['MESSAGE'] = preg_replace_callback("/\[USER=([0-9]{1,})\]\[\/USER\]/i", Array('\Bitrix\Im\Text', 'modifyShortUserTag'), $message['MESSAGE']);
584 }
585
586 $messages[$message['ID']] = Array(
587 'ID' => (int)$message['ID'],
588 'CHAT_ID' => (int)$chatId,
589 'AUTHOR_ID' => (int)$message['AUTHOR_ID'],
590 'DATE' => $message['DATE_CREATE'],
591 'TEXT' => (string)\Bitrix\Im\Text::parse($message['MESSAGE']),
592 'UNREAD' => $chatData['RELATION_USER_ID'] > 0 && $chatData['RELATION_LAST_ID'] < $message['ID'],
593 'UUID' => $message['MESSAGE_UUID'],
594 );
595 $messages[$message['ID']]['REPLACES'] = \Bitrix\Im\Text::getReplaceMap($messages[$message['ID']]['TEXT']);
596 if ($message['AUTHOR_ID'] && !isset($users[$message['AUTHOR_ID']]))
597 {
598 $user = User::getInstance($message['AUTHOR_ID'])->getArray($userOptions);
599 $user['last_activity_date'] = $message['USER_LAST_ACTIVITY_DATE']? date('c', $message['USER_LAST_ACTIVITY_DATE']->getTimestamp()): false;
600 $user['desktop_last_date'] = false;
601 $user['mobile_last_date'] = false;
602 $user['idle'] = false;
603
604 $users[$message['AUTHOR_ID']] = $user;
605 }
606 if ($options['CONVERT_TEXT'])
607 {
608 $messages[$message['ID']]['TEXT_CONVERTED'] = \Bitrix\Im\Text::parseLegacyFormat($message['MESSAGE']);
609 }
610 }
611
612 $params = \CIMMessageParam::Get(array_keys($messages));
613
614 $fileIds = Array();
615 foreach ($params as $messageId => $param)
616 {
617 $messages[$messageId]['PARAMS'] = empty($param)? []: $param;
618
619 if (
620 empty($messages[$messageId]['TEXT'])
621 && !isset($param['FILE_ID'])
622 && !isset($param['KEYBOARD'])
623 && !isset($param['ATTACH'])
624 )
625 {
626 $messages[$messageId]['TEXT'] = Loc::getMessage('IM_CHAT_MESSAGE_DELETED');
627 $messages[$messageId]['PARAMS']['IS_DELETED'] = 'Y';
628 }
629
630 if (isset($param['FILE_ID']))
631 {
632 foreach ($param['FILE_ID'] as $fileId)
633 {
634 $fileIds[$fileId] = $fileId;
635 }
636 }
637
638 if (isset($param['CHAT_USER']) && is_array($param['CHAT_USER']))
639 {
640 foreach ($param['CHAT_USER'] as $paramsUserId)
641 {
642 $users[$paramsUserId] = User::getInstance($paramsUserId)->getArray($userOptions);
643 }
644 }
645 }
646
647 $disappearing = DisappearService::getMessagesDisappearingTime(array_keys($messages));
648 foreach ($messages as $messageId => $message)
649 {
650 if (
651 isset($disappearing[$messageId])
652 && $disappearing[$messageId]['DATE_REMOVE'] instanceof DateTime
653 )
654 {
655 $messages[$messageId]['DISAPPEARING_DATE'] = $disappearing[$messageId]['DATE_REMOVE']->format(DATE_ATOM);
656 }
657 else
658 {
659 $messages[$messageId]['DISAPPEARING_DATE'] = null;
660 }
661 }
662
664
665 $files = \CIMDisk::GetFiles($chatId, $fileIds);
666
667 $result = Array(
668 'CHAT_ID' => (int)$chatId,
669 'MESSAGES' => $messages,
670 'USERS' => array_values($users),
671 'FILES' => array_values($files),
672 );
673
674 if (count($files) && $fileSort == 'DESC')
675 {
676 $result['FILES'] = array_reverse($result['FILES']);
677 }
678
679 if ($startFromUnread)
680 {
681 $result['MESSAGES'] = array_reverse($result['MESSAGES']);
682 $additionalMessages = self::getMessages($chatId, $userId, [
683 'LIMIT' => $limit,
684 'LAST_ID' => $chatData['RELATION_UNREAD_ID']
685 ]);
686 $result['MESSAGES'] = array_merge($result['MESSAGES'], $additionalMessages['MESSAGES']);
687 }
688
689 if ($options['JSON'])
690 {
691 foreach ($result['MESSAGES'] as $key => $value)
692 {
693 if ($value['DATE'] instanceof \Bitrix\Main\Type\DateTime)
694 {
695 $result['MESSAGES'][$key]['DATE'] = date('c', $value['DATE']->getTimestamp());
696 }
697
698 if (isset($value['PARAMS']['CHAT_LAST_DATE']) && $value['PARAMS']['CHAT_LAST_DATE'] instanceof \Bitrix\Main\Type\DateTime)
699 {
700 $result['MESSAGES'][$key]['PARAMS']['CHAT_LAST_DATE'] = date('c', $value['PARAMS']['CHAT_LAST_DATE']->getTimestamp());
701 }
702
703 if (is_array($value['REPLACES']) && !empty($value['REPLACES']))
704 {
705 $result['MESSAGES'][$key]['REPLACES'] = Common::toJson($value['REPLACES']);
706 }
707
708 $result['MESSAGES'][$key] = array_change_key_case($result['MESSAGES'][$key], CASE_LOWER);
709 }
710 $result['MESSAGES'] = array_values($result['MESSAGES']);
711
712 foreach ($result['FILES'] as $key => $value)
713 {
714 if ($value['date'] instanceof \Bitrix\Main\Type\DateTime)
715 {
716 $result['FILES'][$key]['date'] = date('c', $value['date']->getTimestamp());
717 }
718
719 foreach (['urlPreview', 'urlShow', 'urlDownload'] as $field)
720 {
721 $url = $result['FILES'][$key][$field];
722 if (is_string($url) && $url && mb_strpos($url, 'http') !== 0)
723 {
724 $result['FILES'][$key][$field] = \Bitrix\Im\Common::getPublicDomain().$url;
725 }
726 }
727
728 }
729
730 $result = array_change_key_case($result, CASE_LOWER);
731 }
732
733 return $result;
734 }
735
736 public static function getUsers($chatId, $options = []): array
737 {
738 $params = [
739 'SELECT' => ['ID', 'USER_ID'],
740 'SKIP_INACTIVE_USER' => 'Y',
741 'WITHOUT_COUNTERS' => 'Y',
742 ];
743
744 $skipExternal = isset($options['SKIP_EXTERNAL']) || isset($options['SKIP_EXTERNAL_EXCEPT_TYPES']);
745 if ($skipExternal)
746 {
747 $exceptType = $options['SKIP_EXTERNAL_EXCEPT_TYPES'] ?? [];
748 $params['SKIP_USER_TYPES'] = \Bitrix\Im\Model\UserTable::filterExternalUserTypes($exceptType);
749 }
750
751 if (isset($options['LIMIT']))
752 {
753 $params['LIMIT'] = $options['LIMIT'];
754 }
755 if (isset($options['OFFSET']))
756 {
757 $params['OFFSET'] = $options['OFFSET'];
758 }
759 if (isset($options['LAST_ID']))
760 {
761 $params['LAST_USER_ID'] = (int)$options['LAST_ID'];
762 }
763
764 $json = isset($options['JSON']) && $options['JSON'] === 'Y' ? 'Y' : 'N';
765 $users = [];
766 $relations = self::getRelation($chatId, $params);
767 foreach ($relations as $user)
768 {
769 $userData = \Bitrix\Im\User::getInstance($user['USER_ID'])->getArray([
770 'JSON' => $json
771 ]);
772
773 if ($userData['bot'])
774 {
775 $converter = new Converter(Converter::TO_SNAKE | Converter::TO_LOWER | Converter::KEYS);
776
777 $botData = \Bitrix\Im\V2\Entity\User\Data\BotData::getInstance((int)$user['USER_ID'])->toRestFormat();
778 $userData['bot_data'] = (!empty($botData)) ? $converter->process($botData) : null;
779 }
780 else
781 {
782 $userData['bot_data'] = null;
783 }
784
785 $users[] = $userData;
786 }
787
788 return $users;
789 }
790
800 public static function getById($id, $params = array())
801 {
802 $userId = \Bitrix\Im\Common::getUserId($params['USER_ID'] ?? null);
803 if (!$userId)
804 {
805 return false;
806 }
807
808 $checkAccessParam = $params['CHECK_ACCESS'] ?? null;
809 $chats = self::getList(Array(
810 'FILTER' => Array('ID' => $id),
811 'SKIP_ACCESS_CHECK' => $checkAccessParam === 'Y'? 'N': 'Y',
812 'CURRENT_USER' => $userId,
813 ));
814 if ($chats)
815 {
816 $chat = $chats[0];
817 }
818 else
819 {
820 return false;
821 }
822
823 if (isset($params['LOAD_READED']) && $params['LOAD_READED'])
824 {
825 $userOptions = ['SKIP_ONLINE' => 'Y'];
826 if ($chat['ENTITY_TYPE'] == 'LIVECHAT')
827 {
828 [$lineId] = explode('|', $chat['CHAT_ENTITY_ID']);
829 $userOptions['LIVECHAT'] = $lineId;
830 $userOptions['USER_CODE'] = 'livechat|' . $lineId . '|' . $id . '|' . $userId;
831 }
832
833 $relations = self::getRelation($id);
834
835 $chat['READED_LIST'] = [];
836 $chat['MANAGER_LIST'] = [];
837 foreach ($relations as $relation)
838 {
839 if (
840 $relation['USER_ID'] != $userId
841 //&& $relation['STATUS'] == self::STATUS_READ
842 && \Bitrix\Im\User::getInstance($relation['USER_ID'])->isActive()
843 )
844 {
845 $user = \Bitrix\Im\User::getInstance($relation['USER_ID'])->getArray($userOptions);
846 $chat['READED_LIST'][] = [
847 'USER_ID' => (int)$relation['USER_ID'],
848 'USER_NAME' => $user['NAME'],
849 'MESSAGE_ID' => (int)$relation['LAST_ID'],
850 'DATE' => $relation['LAST_READ'],
851 ];
852 }
853
854 if ($relation['MANAGER'] === 'Y')
855 {
856 $chat['MANAGER_LIST'][] = (int)$relation['USER_ID'];
857 }
858 }
859
860 // region v2
861
862 $chatInstance = \Bitrix\Im\V2\Chat::getInstance((int)$id);
863 $chat['LAST_MESSAGE_VIEWS'] = $chatInstance->getLastMessageViews();
864
865 // endregion
866 }
867
868 if ($params['JSON'] ?? null)
869 {
870 $chat = self::toJson($chat);
871 }
872
873 return $chat;
874 }
875
876 public static function getList($params = array())
877 {
878 $params = is_array($params)? $params: Array();
879
880 if (!isset($params['CURRENT_USER']) && is_object($GLOBALS['USER']))
881 {
882 $params['CURRENT_USER'] = $GLOBALS['USER']->GetID();
883 }
884
885 $params['CURRENT_USER'] = intval($params['CURRENT_USER']);
886
887 $params['SKIP_ACCESS_CHECK'] = $params['SKIP_ACCESS_CHECK'] === 'Y'? 'Y': 'N';
888
889 $userId = $params['CURRENT_USER'];
890 if ($userId <= 0)
891 {
892 return false;
893 }
894
895 $enableLimit = false;
896 if (isset($params['OFFSET']))
897 {
898 $filterLimit = intval($params['LIMIT']);
899 $filterLimit = $filterLimit <= 0? self::FILTER_LIMIT: $filterLimit;
900
901 $filterOffset = intval($params['OFFSET']);
902
903 $enableLimit = true;
904 }
905 else
906 {
907 $filterLimit = false;
908 $filterOffset = false;
909 }
910
911 $ormParams = self::getListParams($params);
912 if (!$ormParams)
913 {
914 return false;
915 }
916 if ($enableLimit)
917 {
918 $ormParams['offset'] = $filterOffset;
919 $ormParams['limit'] = $filterLimit;
920 }
921 if (isset($params['ORDER']))
922 {
923 $ormParams['order'] = $params['ORDER'];
924 }
925
926 $orm = \Bitrix\Im\Model\ChatTable::getList($ormParams);
927 $chatsRaw = $orm->fetchAll();
928 $chatsRaw = self::fillCounterData($chatsRaw);
929
930 $chats = array();
931 foreach ($chatsRaw as $chatRaw)
932 {
933 $chats[] = self::formatChatData($chatRaw);
934 }
935
936 if (isset($params['JSON']) && $params['JSON'])
937 {
938 $chats = self::toJson($chats);
939 }
940
941 return $chats;
942 }
943
944 public static function formatChatData($chat): array
945 {
946 $generalChatId = \CIMChat::GetGeneralChatId();
947 $avatar = \CIMChat::GetAvatarImage($chat['AVATAR'], 200, false);
948 $color = $chat['COLOR'] <> ''? Color::getColor($chat['COLOR']): Color::getColorByNumber($chat['ID']);
949
950 if ($generalChatId == $chat['ID'])
951 {
952 $chat["ENTITY_TYPE"] = 'GENERAL';
953 }
954
955 $chatType = \Bitrix\Im\Chat::getType($chat);
956
957 $muteList = Array();
958 if ($chat['RELATION_NOTIFY_BLOCK'] == 'Y')
959 {
960 $muteList[] = (int)$chat['RELATION_USER_ID'];
961 }
962
963 $counter = (int)$chat['RELATION_COUNTER'];
964 $startCounter = (int)$chat['RELATION_START_COUNTER'];
965 $userCounter = (int)$chat['USER_COUNT'];
966 $unreadId = (int)$chat['RELATION_UNREAD_ID'];
967 $lastMessageId = (int)$chat['LAST_MESSAGE_ID'];
968
969 $publicOption = '';
970 if ($chat['ALIAS_NAME'])
971 {
972 $publicOption = [
973 'code' => $chat['ALIAS_NAME'],
974 'link' => Alias::getPublicLink($chat['ENTITY_TYPE'], $chat['ALIAS_NAME'])
975 ];
976 }
977
978 $options = \CIMChat::GetChatOptions();
979 $restrictions = $options['DEFAULT'];
980
981 if ($chat["ENTITY_TYPE"] && in_array($chat["ENTITY_TYPE"], array_keys($options), true))
982 {
983 $restrictions = $options[$chat['ENTITY_TYPE']];
984 }
985
986 return Array(
987 'ID' => (int)$chat['ID'],
988 'PARENT_CHAT_ID' => (int)$chat['PARENT_ID'],
989 'PARENT_MESSAGE_ID' => (int)$chat['PARENT_MID'],
990 'NAME' => $chat['TITLE'],
991 'DESCRIPTION' => $chat['DESCRIPTION'],
992 'OWNER' => (int)$chat['AUTHOR_ID'],
993 'EXTRANET' => $chat['EXTRANET'] == 'Y',
994 'AVATAR' => $avatar,
995 'COLOR' => $color,
996 'TYPE' => $chatType,
997 'COUNTER' => $counter,
998 'USER_COUNTER' => $userCounter,
999 'MESSAGE_COUNT' => (int)$chat['MESSAGE_COUNT'] - $startCounter,
1000 'UNREAD_ID' => $unreadId,
1001 'RESTRICTIONS' => $restrictions,
1002 'LAST_MESSAGE_ID' => $lastMessageId,
1003 'LAST_ID' => (int)$chat['RELATION_LAST_ID'],
1004 'MARKED_ID' => (int)$chat['MARKED_ID'],
1005 'DISK_FOLDER_ID' => (int)$chat['DISK_FOLDER_ID'],
1006 'ENTITY_TYPE' => (string)$chat['ENTITY_TYPE'],
1007 'ENTITY_ID' => (string)$chat['ENTITY_ID'],
1008 'ENTITY_DATA_1' => (string)$chat['ENTITY_DATA_1'],
1009 'ENTITY_DATA_2' => (string)$chat['ENTITY_DATA_2'],
1010 'ENTITY_DATA_3' => (string)$chat['ENTITY_DATA_3'],
1011 'MUTE_LIST' => $muteList,
1012 'DATE_CREATE' => $chat['DATE_CREATE'],
1013 'MESSAGE_TYPE' => $chat["TYPE"],
1014 'PUBLIC' => $publicOption,
1015 'ROLE' => mb_strtolower(self::getRole($chat)),
1016 'ENTITY_LINK' => EntityLink::getInstance(\CIMChat::initChatByArray($chat))->toArray(),
1017 'TEXT_FIELD_ENABLED' => (new TextFieldEnabled((int)$chat['ID']))->get(),
1018 'BACKGROUND_ID' => (new Background((int)$chat['ID']))->get(),
1019 'PERMISSIONS' => [
1020 'MANAGE_USERS_ADD' => mb_strtolower((string)$chat['MANAGE_USERS_ADD']),
1021 'MANAGE_USERS_DELETE' => mb_strtolower((string)$chat['MANAGE_USERS_DELETE']),
1022 'MANAGE_UI' => mb_strtolower((string)$chat['MANAGE_UI']),
1023 'MANAGE_SETTINGS' => mb_strtolower((string)$chat['MANAGE_SETTINGS']),
1024 'MANAGE_MESSAGES' => mb_strtolower((string)$chat['CAN_POST']),
1025 'CAN_POST' => mb_strtolower((string)$chat['CAN_POST']),
1026 ],
1027 'IS_NEW' => \CIMChat::isNewChat($chat['TYPE'], $chat['DATE_CREATE']),
1028 );
1029 }
1030
1031 public static function getListParams($params)
1032 {
1033 if (!isset($params['CURRENT_USER']) && is_object($GLOBALS['USER']))
1034 {
1035 $params['CURRENT_USER'] = $GLOBALS['USER']->GetID();
1036 }
1037
1038 $params['CURRENT_USER'] = intval($params['CURRENT_USER']);
1039
1040 $userId = $params['CURRENT_USER'];
1041 if ($userId <= 0)
1042 {
1043 return null;
1044 }
1045
1046 $filter = [];
1047 $runtime = [];
1048
1049 $find = null;
1050 $field = '*INDEX.SEARCH_CONTENT';
1051
1052 if (isset($params['FILTER']['SEARCH']))
1053 {
1054 $find = (string)$params['FILTER']['SEARCH'];
1055 }
1056 elseif (isset($params['FILTER']['SEARCH_OL']) && Loader::includeModule('imopenlines'))
1057 {
1058 $find = (string)$params['FILTER']['SEARCH_OL'];
1059 $field = '*OL_INDEX.SEARCH_TITLE';
1060 }
1061
1062 if (isset($params['FILTER']['ID']))
1063 {
1064 $filter['=ID'] = $params['FILTER']['ID'];
1065 }
1066 else if (isset($find))
1067 {
1068 $helper = Application::getConnection()->getSqlHelper();
1069 if (Model\ChatIndexTable::getEntity()->fullTextIndexEnabled('SEARCH_CONTENT'))
1070 {
1071 $find = trim($find);
1073
1074 if (\Bitrix\Main\Search\Content::canUseFulltextSearch($find, \Bitrix\Main\Search\Content::TYPE_MIXED))
1075 {
1076 $filter[$field] = $find;
1077 }
1078 else
1079 {
1080 return null;
1081 }
1082 }
1083 else
1084 {
1085 if (mb_strlen($find) < 3)
1086 {
1087 return null;
1088 }
1089
1090 $filter['%=INDEX.SEARCH_TITLE'] = $helper->forSql($find).'%';
1091 }
1092 }
1093
1094 if ($params['SKIP_ACCESS_CHECK'] === 'Y')
1095 {
1096 // do nothing
1097 }
1098 else if (
1099 User::getInstance($params['CURRENT_USER'])->isExtranet()
1100 || User::getInstance($params['CURRENT_USER'])->isBot()
1101 )
1102 {
1103 $filter['=TYPE'] = [
1104 self::TYPE_CHANNEL,
1105 self::TYPE_GROUP,
1106 self::TYPE_THREAD,
1107 self::TYPE_PRIVATE
1108 ];
1109 if (User::getInstance($params['CURRENT_USER'])->isBot() && Loader::includeModule('imopenlines'))
1110 {
1111 $filter['=TYPE'][] = self::TYPE_OPEN_LINE;
1112 $filter[] = [
1113 'LOGIC' => 'OR',
1114 [
1115 '=RELATION.USER_ID' => $params['CURRENT_USER']
1116 ],
1117 [
1118 '=RECENT_OL.USER_ID' => $params['CURRENT_USER']
1119 ]
1120 ];
1121 }
1122 else
1123 {
1124 $filter['=RELATION.USER_ID'] = $params['CURRENT_USER'];
1125 }
1126 }
1127 else
1128 {
1129 $condition = [
1130 'LOGIC' => 'OR',
1131 [
1132 '=TYPE' => self::TYPE_OPEN,
1133 ],
1134 [
1135 '=TYPE' => self::TYPE_GROUP,
1136 '=RELATION.USER_ID' => $params['CURRENT_USER']
1137 ],
1138 [
1139 '=TYPE' => self::TYPE_THREAD,
1140 '=RELATION.USER_ID' => $params['CURRENT_USER']
1141 ],
1142 [
1143 '=TYPE' => self::TYPE_PRIVATE,
1144 '=RELATION.USER_ID' => $params['CURRENT_USER']
1145 ],
1146 [
1147 '=TYPE' => self::TYPE_OPEN_LINE,
1148 '=RELATION.USER_ID' => $params['CURRENT_USER']
1149 ],
1150 ];
1151 if (Loader::includeModule('imopenlines'))
1152 {
1153 $condition[] = [
1154 '=TYPE' => self::TYPE_OPEN_LINE,
1155 '=RECENT_OL.USER_ID' => $params['CURRENT_USER']
1156 ];
1157 }
1158 $filter[] = $condition;
1159 }
1160
1161 $runtime[] = new \Bitrix\Main\Entity\ReferenceField(
1162 'RELATION',
1163 'Bitrix\Im\Model\RelationTable',
1164 array(
1165 "=ref.CHAT_ID" => "this.ID",
1166 "=ref.USER_ID" => new \Bitrix\Main\DB\SqlExpression('?i', $params['CURRENT_USER']),
1167 ),
1168 array("join_type"=>"LEFT")
1169 );
1170 if (Loader::includeModule('imopenlines'))
1171 {
1172 $runtime[] = new \Bitrix\Main\Entity\ReferenceField(
1173 'RECENT_OL',
1174 \Bitrix\ImOpenLines\Model\RecentTable::class,
1175 array(
1176 "=ref.CHAT_ID" => "this.ID",
1177 "=ref.USER_ID" => new \Bitrix\Main\DB\SqlExpression('?i', $params['CURRENT_USER']),
1178 ),
1179 array("join_type"=>"LEFT")
1180 );
1181 }
1182
1183 return [
1184 'select' => [
1185 '*',
1186 'RELATION_USER_ID' => 'RELATION.USER_ID',
1187 'RELATION_MANAGER' => 'RELATION.MANAGER',
1188 'RELATION_NOTIFY_BLOCK' => 'RELATION.NOTIFY_BLOCK',
1189 //'RELATION_COUNTER' => 'RELATION.COUNTER',
1190 'RELATION_START_COUNTER' => 'RELATION.START_COUNTER',
1191 'RELATION_LAST_ID' => 'RELATION.LAST_ID',
1192 //'RELATION_STATUS' => 'RELATION.STATUS',
1193 //'RELATION_UNREAD_ID' => 'RELATION.UNREAD_ID',
1194 'ALIAS_NAME' => 'ALIAS.ALIAS',
1195 ],
1196 'filter' => $filter,
1197 'runtime' => $runtime
1198 ];
1199 }
1200
1201 public static function toJson($array)
1202 {
1203 return \Bitrix\Im\Common::toJson($array, false);
1204 }
1205
1206 public static function isUserInChat($chatId, $userId = 0) : bool
1207 {
1208 if ($userId === 0)
1209 {
1211 }
1212
1213 if (!$userId)
1214 {
1215 return false;
1216 }
1217
1218 $result = \Bitrix\Im\Model\RelationTable::getList(
1219 [
1220 'select' => ["ID"],
1221 'filter' => [
1222 '=USER_ID' => $userId,
1223 '=CHAT_ID' => $chatId
1224 ]
1225 ]
1226 )->fetch();
1227
1228 return (bool)$result['ID'];
1229 }
1230
1231 public static function isUserKickedFromChat($chatId, $userId = 0) : bool
1232 {
1233 if ($userId === 0)
1234 {
1236 }
1237
1238 if (!$userId)
1239 {
1240 return false;
1241 }
1242
1243 $result = BlockUserTable::getList(
1244 [
1245 'select' => ["ID"],
1246 'filter' => [
1247 '=USER_ID' => $userId,
1248 '=CHAT_ID' => $chatId
1249 ]
1250 ]
1251 )->fetch();
1252
1253 return is_array($result) && (bool)$result['ID'];
1254 }
1255
1256 public static function checkReplicaDeprecatedAgent(): string
1257 {
1258 return '';
1259 }
1260
1276 public static function isActionAllowed($dialogId, $action, $entityType = null): bool
1277 {
1278 if (!\Bitrix\Im\Common::isChatId($dialogId))
1279 {
1280 return true;
1281 }
1282
1283 $chatOptions = \CIMChat::GetChatOptions();
1284 $isAllowedByDefault = (bool)($chatOptions['DEFAULT'][$action] ?? true);
1285
1286 if ($entityType && $chatOptions[$entityType])
1287 {
1288 return (bool)($chatOptions[$entityType][$action] ?? $isAllowedByDefault);
1289 }
1290
1291 if ($entityType)
1292 {
1293 return $isAllowedByDefault;
1294 }
1295
1296 $chatId = \Bitrix\Im\Dialog::getChatId($dialogId);
1297 if (!$chatId)
1298 {
1299 return $isAllowedByDefault;
1300 }
1301
1302 $generalChatId = (int)\CIMChat::GetGeneralChatId();
1303 if ($chatId === $generalChatId)
1304 {
1305 return (bool)($chatOptions['GENERAL'][$action] ?? $isAllowedByDefault);
1306 }
1307
1308 $chat = \Bitrix\Im\Model\ChatTable::getList([
1309 'select' => [
1310 'ID',
1311 'ENTITY_TYPE',
1312 ],
1313 'filter' => [
1314 'ID' => $chatId,
1315 ]
1316 ])->fetch();
1317
1318 $entityType = ($chat && $chat['ENTITY_TYPE']) ? $chat['ENTITY_TYPE'] : null;
1319
1320 if ($entityType && $chatOptions[$entityType])
1321 {
1322 return (bool)($chatOptions[$entityType][$action] ?? $isAllowedByDefault);
1323 }
1324
1325 return $isAllowedByDefault;
1326 }
1327
1339 public static function getOwnerById($dialogId): ?int
1340 {
1341 $chatId = \Bitrix\Im\Dialog::getChatId($dialogId);
1342 if (!$chatId)
1343 {
1344 return null;
1345 }
1346
1347 $chat = \Bitrix\Im\Model\ChatTable::getList([
1348 'select' => [
1349 'ID',
1350 'AUTHOR_ID',
1351 ],
1352 'filter' => [
1353 'ID' => $chatId,
1354 ]
1355 ])->fetch();
1356
1357 return ($chat && is_numeric($chat['AUTHOR_ID'])) ? (int)$chat['AUTHOR_ID'] : null;
1358 }
1359
1360 public static function fillCounterData(array $chats): array
1361 {
1362 if (empty($chats))
1363 {
1364 return [];
1365 }
1366
1368 $readService = new ReadService($userId);
1369
1370 $chatIds = [];
1371
1372 foreach ($chats as $chat)
1373 {
1374 $chatIds[] = (int)$chat['ID'];
1375 }
1376
1377 $counters = $readService->getCounterService()->getForEachChat($chatIds);
1378 $unreadIds = $readService->getCounterService()->getIdFirstUnreadMessageForEachChats($chatIds);
1379 $markedIds = Recent::getMarkedIdByChatIds($userId, $chatIds);
1380
1381 foreach ($chats as $key => $chat)
1382 {
1383 $id = (int)$chat['ID'];
1384 $chats[$key]['RELATION_COUNTER'] = $counters[$id] ?? 0;
1385 $chats[$key]['RELATION_UNREAD_ID'] = $unreadIds[$id] ?? 0;
1386 $chats[$key]['MARKED_ID'] = $markedIds[$id] ?? 0;
1387 }
1388
1389 return $chats;
1390 }
1391
1392 public static function filterRelationsByAccess(int $chatId, array $relations): array
1393 {
1394 $userIds = array_keys($relations);
1395 $usersWithAccess = \Bitrix\Im\V2\Chat::getInstance($chatId)
1396 ->getRelationFacade()
1397 ?->filterUserIdsByAccess($userIds)
1398 ?? []
1399 ;
1400
1401 return array_filter(
1402 $relations,
1403 static fn ($userId) => in_array($userId, $usersWithAccess, true),
1404 ARRAY_FILTER_USE_KEY
1405 );
1406 }
1407
1408 private static function getRole(array $chat): string
1409 {
1410 if (!isset($chat['RELATION_USER_ID']))
1411 {
1412 return \Bitrix\Im\V2\Chat::ROLE_GUEST;
1413 }
1414 if ((int)$chat['RELATION_USER_ID'] === (int)$chat['AUTHOR_ID'])
1415 {
1416 return \Bitrix\Im\V2\Chat::ROLE_OWNER;
1417 }
1418 if ($chat['RELATION_MANAGER'] === 'Y')
1419 {
1420 return \Bitrix\Im\V2\Chat::ROLE_MANAGER;
1421 }
1422
1423 return \Bitrix\Im\V2\Chat::ROLE_MEMBER;
1424 }
1425}
$connection
Определения actionsdefinitions.php:38
$type
Определения options.php:106
if(! $messageFields||!isset($messageFields['message_id'])||!isset($messageFields['status'])||!CModule::IncludeModule("messageservice")) $messageId
Определения callback_ismscenter.php:26
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getPublicLink($type, $alias)
Определения alias.php:226
static isUserInChat($chatId, $userId=0)
Определения chat.php:1206
static fillCounterData(array $chats)
Определения chat.php:1360
const STATUS_READ
Определения chat.php:34
const TYPE_CHANNEL
Определения chat.php:29
const TYPE_THREAD
Определения chat.php:27
static isGeneralChannel(?int $chatId, string $typeLiteral, string $entityType)
Определения chat.php:83
static getTypes()
Определения chat.php:40
static hasAccess($chatId)
Определения chat.php:394
static getMessageCount($chatId, $userId=null)
Определения chat.php:363
const TYPE_PRIVATE
Определения chat.php:25
const FILTER_LIMIT
Определения chat.php:38
const STATUS_UNREAD
Определения chat.php:32
static getUsers($chatId, $options=[])
Определения chat.php:736
static getMessages($chatId, $userId=null, $options=Array())
Определения chat.php:411
static getById($id, $params=array())
Определения chat.php:800
static getListParams($params)
Определения chat.php:1031
static getList($params=array())
Определения chat.php:876
static formatChatData($chat)
Определения chat.php:944
static isActionAllowed($dialogId, $action, $entityType=null)
Определения chat.php:1276
static getType($chatData, bool $camelCase=true)
Определения chat.php:45
static filterRelationsByAccess(int $chatId, array $relations)
Определения chat.php:1392
const TYPE_OPEN
Определения chat.php:26
static isGeneralChat(?int $chatId, string $typeLiteral, string $entityType)
Определения chat.php:73
const TYPE_OPEN_LINE
Определения chat.php:30
const TYPE_SYSTEM
Определения chat.php:24
static isUserKickedFromChat($chatId, $userId=0)
Определения chat.php:1231
const TYPE_GROUP
Определения chat.php:28
const LIMIT_SEND_EVENT
Определения chat.php:36
const STATUS_NOTIFY
Определения chat.php:33
static toJson($array)
Определения chat.php:1201
static getOwnerById($dialogId)
Определения chat.php:1339
static getRelation($chatId, $params=[])
Определения chat.php:93
static mute($chatId, $action, $userId=null)
Определения chat.php:278
static checkReplicaDeprecatedAgent()
Определения chat.php:1256
static getColorByNumber($number)
Определения color.php:144
static getColor($code)
Определения color.php:121
static toJson($array, $camelCase=true)
Определения common.php:89
static isChatId($id)
Определения common.php:58
static getPullExtra()
Определения common.php:127
static getUserId($userId=null)
Определения common.php:73
static getPublicDomain()
Определения common.php:8
static getChatId($dialogId, $userId=null)
Определения dialog.php:93
static getMap()
Определения relation.php:71
static filterExternalUserTypes(array $skipTypes=[])
Определения user.php:31
static getMarkedIdByChatIds(int $userId, array $chatIds)
Определения recent.php:1878
static parse($text, $params=Array())
Определения text.php:28
static parseLegacyFormat($text, $params=Array())
Определения text.php:94
static getReplaceMap($text)
Определения text.php:177
static getInstance($userId=null)
Определения user.php:45
static getGeneralChannelId()
Определения GeneralChannel.php:56
static getGeneralChatId()
Определения GeneralChat.php:123
static getInstance(?int $id)
Определения BotData.php:34
static getInstance()
Определения application.php:98
static clearCache($moduleId)
Определения option.php:464
static getInstance()
Определения servicelocator.php:33
static getInstance()
Определения eventmanager.php:31
static prepareStringToken($token)
Определения content.php:18
static add($recipient, array $parameters, $channelType=\CPullChannel::TYPE_PRIVATE)
Определения event.php:22
static GetFiles($chatId, $fileId=false, $checkPermission=true)
Определения im_disk.php:1601
$options
Определения commerceml2.php:49
$orderId
Определения payment.php:5
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$query
Определения get_search.php:11
$filter
Определения iblock_catalog_list.php:54
$selectFields
Определения iblock_catalog_list.php:160
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения tools.php:5214
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
$map
Определения config.php:5
Определения alias.php:2
Определения arrayresult.php:2
Определения ufield.php:9
Определения content.php:3
Определения collection.php:2
$user
Определения mysql_to_pgsql.php:33
$files
Определения mysql_to_pgsql.php:30
$GLOBALS['____1690880296']
Определения license.php:1
$message
Определения payment.php:8
$counter
Определения options.php:5
$event
Определения prolog_after.php:141
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$messages
Определения template.php:8
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$counters
Определения options.php:100
$action
Определения file_dialog.php:21
$url
Определения iframe.php:7