• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/classes/general/im_rest.php
  • Класс: CIMRestService
  • Вызов: CIMRestService::videoconfShareChange
static function videoconfShareChange($params, $n, CRestServer $server)
{
	global $USER;
	$userName = $USER->GetFullName();
	$params = array_change_key_case($params, CASE_UPPER);

	if (!BitrixImCommon::isDialogId($params['DIALOG_ID']))
	{
		throw new BitrixRestRestException("Dialog ID can't be empty", "DIALOG_ID_EMPTY", CRestServer::STATUS_WRONG_REQUEST);
	}

	//check owner
	$chatId = BitrixImDialog::getChatId($params['DIALOG_ID']);
	$chatData = BitrixImChat::getById($chatId);

	if ($USER->GetID() != $chatData['OWNER'])
	{
		throw new BitrixRestRestException("You don't have access to this chat", "ACCESS_ERROR", CRestServer::STATUS_WRONG_REQUEST);
	}

	//get chat users and delete guests
	$chatUsers = BitrixImChat::getUsers($chatId);
	$externalTypes = BitrixMainUserTable::getExternalUserTypes();

	$chat = new CIMChat($USER->GetId());
	foreach($chatUsers as $user)
	{
		if (in_array($user['external_auth_id'], $externalTypes, true))
		{
			$chat->DeleteUser($chatId, $user['id']);
		}
	}

	//get alias
	$aliasData = BitrixImAlias::getByEntity('VIDEOCONF', $chatId);

	//generate new alias and update
	$newCode = BitrixImAlias::generateUnique();
	$updateResult = BitrixImAlias::update($aliasData['ID'], [
		'ALIAS' => $newCode,
		'ENTITY_TYPE' => 'VIDEOCONF',
		'ENTITY_ID' => $chatId
	]);

	if (!$updateResult)
	{
		throw new BitrixRestRestException("Can't update alias", "ACCESS_ERROR", CRestServer::STATUS_WRONG_REQUEST);
	}

	$newLink = BitrixImAlias::get($newCode)['LINK'];

	//add message to chat
	$attach = new CIMMessageParamAttach(null);
	$attach->AddLink(
		[
			"NAME" => $newLink,
			"DESC" => GetMessage("IM_VIDEOCONF_SHARE_UPDATED_LINK", ['#USER_NAME#' => htmlspecialcharsback($userName)]),
			"LINK" => $newLink
		]
	);

	CIMChat::AddMessage(
		[
			"TO_CHAT_ID" => $chatId,
			"SYSTEM" => 'Y',
			"FROM_USER_ID" => $USER->GetID(),
			"MESSAGE" => GetMessage("IM_VIDEOCONF_LINK_TITLE"),
			"ATTACH" => $attach
		]
	);

	//send pull with changed alias

	$relations = BitrixImChat::getRelation($chatId, ['WITHOUT_COUNTERS' => 'Y']);
	if (CModule::IncludeModule("pull"))
	{
		BitrixPullEvent::add(array_keys($relations), [
			'module_id' => 'im',
			'command' => 'videoconfShareUpdate',
			'params' => [
				'newCode' => $newCode,
				'newLink' => $newLink,
				'dialogId' => $params['DIALOG_ID']
			],
			'extra' => BitrixImCommon::getPullExtra()
		]);
	}

	return true;
}