2024-12-24 00:51:13 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Socialbox\Classes\StandardMethods;
|
|
|
|
|
|
|
|
use Exception;
|
2025-01-06 04:44:35 -05:00
|
|
|
use ncc\ThirdParty\Symfony\Process\Exception\InvalidArgumentException;
|
2024-12-24 00:51:13 -05:00
|
|
|
use Socialbox\Abstracts\Method;
|
|
|
|
use Socialbox\Enums\Flags\SessionFlags;
|
|
|
|
use Socialbox\Enums\StandardError;
|
|
|
|
use Socialbox\Exceptions\StandardException;
|
|
|
|
use Socialbox\Interfaces\SerializableInterface;
|
|
|
|
use Socialbox\Managers\RegisteredPeerManager;
|
|
|
|
use Socialbox\Managers\SessionManager;
|
|
|
|
use Socialbox\Objects\ClientRequest;
|
|
|
|
use Socialbox\Objects\RpcRequest;
|
|
|
|
|
|
|
|
class SettingsSetDisplayName extends Method
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public static function execute(ClientRequest $request, RpcRequest $rpcRequest): ?SerializableInterface
|
|
|
|
{
|
|
|
|
if(!$rpcRequest->containsParameter('name'))
|
|
|
|
{
|
|
|
|
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, "Missing 'name' parameter");
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2025-01-06 04:44:35 -05:00
|
|
|
// Update the display name
|
2024-12-24 00:51:13 -05:00
|
|
|
RegisteredPeerManager::updateDisplayName($request->getPeer(), $rpcRequest->getParameter('name'));
|
|
|
|
|
|
|
|
// Check & update the session flow
|
2025-01-06 04:44:35 -05:00
|
|
|
SessionManager::updateFlow($request->getSession(), [SessionFlags::SET_DISPLAY_NAME]);
|
|
|
|
}
|
|
|
|
catch(InvalidArgumentException)
|
|
|
|
{
|
|
|
|
return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, 'Invalid display name');
|
2024-12-24 00:51:13 -05:00
|
|
|
}
|
|
|
|
catch(Exception $e)
|
|
|
|
{
|
|
|
|
throw new StandardException('Failed to set password due to an internal exception', StandardError::INTERNAL_SERVER_ERROR, $e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $rpcRequest->produceResponse(true);
|
|
|
|
}
|
|
|
|
}
|