- Модуль: socialnetwork
- Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/log_comments.php
- Класс: CAllSocNetLogComments
- Вызов: CAllSocNetLogComments::SendMentionNotification
static function SendMentionNotification($arCommentFields)
{
if (!CModule::IncludeModule("im"))
{
return false;
}
switch ($arCommentFields["EVENT_ID"])
{
case "forum":
$arTitleRes = self::OnSendMentionGetEntityFields_Forum($arCommentFields);
break;
default:
$db_events = GetModuleEvents("socialnetwork", "OnSendMentionGetEntityFields");
while ($arEvent = $db_events->Fetch())
{
$arTitleRes = ExecuteModuleEventEx($arEvent, array($arCommentFields));
if ($arTitleRes)
{
break;
}
}
}
if (
$arTitleRes
&& is_array($arTitleRes)
&& !empty($arTitleRes["NOTIFY_MESSAGE"])
)
{
$arMessageFields = array(
"MESSAGE_TYPE" => IM_MESSAGE_SYSTEM,
"FROM_USER_ID" => $arCommentFields["USER_ID"],
"NOTIFY_TYPE" => IM_NOTIFY_FROM,
"NOTIFY_MODULE" => (!empty($arTitleRes["NOTIFY_MODULE"]) ? $arTitleRes["NOTIFY_MODULE"] : "socialnetwork"),
"NOTIFY_EVENT" => "mention",
"NOTIFY_TAG" => (!empty($arTitleRes["NOTIFY_TAG"]) ? $arTitleRes["NOTIFY_TAG"] : "LOG_COMMENT|COMMENT_MENTION|".$arCommentFields["ID"])
);
$arMention = BitrixSocialnetworkHelperMention::getUserIds($arCommentFields['MESSAGE']);
if(!empty($arMention))
{
$arExcludeUsers = array($arCommentFields["USER_ID"]);
if (!empty($arCommentFields["LOG_ID"]))
{
$rsUnFollower = CSocNetLogFollow::GetList(
array(
"CODE" => "L".$arCommentFields["LOG_ID"],
"TYPE" => "N"
),
array("USER_ID")
);
while ($arUnFollower = $rsUnFollower->Fetch())
{
$arExcludeUsers[] = $arUnFollower["USER_ID"];
}
}
$arSourceURL = array(
"URL" => $arTitleRes["URL"]
);
if (!empty($arTitleRes["CRM_URL"]))
{
$arSourceURL["CRM_URL"] = $arTitleRes["CRM_URL"];
}
foreach ($arMention as $mentionUserID)
{
$bHaveRights = (
($arTitleRes["IS_CRM"] ?? null) != "Y"
|| COption::GetOptionString("crm", "enable_livefeed_merge", "N") == "Y"
? CSocNetLogRights::CheckForUserOnly($arCommentFields["LOG_ID"], $mentionUserID)
: false
);
if (
$bHaveRights
&& $arTitleRes["IS_CRM"] == "Y"
) // user has 'normal' rights to the log entry but it's crm
{
$dbLog = CSocNetLog::getList(
array(),
array(
"ID" => $arCommentFields["LOG_ID"],
),
false,
false,
array("ID", "MODULE_ID")
);
if (
!($arLog = $dbLog->fetch())
|| $arLog["MODULE_ID"] != "crm_shared"
)
{
$bHaveRights = false;
}
}
$bHaveCrmRights = false;
if (
!$bHaveRights
&& ($arTitleRes["IS_CRM"] ?? null) == "Y"
)
{
$dbLog = CSocNetLog::GetList(
array(),
array(
"ID" => $arCommentFields["LOG_ID"],
"ENTITY_TYPE" => $arCommentFields["ENTITY_TYPE"],
),
false,
false,
array("ID"),
array(
"IS_CRM" => "Y",
"CHECK_CRM_RIGHTS" => "Y",
"USER_ID" => $mentionUserID,
"USE_SUBSCRIBE" => "N"
)
);
if ($arLog = $dbLog->fetch())
{
$bHaveCrmRights = true;
}
}
if (
in_array($mentionUserID, $arExcludeUsers)
|| (!$bHaveRights && !$bHaveCrmRights)
)
{
continue;
}
$url = false;
if (
!empty($arSourceURL["URL"])
|| !empty($arSourceURL["CRM_URL"])
)
{
$arTmp = CSocNetLogTools::ProcessPath(
$arSourceURL,
$mentionUserID
);
if (
$arTitleRes["IS_CRM"] == "Y"
&& $bHaveCrmRights
&& !empty($arTmp["URLS"]["CRM_URL"])
)
{
$url = $arTmp["URLS"]["CRM_URL"];
}
else
{
$url = $arTmp["URLS"]["URL"];
}
$serverName = (mb_strpos($url, "http://") === 0 || mb_strpos($url, "https://") === 0 ? "" : $arTmp["SERVER_NAME"]);
}
$arMessageFields["TO_USER_ID"] = $mentionUserID;
$arMessageFields["NOTIFY_MESSAGE"] = str_replace(array("#url#", "#server_name#"), array($url, $serverName), $arTitleRes["NOTIFY_MESSAGE"]);
$arMessageFields["NOTIFY_MESSAGE_OUT"] = (!empty($arTitleRes["NOTIFY_MESSAGE_OUT"]) ? str_replace(array("#url#", "#server_name#"), array($url, $serverName), $arTitleRes["NOTIFY_MESSAGE_OUT"]) : "");
CIMNotify::Add($arMessageFields);
}
$arMentionedDestCode = array();
foreach($arMention as $val)
{
$arMentionedDestCode[] = "U".$val;
}
BitrixMainFinderDestTable::merge(array(
"CONTEXT" => "mention",
"CODE" => array_unique($arMentionedDestCode)
));
}
}
}