- Модуль: im
- Путь к файлу: ~/bitrix/modules/im/classes/general/im_contact_list.php
- Класс: CAllIMContactList
- Вызов: CAllIMContactList::DeleteRecent
static function DeleteRecent($entityId, $isChat = false, $userId = false)
{
global $DB;
if (is_array($entityId))
{
foreach ($entityId as $key => $value)
{
$entityId[$key] = (int)$value;
}
$entityId = array_slice($entityId, 0, 1000);
$sqlEntityId = 'ITEM_ID IN ('.implode(',', $entityId).')';
}
else if ((int)$entityId > 0)
{
$sqlEntityId = 'ITEM_ID = '.(int)$entityId;
}
else
{
return false;
}
if ((int)$userId <= 0)
{
if ($GLOBALS['USER'] instanceof CUser && $GLOBALS['USER']->getId() > 0)
{
$userId = $GLOBALS['USER']->getId();
}
else
{
return false;
}
}
if ($isChat)
{
$itemType = "ITEM_TYPE IN ('".implode("','", BitrixImChat::getTypes())."')";
}
else
{
$itemType = "ITEM_TYPE = '".IM_MESSAGE_PRIVATE."'";
}
/*$strSQL = "
UPDATE b_im_relation R
INNER JOIN b_im_recent RC
ON R.ID = RC.ITEM_RID
SET
R.STATUS = '".IM_STATUS_READ."'
, R.UNREAD_ID = 0
, R.MESSAGE_STATUS = '".IM_MESSAGE_STATUS_RECEIVED."'
, R.COUNTER = 0
, R.LAST_READ = NOW()
WHERE
RC.USER_ID = {$userId}
AND RC.{$itemType}
AND RC.{$sqlEntityId}
";
$DB->Query($strSQL, false, "FILE: ".__FILE__."
LINE: ".__LINE__);*/
$strSQL = "DELETE FROM b_im_recent WHERE USER_ID = {$userId} AND {$itemType} AND {$sqlEntityId}";
$DB->Query($strSQL, false, "FILE: ".__FILE__."
LINE: ".__LINE__);
if ($isChat)
{
$chat = IMV2Chat::getInstance((int)$entityId);
}
else
{
$chat = IMV2EntityUserUser::getInstance($userId)->getChatWith($entityId);
}
if ($chat !== null && !($chat instanceof IMV2ChatNullChat) && $chat->getChatId())
{
$chat = $chat->withContextUser($userId);
if ($chat instanceof IMV2ChatOpenLineChat)
{
$chat->read(false, false, true);
}
else
{
$chat->read();
}
}
if ($isChat && BitrixMainLoader::includeModule('pull'))
{
if (is_array($entityId))
{
foreach ($entityId as $value)
{
CPullWatch::delete($userId, 'IM_PUBLIC_'.(int)$value);
}
}
else
{
CPullWatch::delete($userId, 'IM_PUBLIC_'.(int)$entityId);
}
}
//BitrixImCounter::clearCache($userId);
$strSQL = $DB->TopSql("SELECT 1 FROM b_im_recent WHERE USER_ID = ".$userId, 1);
$rs = $DB->Query($strSQL, false, "FILE: ".__FILE__."
LINE: ".__LINE__);
if (!$rs->Fetch())
{
$event = new BitrixMainEvent("im", "OnAfterRecentDelete", array(
"user_id" => $userId,
));
$event->send();
}
return true;
}