- Модуль: im
- Путь к файлу: ~/bitrix/modules/im/classes/general/im_notify.php
- Класс: CIMNotify
- Вызов: CIMNotify::updateStateAfterDelete
static function updateStateAfterDelete(int $chatId, int $userId, bool $needToUpdateRecent): void
{
global $DB;
CIMMessenger::SpeedFileDelete($userId, IM_SPEED_NOTIFY);
// update total amount of notifications
$date = new DateTime();
$date->add('-60 days'); // sync with BitrixImNotify::cleanNotifyAgent
$messageCount = BitrixImModelMessageTable::getList([
'select' => ['CNT'],
'filter' => [
'=CHAT_ID' => $chatId,
'>DATE_CREATE' => $date
],
'runtime' => [
new BitrixMainORMFieldsExpressionField('CNT', 'COUNT(*)')
]
])->fetch();
IMModelChatTable::update($chatId, [
'MESSAGE_COUNT' => $messageCount['CNT'],
]);
// update the preview of last message in recent list
if ($needToUpdateRecent)
{
$ormParams = [
'select' => ['ID'],
'filter' => [
'=CHAT_ID' => $chatId,
],
'order' => ['DATE_CREATE' => 'DESC'],
'limit' => 1,
];
$lastNotification = BitrixImModelMessageTable::getRow($ormParams);
if ($lastNotification !== null)
{
$DB->Query("
UPDATE b_im_recent
SET ITEM_MID = {$lastNotification['ID']}
WHERE
USER_ID = {$userId}
AND
ITEM_TYPE = 'S'
AND
ITEM_ID = {$userId}
");
}
}
}