static function SendUnreadMessages($receiverJId, $domain = "")
{
$receiverJId = trim($receiverJId);
if ($receiverJId == '')
return false;
$receiver = CXMPPUtility::GetUserByJId($receiverJId, $domain);
if (!$receiver)
return false;
$factory = CXMPPFactory::GetFactory();
if (IsModuleInstalled("im") && CModule::IncludeModule("im"))
{
$CIMMessage = new CIMMessage($receiverJId, Array(
'hide_link' => true
));
$arMessage = $CIMMessage->GetUnreadMessage(Array(
'SPEED_CHECK' => 'N',
'ORDER' => 'ASC',
'USE_SMILES' => 'N',
'USER_LOAD' => 'N',
'LOAD_DEPARTMENT' => 'N'
));
if ($arMessage['result'])
{
$parser = new CTextParser();
foreach ($arMessage['message'] as $id => $arMessage)
{
$factory->__SendMessage(
$arMessage["senderId"],
$arMessage["recipientId"],
$arMessage["id"],
IM_MESSAGE_PRIVATE,
htmlspecialcharsbx($parser->convert4mail(str_replace(array("#BR#", "
", "
", "
"), "n", $arMessage["text"]))),
$domain
);
}
}
// Notify
$CIMNotify = new CIMNotify($receiverJId);
$arNotify = $CIMNotify->GetUnreadNotify(Array(
'SPEED_CHECK' => 'N',
'ORDER' => 'ASC'
));
if ($arNotify['result'])
{
$parser = new CTextParser();
foreach ($arNotify['original_notify'] as $id => $arNotify)
{
if (isset($arNotify["NOTIFY_MODULE"]) && isset($arNotify["NOTIFY_EVENT"])
&& !CIMSettings::GetNotifyAccess($arNotify["TO_USER_ID"], $arNotify["NOTIFY_MODULE"], $arNotify["NOTIFY_EVENT"], CIMSettings::CLIENT_XMPP))
continue;
if ($arNotify["MESSAGE_OUT"] == IM_MAIL_SKIP)
$arNotify["MESSAGE_OUT"] = '';
$factory->__SendMessage(
$arNotify["FROM_USER_ID"],
$arNotify["TO_USER_ID"],
$arNotify["ID"],
IM_MESSAGE_SYSTEM,
htmlspecialcharsbx($parser->convert4mail(str_replace(array("#BR#", "
", "
", "
"), "n", (($arNotify["MESSAGE_OUT"] <> ''? $arNotify["MESSAGE_OUT"]: $arNotify["MESSAGE"]))))),
$domain
);
}
}
}
else
{
$parser = new CSocNetTextParser();
$dbMessages = CSocNetMessages::GetList(
array("DATE_CREATE" => "ASC"),
array("TO_USER_ID" => $receiver["ID"], "DATE_VIEW" => "", "TO_DELETED" => "N", "IS_LOG_ALL" => "Y"),
false,
false,
array("ID", "FROM_USER_ID", "TO_USER_ID", "MESSAGE", "DATE_VIEW", "MESSAGE_TYPE", "FROM_DELETED", "TO_DELETED", "IS_LOG")
);
while ($arMessage = $dbMessages->Fetch())
{
$factory->__SendMessage(
(($arMessage["IS_LOG"] == "Y") ? -5 : $arMessage["FROM_USER_ID"]),
$arMessage["TO_USER_ID"],
$arMessage["ID"],
$arMessage["MESSAGE_TYPE"],
htmlspecialcharsbx($parser->convert4mail(str_replace(array("#BR#", "
", "
", "
"), "n", $arMessage["MESSAGE"]))),
$domain
);
}
}
return true;
}