• Модуль: xdimport
  • Путь к файлу: ~/bitrix/modules/xdimport/lib/integration/socialnetwork/logcomment.php
  • Класс: BitrixXDImportIntegrationSocialnetworkLogComment
  • Вызов: LogComment::sendNotification
static function sendNotification(array $params = [])
{
	$result = [];

	if (
		!Loader::includeModule('im')
		|| !Loader::includeModule('socialnetwork')
	)
	{
		return $result;
	}

	$type = (isset($params['type']) ? (string)$params['type'] : '');
	if ($type !== 'mention')
	{
		return $result;
	}

	$userIdList = (isset($params['userIdList']) && is_array($params['userIdList']) ? $params['userIdList'] : []);
	$userIdList = self::processUserList($userIdList);
	if (empty($userIdList))
	{
		return $result;
	}

	$authorId = (isset($params['authorId']) ? (int)$params['authorId'] : 0);
	if ($authorId <= 0)
	{
		return $result;
	}

	$logId = (isset($params['logId']) ? (int)$params['logId'] : 0);
	if ($logId <= 0)
	{
		return $result;
	}

	$notifyEvent = '';
	$notifyTag = '';
	$pushAction = '';

	switch ($type)
	{
		case 'mention':
			$notifyEvent = 'mention_comment';
			$notifyTag = 'XDIMPORT|COMMENT_MENTION|' . $logId . '|';
			$pushAction = 'mention';
			break;
		default:
	}

	$notificationFields = [
		'MESSAGE_TYPE' => IM_MESSAGE_SYSTEM,
		'TO_USER_ID' => null,
		'FROM_USER_ID' => $authorId,
		'NOTIFY_TYPE' => IM_NOTIFY_FROM,
		'NOTIFY_ANSWER' => 'N',
		'NOTIFY_MODULE' => 'xdimport',
		'PARSE_LINK' => 'N',
		'PUSH_PARAMS' => [
			'ACTION' => $pushAction,
			'TAG' => $notifyTag,
			'ADVANCED_PARAMS' => [],
		],
		'NOTIFY_EVENT' => $notifyEvent,
		'NOTIFY_TAG' => $notifyTag,
	];

	$authorFields = self::getUserData($authorId);
	$authorGenderSuffix = (string)$authorFields['PERSONAL_GENDER'];
	$authorAvatarUrl = self::getAvatarUrl([
		'fileId' => (int)$authorFields['PERSONAL_PHOTO'],
	]);

	if (!empty($authorAvatarUrl))
	{
		$notificationFields['PUSH_PARAMS']['ADVANCED_PARAMS']['avatarUrl'] = $authorAvatarUrl;
	}

	foreach ($userIdList as $userId)
	{
		$userSite = self::getUserSite($userId);

		$currentNotificationFields = $notificationFields;
		$currentNotificationFields['TO_USER_ID'] = $userId;

		$provider = new LivefeedLogEvent();
		$provider->setEntityId($logId);
		$provider->setLogId($logId);
		$provider->setSiteId($userSite);

		$postUrl = $provider->getLiveFeedUrl();

		$notifySubTag = '';
		switch ($type)
		{
			case 'mention':
				$notifySubTag = 'XDIMPORT|COMMENT_MENTION|' . $logId . '|' . $userId;
				$message = ($authorGenderSuffix === 'F' ? 'XDIMPORT_COMMENT_MENTION_NOTIFICATION_MESSAGE_F' : 'XDIMPORT_COMMENT_MENTION_NOTIFICATION_MESSAGE');
				$messageOut = ($authorGenderSuffix === 'F' ? 'XDIMPORT_COMMENT_MENTION_NOTIFICATION_MESSAGE_OUT_F' : 'XDIMPORT_COMMENT_MENTION_NOTIFICATION_MESSAGE_OUT');
				$messagePush = ($authorGenderSuffix === 'F' ? 'XDIMPORT_COMMENT_MENTION_NOTIFICATION_MESSAGE_PUSH_F' : 'XDIMPORT_COMMENT_MENTION_NOTIFICATION_MESSAGE_PUSH');
				break;
			default:
		}

		$currentNotificationFields['NOTIFY_SUB_TAG'] = $notifySubTag;

		$currentNotificationFields['NOTIFY_MESSAGE'] = Loc::getMessage(
			$message,
			[
				'#A_BEGIN#' => '',
				'#A_END#' => '',
			]
		);

		$currentNotificationFields['NOTIFY_MESSAGE_OUT'] = Loc::getMessage(
			$messageOut,
			[
				'#URL#' => self::getAbsoluteUrl([
					'url' => $postUrl,
					'siteId' => $userSite,
				]),
			]
		);

		$authorName = CUser::formatName(CSite::getNameFormat(null, $userSite), $authorFields, true, false);

		$currentNotificationFields['PUSH_MESSAGE'] = Loc::getMessage(
			$messagePush,
			[
				"#AUTHOR#" => htmlspecialcharsbx($authorName),
			]
		);

		$currentNotificationFields['PUSH_PARAMS']['ADVANCED_PARAMS']['senderName'] = $authorName;

		if (CIMNotify::add($currentNotificationFields))
		{
			$result[] = $userId;
		}
	}

	return $result;
}