- Модуль: im
- Путь к файлу: ~/bitrix/modules/im/classes/general/im_chat.php
- Класс: CIMChat
- Вызов: CIMChat::SetUnReadMessage
public function SetUnReadMessage($chatId, $lastId)
{
//global $DB;
$chatId = intval($chatId);
if ($chatId <= 0)
return false;
$lastId = intval($lastId);
if (intval($lastId) <= 0)
return false;
/*$result = BitrixImV2Chat::getInstance($chatId)->unreadToMessage(new IMV2Message($lastId));
return $result->isSuccess();*/
$readService = new IMV2MessageReadService($this->user_id);
$endId = $readService->getLastMessageIdInChat($chatId);
$relation = CIMMessage::SetLastIdForUnread($chatId, $this->user_id, $lastId);
if ($relation)
{
$chat = BitrixImV2Chat::getInstance($chatId);
BitrixMainApplication::getConnection()->query(
"UPDATE b_im_recent SET DATE_UPDATE = NOW() WHERE USER_ID = ".$this->user_id." AND ITEM_CID = ".intval($chatId)
);
CIMMessenger::SpeedFileDelete($this->user_id, IM_SPEED_GROUP);
if (CModule::IncludeModule("pull"))
{
$lastMessageStatuses = $readService->getViewedService()->getMessageStatuses($chat->getLastMessages($endId, $lastId));
BitrixPullEvent::add($this->user_id, Array(
'module_id' => 'im',
'command' => 'unreadMessageChat',
'params' => Array(
'dialogId' => 'chat'.$chatId,
'chatId' => (int)$chatId,
'lastId' => $endId,
'date' => new BitrixMainTypeDateTime(),
'counter' => (int)$relation['COUNTER'],
'muted' => $relation['NOTIFY_BLOCK'] === 'Y',
'lines' => $relation['MESSAGE_TYPE'] === IM_MESSAGE_OPEN_LINE,
'unreadTo' => $lastId,
'unread' => ImRecent::isUnread($this->user_id, $relation['MESSAGE_TYPE'], 'chat'.$chatId),
'lastMessageStatuses' => $lastMessageStatuses,
'lastMessageViews' => ImCommon::toJson($chat->getLastMessageViews()),
),
'push' => Array('badge' => 'Y'),
'extra' => BitrixImCommon::getPullExtra()
));
$arRelation = self::GetRelationById($chatId, false, true, false);
unset($arRelation[$this->user_id]);
$pushMessage = Array(
'module_id' => 'im',
'command' => 'unreadMessageChatOpponent',
'expiry' => 600,
'params' => Array(
'dialogId' => 'chat'.$chatId,
'chatId' => (int)$chatId,
'userId' => (int)$this->user_id,
'chatMessageStatus' => $relation['CHAT_MESSAGE_STATUS'],
'unreadTo' => $lastId,
'lastMessageStatuses' => $lastMessageStatuses,
),
'extra' => BitrixImCommon::getPullExtra()
);
if ($chat->getEntityType() == 'LINES')
{
foreach ($arRelation as $rel)
{
if ($rel["EXTERNAL_AUTH_ID"] == 'imconnector')
{
unset($arRelation[$rel["USER_ID"]]);
}
}
}
$viewsByGroups = $chat->getLastMessageViewsByGroups();
foreach ($viewsByGroups as $view)
{
$pushMessage['params']['lastMessageViews'] = ImCommon::toJson($view['VIEW_INFO']);
$usersForPush = array_keys($arRelation);
$recipient = array_intersect($usersForPush, $view['USERS']);
BitrixPullEvent::add($recipient, $pushMessage);
}
/*BitrixPullEvent::add(array_keys($arRelation), $pushMessage);
if ($chat->getType() == IM_MESSAGE_OPEN || $chat->getType() == IM_MESSAGE_OPEN_LINE)
{
CPullWatch::AddToStack('IM_PUBLIC_'.$chatId, $pushMessage);
}*/
}
return true;
}
return false;
}