3namespace Bitrix\Calendar\Integration\Im;
5use Bitrix\Calendar\Core\EventCategory\EventCategory;
6use Bitrix\Calendar\OpenEvents\Provider;
8use Bitrix\Im\Model\ChatTable;
10use Bitrix\Im\V2\Chat\ChatFactory;
11use Bitrix\Im\V2\Chat\CommentChat;
12use Bitrix\Im\V2\Message;
13use Bitrix\Main\Loader;
14use Bitrix\Main\NotSupportedException;
30 if (!Loader::includeModule(
'im'))
41 $channelIdsResult = ChatTable::query()
44 ->whereIn(
'TYPE', [CHAT::IM_TYPE_CHANNEL, CHAT::IM_TYPE_OPEN_CHANNEL])
45 ->whereNull(
'ENTITY_TYPE')
54 $channelIds = array_map(
'intval', array_column($channelIdsResult,
'ID'));
67 'title' => $channel->getDisplayedTitle(),
68 'closed' => $channel->getType() === CHAT::IM_TYPE_CHANNEL,
69 'avatar' => $channel->getAvatar(),
70 'color' => $channel->getColor(),
81 $channelType = Chat::IM_TYPE_CHANNEL;
86 $channelType = Chat::IM_TYPE_OPEN_CHANNEL;
90 $departments = array_map(
91 static fn (
int|
string $departmentId) => [
'department', $departmentId],
96 'TYPE' => $channelType,
100 'MEMBER_ENTITIES' => $departments,
101 'TITLE' => (
new Provider\CategoryProvider())->prepareCategoryName($eventCategory->
getName()),
102 'ENTITY_TYPE' => self::OPEN_EVENT_CATEGORY_IM_ENTITY_TYPE,
103 'SEND_GREETING_MESSAGES' =>
'Y',
106 $addChannelResult = ChatFactory::getInstance()->addChat(
$params);
108 $chat = $addChannelResult->getResult()[
'CHAT'];
116 if ($addChannelResult->isSuccess())
118 return $chat->getChatId();
121 throw new \RuntimeException(
'channel not created');
126 $channel = ChatFactory::getInstance()->getChatById($eventCategory->
getChannelId());
127 if (!in_array($channel->getType(), [Chat::IM_TYPE_CHANNEL, Chat::IM_TYPE_OPEN_CHANNEL],
true))
132 $categoryProvider =
new Provider\CategoryProvider();
134 $channel->setTitle($categoryProvider->prepareCategoryName($eventCategory->
getName()));
135 $channel->setDescription($categoryProvider->prepareCategoryDescription($eventCategory->
getDescription()));
145 $channel = ChatFactory::getInstance()->getChatById(
$channelId);
147 if ($isMuted === $newMuteState)
152 $channelType = $channel->getType();
153 if (!in_array($channelType, [Chat::IM_TYPE_OPEN_CHANNEL, Chat::IM_TYPE_CHANNEL],
true))
155 throw new \RuntimeException(
'unknown channel type');
158 $CIMChat = new \CIMChat(
$userId);
159 $CIMChat->muteNotify(
$channelId, $newMuteState);
164 $channel = ChatFactory::getInstance()->getChatById(
$channelId);
167 'id' => $channel->getId(),
168 'title' => $channel->getTitle(),
169 'avatar' => $channel->getAvatar(),
170 'color' => Color::getColor($channel->getColor()),
176 return ChatFactory::getInstance()
178 ?->getRelations([
'FILTER' => [
'USER_ID' =>
$userId]])
186 $threadMessage =
new Message($threadId);
188 if ($threadMessage->getMessageId() ===
null)
193 if (!$threadMessage->hasAccess())
199 if ($commentChatResult->getErrors())
205 $commentChat = $commentChatResult->getResult();
207 return $commentChat->getMessageCount() > 0 ? $commentChat->getMessageCount() - 1 : 0;
212 $channel = ChatFactory::getInstance()->getChatById(
$channelId);
215 $CIMChat = new \CIMChat(0);
223 $channel = ChatFactory::getInstance()->getChatById(
$channelId);
225 return $channel->hasAccess(
$userId);
230 return ChatFactory::getInstance()
239 return ChatFactory::getInstance()
241 ->getType() === Chat::IM_TYPE_CHANNEL
247 $channel = ChatFactory::getInstance()->getChatById(
$channelId);
249 return $channel->getAuthorId() ===
$userId;
254 $chat = ChatFactory::getInstance()->getChatById(
$channelId);
256 if ($chat->getEntityType())
258 throw new \Exception(
'can not connect channel with not empty ENTITY_TYPE to category');
261 $chat->setEntityType(self::OPEN_EVENT_CATEGORY_IM_ENTITY_TYPE);
if(empty( $fields)) foreach($fields as $field) $channelId
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
createChannel(EventCategory $eventCategory, array $userIds, array $departmentIds=[])
hasAccess(int $userId, int $channelId)
connectChannelToCategory(int $channelId)
isChannelMuted(int $userId, int $channelId)
const OPEN_EVENT_CATEGORY_IM_ENTITY_TYPE
isChannelPrivate(int $channelId)
includeUserToChannel(int $userId, int $channelId)
isManagerOfChannel(int $userId, int $channelId)
getAvailableChannelsList(int $userId)
getChannelUsers(int $channelId)
setMuteChannel(int $userId, int $channelId, bool $newMuteState)
getChannelInfo(int $channelId)
updateChannel(EventCategory $eventCategory)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
getThreadCommentsCount(int $threadId)
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']