403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/im/lib/V2/Anchor/Push/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/im/lib/V2/Anchor/Push/PushService.php
<?php

declare(strict_types=1);

namespace Bitrix\Im\V2\Anchor\Push;

use Bitrix\Im\Common;
use Bitrix\Im\V2\Anchor\AnchorCollection;
use Bitrix\Im\V2\Anchor\AnchorItem;
use Bitrix\Im\V2\Chat;
use Bitrix\Main\Loader;
use Bitrix\Pull\Event;

class PushService
{
	private const ADD_ANCHOR_EVENT = 'addAnchor';
	private const DELETE_ANCHOR_EVENT = 'deleteAnchor';
	private const DELETE_CHAT_ANCHORS_EVENT = 'deleteChatAnchors';
	private const DELETE_ALL_ANCHORS_EVENT = 'deleteAllAnchors';

	public function addMulti(AnchorCollection $anchorCollection): void
	{
		foreach ($anchorCollection as $anchorItem)
		{
			$this->send(self::ADD_ANCHOR_EVENT, $anchorItem);
		}
	}

	public function add(AnchorItem $anchorItem): void
	{
		$this->send(self::ADD_ANCHOR_EVENT, $anchorItem);
	}

	public function deleteMulti(AnchorCollection $anchorCollection): void
	{
		foreach ($anchorCollection as $anchorItem)
		{
			$this->delete($anchorItem);
		}
	}

	public function delete(AnchorItem $anchorItem): void
	{
		$this->send(self::DELETE_ANCHOR_EVENT, $anchorItem);
	}

	public function deleteByChat(int $chatId, int $userId): void
	{
		if (!Loader::includeModule('pull'))
		{
			return;
		}

		$chat = Chat::getInstance($chatId);

		if ($chat instanceof Chat\PrivateChat)
		{
			$this->deleteByPrivateChat($chatId, $userId);

			return;
		}

		$parameters = [
			'dialogId' => $chat->getDialogId(),
			'chatId' => $chatId,
			'userId' => $userId,
		];

		$pull = [
			'module_id' => 'im',
			'command' => static::DELETE_CHAT_ANCHORS_EVENT,
			'params' => $parameters,
			'extra' => Common::getPullExtra(),
		];

		Event::add([$userId], $pull);
	}

	public function deleteAll(int $userId): void
	{
		if (!Loader::includeModule('pull'))
		{
			return;
		}

		$pull = [
			'module_id' => 'im',
			'command' => static::DELETE_ALL_ANCHORS_EVENT,
			'params' => ['userId' => $userId],
			'extra' => Common::getPullExtra(),
		];

		Event::add($userId, $pull);
	}

	private function send(string $eventName, AnchorItem $anchorItem): void
	{
		if (!Loader::includeModule('pull'))
		{
			return;
		}

		$chat = Chat::getInstance($anchorItem->getChatId());

		$parameters = [...$anchorItem->toRestFormat()];

		if ($chat instanceof Chat\PrivateChat)
		{
			$this->sendToPrivateChat($parameters, $eventName, $anchorItem);

			return;
		}

		$parameters['dialogId'] = $chat->getDialogId();
		$pull = [
			'module_id' => 'im',
			'command' => $eventName,
			'params' => $parameters,
			'extra' => Common::getPullExtra(),
		];

		Event::add([$anchorItem->getUserId()], $pull);
	}

	private function sendToPrivateChat(array $parameters, string $eventName, AnchorItem $anchorItem): void
	{
		/** @var Chat\PrivateChat $chat */
		$chat = Chat::getInstance($anchorItem->getChatId());

		$recipientId = $anchorItem->getUserId();

		$parameters['dialogId'] = $chat->getCompanion($recipientId)->getId();
		Event::add($recipientId, [
			'module_id' => 'im',
			'command' => $eventName,
			'params' => $parameters,
			'extra' => Common::getPullExtra(),
		]);
	}

	private function deleteByPrivateChat(int $chatId, int $userId): void
	{
		/** @var Chat\PrivateChat $chat */
		$chat = Chat::getInstance($chatId);

		$parameters = [
			'dialogId' => $chat->getCompanion($userId)->getId(),
			'chatId' => $chatId,
			'userId' => $userId,
		];

		Event::add($userId, [
			'module_id' => 'im',
			'command' => static::DELETE_CHAT_ANCHORS_EVENT,
			'params' => $parameters,
			'extra' => Common::getPullExtra(),
		]);
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit