16 private $bHideLink =
false;
21 $this->user_id = intval($user_id);
22 if ($this->user_id == 0)
23 $this->user_id = intval(
$USER->GetID());
25 $this->bHideLink =
true;
42 if (in_array(
$key, $locFields,
true))
44 if (isset($field) && is_callable($field))
46 $localizeText = self::getTextMessageByLang((
int)
$arFields[
'TO_USER_ID'], $field);
56 if (isset($button[
'TITLE']) && is_callable($button[
'TITLE']))
58 $localizeText = self::getTextMessageByLang((
int)
$arFields[
'TO_USER_ID'], $button[
'TITLE']);
71 if (!($locFunction instanceof \Closure))
76 if (!Loader::includeModule(
'bitrix24'))
78 return $locFunction(Loc::getCurrentLang(),
$userId);
81 $user = IM\V2\Entity\User\User::getInstance(
$userId);
82 $langId = $user->getLanguageId();
84 return $locFunction($langId,
$userId);
95 $bTimeZone = isset(
$arParams[
'USE_TIME_ZONE']) &&
$arParams[
'USE_TIME_ZONE'] ==
'N'?
false:
true;
98 SELECT COUNT(M.ID) as CNT, M.CHAT_ID
100 INNER JOIN b_im_message M ON M.CHAT_ID = R.CHAT_ID
101 WHERE R.USER_ID = ".$this->user_id.
" AND R.MESSAGE_TYPE = '".
IM_MESSAGE_SYSTEM.
"'
105 $res_cnt =
$DB->Query($sqlStr);
106 $res_cnt = $res_cnt->Fetch();
107 $cnt = $res_cnt[
"CNT"] ?? 0;
108 $chatId = $res_cnt[
"CHAT_ID"] ?? -1;
114 CTimeZone::Disable();
122 ".$DB->DatetimeToTimestampFunction(
'M.DATE_CREATE').
" as DATE_CREATE,
131 $this->user_id as TO_USER_ID,
132 M.AUTHOR_ID as FROM_USER_ID
134 WHERE M.CHAT_ID = ".$chatId.
" #LIMIT#
135 ORDER BY M.DATE_CREATE DESC, M.ID DESC
142 if (
$DB->type ==
"MSSQL")
144 $sqlLimit =
" AND M.DATE_CREATE > dateadd(day, -30, getdate())";
148 $sqlLimit =
" AND M.DATE_CREATE > SYSDATE-30";
154 $sqlLimit =
" AND M.DATE_CREATE > ". $helper->addDaysToDateTime(-30);
157 $strSql =
$DB->TopSql($strSql, 100);
158 $dbRes =
$DB->Query(str_replace(
"#LIMIT#", $sqlLimit, $strSql));
163 $dbRes->NavQuery(str_replace(
"#LIMIT#",
"", $strSql), $cnt, Array(
'iNumPage' => $iNumPage,
'nPageSize' => 20));
166 $arGetUsers = Array();
167 $arNotifyId = Array();
171 if ($this->bHideLink)
172 $arRes[
'HIDE_LINK'] =
'Y';
176 $arGetUsers[] =
$arRes[
'FROM_USER_ID'];
179 if (empty($arNotify))
182 $counters = self::GetCounters($arChatId);
184 $params = CIMMessageParam::Get(array_keys($arNotifyId));
185 foreach (
$params as $notifyId => $param)
187 $arNotify[$notifyId][
'PARAMS'] = $param;
190 $arUsers = CIMContactList::GetUserData(Array(
'ID' => $arGetUsers,
'DEPARTMENT' =>
'N',
'USE_CACHE' =>
'Y',
'CACHE_TTL' => 86400));
191 $arGetUsers = $arUsers[
'users'];
193 $arNotify = $this->fillReadStatuses($arNotify);
194 foreach ($arNotify as
$key => $value)
196 $value[
'COUNTER'] =
$counters[$value[
'CHAT_ID']];
197 $value[
'FROM_USER_DATA'] = $arGetUsers;
198 $arNotify[
$key] = self::GetFormatNotify($value);
209 $bSpeedCheck = isset(
$arParams[
'SPEED_CHECK']) &&
$arParams[
'SPEED_CHECK'] ==
'N'?
false:
true;
210 $bTimeZone = isset(
$arParams[
'USE_TIME_ZONE']) &&
$arParams[
'USE_TIME_ZONE'] ==
'N'?
false:
true;
211 $bGetOnlyFlash = isset(
$arParams[
'GET_ONLY_FLASH']) &&
$arParams[
'GET_ONLY_FLASH'] ==
'Y'?
true:
false;
213 $arNotify[
'result'] =
false;
214 $arNotify[
'notify'] = Array();
215 $arNotify[
'unreadNotify'] = Array();
216 $arNotify[
'loadNotify'] =
false;
217 $arNotify[
'countNotify'] = 0;
218 $arNotify[
'maxNotify'] = 0;
220 $bLoadNotify = $bSpeedCheck? !CIMMessenger::SpeedFileExists($this->user_id,
IM_SPEED_NOTIFY):
true;
242 $result = IM\Model\MessageUnreadTable::query()
243 ->setSelect([
'MESSAGE_ID'])
244 ->where(
'USER_ID', $this->user_id)
250 $messageIds = array_column(
$result,
'MESSAGE_ID');
252 if (empty($messageIds))
257 $implodeMessageIds = implode(
',', $messageIds);
260 CTimeZone::Disable();
267 ".$DB->DatetimeToTimestampFunction(
'M.DATE_CREATE').
" as DATE_CREATE,
276 $this->user_id as TO_USER_ID,
277 M.AUTHOR_ID as FROM_USER_ID
279 WHERE M.ID IN ({$implodeMessageIds})
284 $strSql =
$DB->TopSql($strSql, 100);
288 $arGetUsers = Array();
289 $arNotifyId = Array();
293 if ($this->bHideLink)
294 $arRes[
'HIDE_LINK'] =
'Y';
304 if ($arNotify[
'maxNotify'] <
$arRes[
'ID'])
305 $arNotify[
'maxNotify'] =
$arRes[
'ID'];
307 $arGetUsers[] =
$arRes[
'FROM_USER_ID'];
311 $params = CIMMessageParam::Get(array_keys($arNotifyId));
312 foreach (
$params as $notifyId => $param)
314 $arNotify[
'notify'][$notifyId][
'PARAMS'] = $param;
321 CIMMessenger::SpeedFileCreate($this->user_id,
array(
'counter' => $arNotify[
'countNotify'],
'maxId' => $arNotify[
'maxNotify']),
IM_SPEED_NOTIFY);
323 $arUsers = CIMContactList::GetUserData(Array(
'ID' => $arGetUsers,
'DEPARTMENT' =>
'N',
'USE_CACHE' =>
'Y',
'CACHE_TTL' => 86400));
324 $arGetUsers = $arUsers[
'users'] ??
null;
326 $counters = self::GetCounters($arChatId);
328 $arNotify[
'notify'] = $this->fillReadStatuses($arNotify[
'notify']);
329 foreach ($arNotify[
'notify'] as $id => $value)
331 $value[
'FROM_USER_DATA'] = $arGetUsers;
332 $value[
'COUNTER'] =
$counters[$value[
'CHAT_ID']];
336 $value[
'DATE_CREATE'] = $dateTime->toUserTime()->getTimestamp();
338 $arNotify[
'notify'][$id] = self::GetFormatNotify($value);
341 $arNotify[
'result'] =
true;
346 $arNotify[
'countNotify'] = $cache? $cache[
'counter']: 0;
347 $arNotify[
'maxNotify'] = $cache? $cache[
'maxId']: 0;
348 if ($arNotify[
'countNotify'] > 0)
349 $arNotify[
'loadNotify'] =
true;
359 $mailService =
new IM\V2\Mail();
360 $unsendIds = $mailService->getNotificationIdsToSend(5000);
362 if (empty($unsendIds))
367 $implodeUnsendIds = implode(
',', $unsendIds);
369 CTimeZone::Disable();
376 ".$DB->DatetimeToTimestampFunction(
'M.DATE_CREATE').
" as DATE_CREATE,
385 M.AUTHOR_ID as FROM_USER_ID,
386 U2.LOGIN as FROM_USER_LOGIN,
387 U2.NAME as FROM_USER_NAME,
388 U2.LAST_NAME as FROM_USER_LAST_NAME,
389 U2.SECOND_NAME as FROM_USER_SECOND_NAME,
390 U2.EXTERNAL_AUTH_ID as FROM_EXTERNAL_AUTH_ID,
391 C.AUTHOR_ID as TO_USER_ID,
392 U1.LOGIN as TO_USER_LOGIN,
393 U1.NAME as TO_USER_NAME,
394 U1.LAST_NAME as TO_USER_LAST_NAME,
395 U1.SECOND_NAME as TO_USER_SECOND_NAME,
396 U1.EMAIL as TO_USER_EMAIL,
397 U1.ACTIVE as TO_USER_ACTIVE,
398 U1.LID as TO_USER_LID,
399 U1.TIME_ZONE as TIME_ZONE,
400 U1.EXTERNAL_AUTH_ID as TO_EXTERNAL_AUTH_ID
402 LEFT JOIN b_user U2 ON U2.ID = M.AUTHOR_ID
403 LEFT JOIN b_im_chat C ON M.CHAT_ID = C.ID
404 LEFT JOIN b_user U1 ON U1.ID = C.AUTHOR_ID
405 WHERE M.ID IN ({$implodeUnsendIds})
427 $strSql =
"SELECT M.* FROM b_im_relation R, b_im_message M WHERE M.ID = ".$ID.
" AND R.USER_ID = ".$this->user_id.
" AND R.MESSAGE_TYPE = '".
IM_MESSAGE_SYSTEM.
"' AND R.CHAT_ID = M.CHAT_ID";
440 'LINK' => (isset(
$arFields[
'HIDE_LINK']) &&
$arFields[
'HIDE_LINK'] ===
'Y') ?
'N' :
'Y',
441 'LINK_TARGET_SELF' =>
'Y',
449 $arUsers = CIMContactList::GetUserData(Array(
'ID' =>
$arFields[
'FROM_USER_ID'],
'DEPARTMENT' =>
'N',
'USE_CACHE' =>
'Y',
'CACHE_TTL' => 86400));
450 $arFields[
"FROM_USER_DATA"] = $arUsers[
'users'] ??
null;
455 $user = User::getInstance((
int)
$arFields[
'FROM_USER_ID'])->getArray([
461 $user[
'idle'] =
$arFields[
'FROM_USER_DATA'][
$arFields[
'FROM_USER_ID']][
'idle'] ??
false;
462 $user[
'last_activity_date'] =
$arFields[
'FROM_USER_DATA'][
$arFields[
'FROM_USER_ID']][
'last_activity_date'] ??
false;
463 $user[
'mobile_last_date'] =
$arFields[
'FROM_USER_DATA'][
$arFields[
'FROM_USER_ID']][
'mobile_last_date'] ??
false;
472 'silent' => (
$arFields[
'NOTIFY_SILENT'] ??
null) ?
'Y' :
'N',
473 'onlyFlash' => (bool)(
$arFields[
'NOTIFY_ONLY_FLASH'] ??
false),
474 'link' => (string)(
$arFields[
'NOTIFY_LINK'] ??
''),
475 'text' => $messageText,
477 'originalTag' =>
$arFields[
'NOTIFY_TAG'],
478 'original_tag' =>
$arFields[
'NOTIFY_TAG'],
479 'read' =>
$arFields[
'NOTIFY_READ'] ??
null,
486 $arNotify[
'userId'] =
$arFields[
"FROM_USER_ID"];
487 $arNotify[
'userName'] =
$arFields[
"FROM_USER_DATA"][
$arFields[
"FROM_USER_ID"]][
'name'] ??
null;
488 $arNotify[
'userColor'] =
$arFields[
"FROM_USER_DATA"][
$arFields[
"FROM_USER_ID"]][
'color'] ??
null;
489 $arNotify[
'userAvatar'] =
$arFields[
"FROM_USER_DATA"][
$arFields[
"FROM_USER_ID"]][
'avatar'] ??
null;
490 $arNotify[
'userLink'] =
$arFields[
"FROM_USER_DATA"][
$arFields[
"FROM_USER_ID"]][
'profile'] ??
null;
494 $arNotify[
'buttons'] = unserialize(
$arFields[
'NOTIFY_BUTTONS'], [
'allowed_classes' =>
false]);
504 public function MarkNotifyRead($id = 0, $setThisAndHigher =
false, $appId =
'Bitrix24')
607 $findResult = NotifyChat::find([
'TO_USER_ID' => $this->user_id]);
609 if (!$findResult->isSuccess())
614 $chatId = (int)$findResult->getResult()[
'ID'];
616 $readService =
new IM\V2\Message\ReadService($this->user_id);
617 $counterService = $readService->getCounterService();
621 $readService->readAllInChat($chatId);
622 if (CModule::IncludeModule(
"pull"))
626 'command' =>
'notifyReadAll',
630 'extra' => \
Bitrix\Im\Common::getPullExtra()
641 $operator = $setThisAndHigher ?
'>=' :
'=';
642 $query = IM\Model\MessageUnreadTable::query()
643 ->setSelect([
'MESSAGE_ID'])
644 ->where(
'USER_ID', $this->user_id)
645 ->where(
'CHAT_ID', $chatId)
646 ->where(
'MESSAGE_ID', $operator, $id)
650 $messageCollection =
new IM\V2\MessageCollection();
652 while ($row =
$query->fetch())
656 $message->setMessageId((
int)$row[
'MESSAGE_ID'])->setChatId($chatId)->setAuthorId(0);
665 $counter = $readService->readNotifications($messageCollection, [$chatId => $this->user_id])->getResult()[
'COUNTERS'][$chatId];
667 if (CModule::IncludeModule(
"pull"))
671 'command' =>
'notifyRead',
677 'extra' => \
Bitrix\Im\Common::getPullExtra()
692 if (empty($subTagList))
697 if (!is_array($subTagList))
699 $subTagList =
array($subTagList);
702 $result = IM\Model\MessageTable::query()
703 ->setSelect([
'ID',
'CHAT_ID',
'USER_ID' =>
'RELATION.USER_ID'])
704 ->whereIn(
'NOTIFY_SUB_TAG', $subTagList)
719 $messagesByUser =
array();
721 $messageCollection =
new IM\V2\MessageCollection();
723 while ($row =
$result->fetch())
726 $users[$row[
'CHAT_ID']] = $row[
'USER_ID'];
727 $chats[$row[
'CHAT_ID']] = $row[
'CHAT_ID'];
728 $messagesByUser[$row[
'CHAT_ID']][] = $row[
'ID'];
730 $message->setMessageId((
int)$row[
'ID'])->setChatId((
int)$row[
'CHAT_ID']);
739 $readService =
new IM\V2\Message\ReadService();
740 $counters = $readService->readNotifications($messageCollection, $users)->getResult()[
'COUNTERS'];
742 $isLoadPull = Loader::includeModule(
"pull");
743 foreach ($messagesByUser as $chatId => $messagesList)
752 'command' =>
'notifyRead',
755 'list' => array_values($messagesList),
758 'extra' => \
Bitrix\Im\Common::getPullExtra()
823 $startNotify = \Bitrix\Im\Model\MessageTable::getList(Array(
824 'select' => Array(
'ID',
'CHAT_ID',
'NOTIFY_TAG'),
828 '=RELATION.USER_ID' => $this->user_id,
836 $notifyTag = $startNotify[
'NOTIFY_TAG'] ??
null;
838 $chatId = intval($startNotify[
'CHAT_ID']);
840 $operator = $setThisAndHigher ?
'>=' :
'=';
841 $notifyByIdResult = IM\Model\MessageTable::query()
843 ->where(
'CHAT_ID', $chatId)
844 ->where(
'ID', $operator, $id)
849 $messages =
new IM\V2\MessageCollection();
851 while ($notifyById = $notifyByIdResult->fetch())
854 $message->setMessageId((
int)$notifyById[
'ID'])->setChatId($chatId)->setAuthorId(0);
858 if ($notifyTag !==
null && $notifyTag !==
'')
860 $notifyByTagResult = IM\Model\MessageTable::query()
862 ->where(
'CHAT_ID', $chatId)
863 ->where(
'NOTIFY_TAG', $notifyTag)
868 while ($notifyByTag = $notifyByTagResult->fetch())
871 $message->setMessageId((
int)$notifyByTag[
'ID'])->setChatId($chatId)->setAuthorId(0);
876 $readService =
new IM\V2\Message\ReadService($this->user_id);
878 $relation =
new IM\V2\Relation();
879 $relation->setChatId($chatId)->setUserId($this->user_id)->setMessageType(
'S')->setNotifyBlock(
false);
881 $counter = $readService->unreadNotifications(
$messages, $relation)->getResult()[
'COUNTER'];
934 if (CModule::IncludeModule(
"pull"))
938 'command' =>
'notifyUnread',
944 'extra' => \
Bitrix\Im\Common::getPullExtra()
1020 FROM b_im_relation R, b_im_message M
1021 WHERE M.ID = ".$id.
" AND R.USER_ID = ".$this->user_id.
" AND R.MESSAGE_TYPE = '".
IM_MESSAGE_SYSTEM.
"' AND R.CHAT_ID = M.CHAT_ID AND M.NOTIFY_TYPE = ".
IM_NOTIFY_CONFIRM;
1026 $arRes[
'RELATION_USER_ID'] = $this->user_id;
1027 $arRes[
'NOTIFY_BUTTONS'] = unserialize(
$arRes[
'NOTIFY_BUTTONS'], [
'allowed_classes' =>
false]);
1029 $resultMessages = Array();
1030 if (
$arRes[
'NOTIFY_TAG'] <>
'')
1034 'a' =>
array(
'href',
'style',
'target'),
1037 'span' =>
array(
'style'),
1040 foreach(
GetModuleEvents(
"im",
"OnBeforeConfirmNotify",
true) as $arEvent)
1043 if($resultEvent===
false || is_array($resultEvent) && $resultEvent[
'result'] ===
false)
1045 $resultMessages = Array();
1046 if (is_array($resultEvent) && $resultEvent[
'text'])
1048 $resultMessages[] = $CBXSanitizer->SanitizeHtml($resultEvent[
'text']);
1052 else if (is_array($resultEvent) && $resultEvent[
'text'] || is_string($resultEvent) && $resultEvent <>
'')
1054 $resultMessages[] = $CBXSanitizer->SanitizeHtml(is_string($resultEvent)? $resultEvent: $resultEvent[
'text']);
1058 if (empty($resultMessages))
1060 foreach (
$arRes[
'NOTIFY_BUTTONS'] as $button)
1062 if ($button[
'VALUE'] == $value)
1064 $resultMessages[] =
GetMessage(
'IM_CONFIRM_CHOICE', Array(
'#BUTTON#' => $button[
'TITLE']));
1072 if (
$arRes[
'NOTIFY_TAG'] <>
'')
1074 foreach(
GetModuleEvents(
"im",
"OnAfterConfirmNotify",
true) as $arEvent)
1078 if (CModule::IncludeModule(
"pull"))
1081 'module_id' =>
'im',
1082 'command' =>
'notifyConfirm',
1085 'chatId' => intval(
$arRes[
'CHAT_ID']),
1086 'confirmMessages' => $resultMessages,
1087 'counter' => self::GetRealCounter(
$arRes[
'CHAT_ID']),
1089 'extra' => \
Bitrix\Im\Common::getPullExtra()
1095 return $resultMessages;
1104 if ($id <= 0 ||
$text ==
'')
1109 FROM b_im_relation R, b_im_message M
1110 WHERE M.ID = ".$id.
" AND R.USER_ID = ".$this->user_id.
" AND R.MESSAGE_TYPE = '".
IM_MESSAGE_SYSTEM.
"' AND R.CHAT_ID = M.CHAT_ID
1117 if ($mention->isExists())
1119 $text =
'[USER='.$mention->getId().
']'.$mention->getFullName(
false).
'[/USER] '.
$text;
1124 'a' =>
array(
'href',
'style',
'target'),
1127 'span' =>
array(
'style'),
1133 if($resultEvent===
false || is_array($resultEvent) && $resultEvent[
'result'] ===
false)
1135 $resultMessages = Array();
1136 if (is_array($resultEvent) && $resultEvent[
'text'])
1138 $resultMessages[] = $CBXSanitizer->SanitizeHtml($resultEvent[
'text']);
1142 else if (is_array($resultEvent) && $resultEvent[
'text'] || is_string($resultEvent) && $resultEvent <>
'')
1144 $resultMessages[] = $CBXSanitizer->SanitizeHtml(is_string($resultEvent)? $resultEvent: $resultEvent[
'text']);
1148 if (empty($resultMessages))
1150 $resultMessages[] =
GetMessage(
'IM_ANSWER_DONE');
1153 return $resultMessages;
1159 $notification = self::getNotificationById($id);
1165 $message = (
new IM\V2\Message())->setMessageId($id)->setChatId((
int)$notification[
'CHAT_ID']);
1166 self::deleteInternal(
$message, (
int)$notification[
'RELATION_USER_ID']);
1167 $counter = self::GetRealCounter($notification[
'CHAT_ID']);
1168 $chatId = (int)$notification[
'CHAT_ID'];
1170 self::updateStateAfterDelete($chatId, $notification[
'RELATION_USER_ID']);
1172 foreach(
GetModuleEvents(
"im",
"OnAfterDeleteNotify",
true) as $arEvent)
1177 if (CModule::IncludeModule(
"pull"))
1181 $notification[
'RELATION_USER_ID'],
1183 'module_id' =>
'im',
1184 'command' =>
'notifyDelete',
1186 'id' => [$id => $notification[
'NOTIFY_TYPE']],
1189 'extra' => \
Bitrix\Im\Common::getPullExtra()
1205 $relationUserIds = [];
1206 $resultDataForPushAndPull = [];
1207 $messageCollection =
new IM\V2\MessageCollection();
1209 $notifyList = self::getNotificationList($ids);
1210 foreach ($notifyList as $notify)
1212 $notifyId = (int)$notify[
'ID'];
1215 ->setMessageId($notifyId)
1216 ->setChatId((
int)$notify[
'CHAT_ID'])
1220 $chatIds[(int)$notify[
'CHAT_ID']] = (
int)$notify[
'CHAT_ID'];
1221 $relationUserIds[(int)$notify[
'CHAT_ID']] = (
int)$notify[
'RELATION_USER_ID'];
1222 $resultDataForPushAndPull[$notifyId] = $notify[
'NOTIFY_TYPE'];
1225 self::deleteListInternal($messageCollection, $relationUserIds);
1227 foreach ($notifyList as $notify)
1229 $notifyId = (int)$notify[
'ID'];
1230 foreach(
GetModuleEvents(
"im",
"OnAfterDeleteNotify",
true) as $arEvent)
1236 if (empty($resultDataForPushAndPull))
1241 $counters = self::GetCounters(array_values($chatIds));
1243 foreach ($chatIds as $chatId)
1245 $userId = $relationUserIds[$chatId];
1248 self::updateStateAfterDelete($chatId,
$userId);
1250 if (CModule::IncludeModule(
"pull"))
1252 if (isset(
$params[
'NOTIFY_TAG']))
1254 CPushManager::DeleteFromQueueByTag(
$userId,
$params[
'NOTIFY_TAG']);
1258 CPushManager::DeleteFromQueueBySubTag(
$userId,
$params[
'NOTIFY_SUB_TAG']);
1264 'module_id' =>
'im',
1265 'command' =>
'notifyDelete',
1267 'id' => $resultDataForPushAndPull,
1270 'extra' => \
Bitrix\Im\Common::getPullExtra()
1283 private static function updateStateAfterDelete(
int $chatId,
int $userId): void
1288 $date =
new DateTime();
1289 $date->add(
'-60 days');
1290 $messageCount = \Bitrix\Im\Model\MessageTable::getCount([
1291 '=CHAT_ID' => $chatId,
1292 '>DATE_CREATE' => $date
1295 IM\Model\ChatTable::update($chatId, [
'MESSAGE_COUNT' => $messageCount]);
1298 private static function deleteInternal(IM\V2\Message
$message,
int $userId): void
1301 \Bitrix\Im\Model\MessageTable::delete(
$message->getId());
1302 (
new IM\V2\Message\ReadService())->deleteByMessage(
$message, [
$userId]);
1305 private static function deleteListInternal(IM\V2\MessageCollection
$messages,
array $userIds): void
1308 if (empty($messageIds))
1313 IM\Model\MessageParamTable::deleteBatch([
'=MESSAGE_ID' => $messageIds]);
1314 IM\Model\MessageTable::deleteBatch([
'=ID' => $messageIds]);
1315 (
new IM\V2\Message\ReadService())->deleteByMessages(
$messages, $userIds);
1318 private static function getNotificationById(
int $id): ?
array
1323 SELECT M.*, R.USER_ID as RELATION_USER_ID
1325 LEFT JOIN b_im_relation R ON R.CHAT_ID = M.CHAT_ID
1338 private static function getNotificationList(
array $messageIds):
array
1340 if (empty($messageIds))
1345 return IM\Model\MessageTable::query()
1346 ->setSelect([
'*',
'RELATION_USER_ID' =>
'RELATION.USER_ID'])
1347 ->registerRuntimeField(
new Reference(
1349 IM\Model\RelationTable::class,
1350 Join::on(
'this.CHAT_ID',
'ref.CHAT_ID')
1352 [
'join_type' => Join::TYPE_INNER]
1354 ->whereIn(
'ID', $messageIds)
1359 private function fillReadStatuses(
array $notifications):
array
1361 $messageIds = array_keys($notifications);
1363 $readStatuses = (
new IM\V2\Message\ReadService($this->user_id))->getReadStatusesByMessageIds($messageIds);
1365 foreach ($notifications as $id => $notification)
1367 $notifications[$id][
'NOTIFY_READ'] = $readStatuses[$id] ?
'Y' :
'N';
1370 return $notifications;
1377 if (is_array($id) &&
count($id) === 1)
1382 if (is_array($id) &&
count($id) > 1)
1384 $ids = array_map(
static function($item) {
1388 $sqlWhere =
"M.ID IN (" . implode(
',', $ids) .
")";
1393 $sqlWhere =
"M.ID = " . $id;
1397 SELECT M.* FROM b_im_relation R, b_im_message M
1398 WHERE ". $sqlWhere .
"
1399 AND R.USER_ID = ".$this->user_id.
"
1401 AND R.CHAT_ID = M.CHAT_ID
1405 $notificationsToDelete = [];
1408 $notificationsToDelete[] = (int)
$arRes[
'ID'];
1411 if (
count($notificationsToDelete) === 0)
1416 if (
count($notificationsToDelete) === 1)
1418 self::Delete($notificationsToDelete[0]);
1422 self::deleteList($notificationsToDelete);
1432 $notifyTag = (string)$notifyTag;
1433 if ($notifyTag ==
'')
1439 if ($authorId !==
false)
1441 $sqlUser =
" AND M.AUTHOR_ID = " . (int)$authorId;
1447 WHERE M.NOTIFY_TAG = '" .
$DB->ForSQL($notifyTag) .
"'" . $sqlUser)
1451 while ($row =
$dbRes->Fetch())
1458 self::deleteList(
$messages, [
'NOTIFY_TAG' => $notifyTag]);
1468 $notifySubTag = (string)$notifySubTag;
1469 if ($notifySubTag ==
'')
1473 SELECT M.ID, M.NOTIFY_TYPE, R.USER_ID, R.STATUS, R.CHAT_ID
1474 FROM b_im_relation R, b_im_message M
1475 WHERE M.CHAT_ID = R.CHAT_ID AND M.NOTIFY_SUB_TAG = '".
$DB->ForSQL($notifySubTag).
"'");
1477 $arChatId = Array();
1479 while ($row =
$dbRes->Fetch())
1482 $arUsers[$row[
'USER_ID']] = $row[
'USER_ID'];
1483 $arChatId[$row[
'CHAT_ID']] = $row[
'CHAT_ID'];
1486 $pullActive =
false;
1487 if (CModule::IncludeModule(
"pull"))
1490 $arUsersSend = Array();
1500 CPushManager::DeleteFromQueueBySubTag(
$userId, $notifySubTag);
1504 $counters = self::GetCounters(array_keys($arChatId));
1514 'module_id' =>
'im',
1515 'command' =>
'notifyConfirm',
1519 'confirmMessages' => $resultMessages,
1522 'extra' => \
Bitrix\Im\Common::getPullExtra()
1531 public static function DeleteBySubTag($notifySubTag, $authorId =
false, $pullActive =
true)
1535 $notifySubTag = (string)$notifySubTag;
1536 if ($notifySubTag ==
'')
1542 if ($authorId !==
false)
1544 $sqlUser =
" AND M.AUTHOR_ID = ".intval($authorId);
1550 WHERE M.NOTIFY_SUB_TAG = '".
$DB->ForSQL($notifySubTag).
"'".$sqlUser)
1554 while ($row =
$dbRes->Fetch())
1561 $notifySubTag =
null;
1564 return self::deleteList(
$messages, [
'NOTIFY_SUB_TAG' => $notifySubTag]);
1575 $moduleEvent = (string)$moduleEvent;
1576 if ($moduleEvent <>
'')
1578 $sqlEvent =
" AND NOTIFY_EVENT = '".$DB->ForSQL($moduleEvent).
"'";
1581 if (
$DB->type ==
'MYSQL')
1585 FROM b_im_message M INNER JOIN b_im_message_unread U ON M.ID = U.MESSAGE_ID
1586 WHERE M.NOTIFY_MODULE = '".$DB->ForSQL(
$moduleId).
"'".$sqlEvent;
1591 DELETE FROM b_im_message_unread U
1592 USING b_im_message M
1593 WHERE M.ID = U.MESSAGE_ID
1594 AND M.NOTIFY_MODULE = '".$DB->ForSQL(
$moduleId).
"'".$sqlEvent;
1596 $DB->Query($strSql);
1598 if (
$DB->type ==
'MYSQL')
1602 FROM b_im_message M INNER JOIN b_im_message_viewed V ON M.ID = V.MESSAGE_ID
1603 WHERE M.NOTIFY_MODULE = '".$DB->ForSQL(
$moduleId).
"'".$sqlEvent;
1608 DELETE FROM b_im_message_viewed V
1609 USING b_im_message M
1610 WHERE M.ID = V.MESSAGE_ID
1611 AND M.NOTIFY_MODULE = '".$DB->ForSQL(
$moduleId).
"'".$sqlEvent;
1613 $DB->Query($strSql);
1615 $strSql =
"DELETE FROM b_im_message WHERE NOTIFY_MODULE = '".$DB->ForSQL(
$moduleId).
"'".$sqlEvent;
1616 $DB->Query($strSql);
1624 if (isset($arNotify[
'unreadNotify']) && !empty($arNotify[
'unreadNotify']) && isset($arNotify[
'notify']))
1626 foreach ($arNotify[
'unreadNotify'] as
$key => $value)
1628 if (!isset($arNotify[
'notify'][
$key]))
1637 $count = $cache? $cache[
'counter']: 0;
1644 return \Bitrix\Im\Notify::getRealCounter($chatId);
1649 return \Bitrix\Im\Notify::getRealCounters($chatId);
1654 return \Bitrix\Im\Notify::getCounter($chatId);
1659 return \Bitrix\Im\Notify::getCounters($chatIds);
if(! $messageFields||!isset($messageFields['message_id'])||!isset($messageFields['status'])||!CModule::IncludeModule("messageservice")) $messageId
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static clearCache($userId=null)
static parse($text, $params=Array())
static getInstance($userId=null)
static createFromTimestamp($timestamp)
static add($recipient, array $parameters, $channelType=\CPullChannel::TYPE_PRIVATE)
static send($userId=null, $appId=self::MOBILE_APP)
static GetUserOffset(array $params)
static DeleteAll($messageId)
GetNotifyCounter($arNotify=Array())
static DeleteByTag($notifyTag, $authorId=false)
static DeleteBySubTag($notifySubTag, $authorId=false, $pullActive=true)
static ConfirmBySubTag($notifySubTag, $resultMessages)
static GetRealCounters($chatId)
static deleteList(array $ids, array $params=[])
static getTextMessageByLang(int $userId, callable $locFunction)
static SetLastSendId($chatId, $lastSendId)
static GetFormatNotify(array $arFields)
static GetCounters($chatIds)
MarkNotifyUnRead($id=0, $setThisAndHigher=false, $appId='Bitrix24')
static GetCounter($chatId)
MarkNotifyRead($id=0, $setThisAndHigher=false, $appId='Bitrix24')
MarkNotifyReadBySubTag($subTagList=array())
GetUnreadNotify($arParams=Array())
static SetLastId($chatId, $userId, $lastId=null)
static GetRealCounter($chatId)
static DeleteByModule($moduleId, $moduleEvent='')
GetNotifyList($arParams=array())
__construct($user_id=false, $arParams=Array())
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
ExecuteModuleEventEx($arEvent, $arParams=[])
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
GetMessage($name, $aReplace=null)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
</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."%"
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']