• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/lib/V2/Message/PushFormat.php
  • Класс: BitrixImV2MessagePushFormat
  • Вызов: PushFormat::validateDataForInform
public function validateDataForInform(Message $message, PrivateChat $chat): Result
{
	$result = new Result();

	$toUserId = $chat->getCompanion()->getId();
	$user = CIMContactList::GetUserData(['ID' =>  [$toUserId]]);
	$toUserStatus = $user['users'][$toUserId]['status'];

	if (!($message->getAuthorId() === $this->getContext()->getUserId()))
	{
		$result->addError(new MessageMessageError(MessageMessageError::INFORM_USER_CONTEXT_ERROR));
	}

	if ($message->isViewedByOthers())
	{
		$result->addError(new MessageMessageError(MessageMessageError::INFORM_VIEWED_ERROR));
	}

	$timestampTimeNow = DateTime::createFromTimestamp(time())->getTimestamp();
	if (!($timestampTimeNow - $message->getDateCreate()->getTimestamp() <= self::MAX_CHAT_MESSAGE_TIME))
	{
		$result->addError(new MessageMessageError(MessageMessageError::INFORM_TIMEOUT_ERROR));
	}

	if (!($toUserStatus === self::DND_USER_STATUS))
	{
		$result->addError(new MessageMessageError(MessageMessageError::INFORM_USER_STATUS_ERROR));
	}

	return $result;
}