- Модуль: im
- Путь к файлу: ~/bitrix/modules/im/classes/general/im_notify.php
- Класс: CIMNotify
- Вызов: CIMNotify::MarkNotifyUnRead
public function MarkNotifyUnRead($id = 0, $setThisAndHigher = false, $appId = 'Bitrix24')
{
global $DB;
$id = intval($id);
if ($id <= 0)
return false;
$startNotify = BitrixImModelMessageTable::getList(Array(
'select' => Array('ID', 'CHAT_ID', 'NOTIFY_TAG'),
'filter' => Array(
'=ID' => $id,
'=RELATION.MESSAGE_TYPE' => IM_MESSAGE_SYSTEM,
'=RELATION.USER_ID' => $this->user_id,
)
))->fetch();
if (!$startNotify)
{
return false;
}
$notifyTag = $startNotify['NOTIFY_TAG'] ?? null;
$chatId = intval($startNotify['CHAT_ID']);
$operator = $setThisAndHigher ? '>=' : '=';
$notifyByIdResult = IMModelMessageTable::query()
->setSelect(['ID'])
->where('CHAT_ID', $chatId)
->where('ID', $operator, $id)
->withReadOnly()
->exec()
;
$messages = new IMV2MessageCollection();
while ($notifyById = $notifyByIdResult->fetch())
{
$message = new IMV2Message();
$message->setMessageId((int)$notifyById['ID'])->setChatId($chatId)->setAuthorId(0);
$messages->add($message);
}
if ($notifyTag !== null && $notifyTag !== '')
{
$notifyByTagResult = IMModelMessageTable::query()
->setSelect(['ID'])
->where('CHAT_ID', $chatId)
->where('NOTIFY_TAG', $notifyTag)
->withReadOnly()
->exec()
;
while ($notifyByTag = $notifyByTagResult->fetch())
{
$message = new IMV2Message();
$message->setMessageId((int)$notifyByTag['ID'])->setChatId($chatId)->setAuthorId(0);
$messages->add($message);
}
}
$readService = new IMV2MessageReadService($this->user_id);
$relation = new IMV2Relation();
$relation->setChatId($chatId)->setUserId($this->user_id)->setMessageType('S')->setNotifyBlock(false);
$counter = $readService->unreadNotifications($messages, $relation)->getResult()['COUNTER'];
/* $filterId = ($setThisAndHigher? '>=': '=').'ID';
$orm = BitrixImModelMessageTable::getList(Array(
'select' => Array('ID', 'CHAT_ID', 'NOTIFY_TAG'),
'filter' => Array(
'=CHAT_ID' => $chatId,
'=NOTIFY_READ' => 'Y',
$filterId => $id,
)
));
while ($row = $orm->fetch())
{
$messages[$row['ID']] = $row;
}
if ($messages)
{
$DB->Query("UPDATE b_im_message SET NOTIFY_READ = 'N' WHERE ID IN (".implode(',', array_keys($messages)).")");
}
if (!empty($startNotify['NOTIFY_TAG']))
{
$orm = BitrixImModelMessageTable::getList(Array(
'select' => Array('ID', 'CHAT_ID', 'NOTIFY_TYPE', 'NOTIFY_READ'),
'filter' => Array(
'=CHAT_ID' => $chatId,
'=NOTIFY_READ' => 'Y',
'=NOTIFY_TAG' => $startNotify['NOTIFY_TAG'],
)
));
$tagIds = Array();
while ($row = $orm->fetch())
{
$messages[$row['ID']] = $row;
$tagIds[] = $row['ID'];
}
if ($tagIds)
{
$DB->Query("UPDATE b_im_message SET NOTIFY_READ = 'N' WHERE ID IN (".implode(',', $tagIds).")");
}
}
if (!$messages)
{
return false;
}
$lastId = max(array_keys($messages));
self::SetLastId($chatId, $this->user_id, $lastId);*/
if (CModule::IncludeModule("pull"))
{
BitrixPullEvent::add($this->user_id, Array(
'module_id' => 'im',
'command' => 'notifyUnread',
'params' => Array(
'chatId' => $chatId,
'list' => $messages->getIds(),
'counter' => $counter
),
'extra' => BitrixImCommon::getPullExtra()
));
BitrixPullMobileCounter::send($this->user_id, $appId);
}
CIMMessenger::SpeedFileDelete($this->user_id, IM_SPEED_NOTIFY);
return true;
}