2021-04-02 17:20:02 +00:00
|
|
|
<?php
|
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2021-04-02 17:20:02 +00:00
|
|
|
/**
|
2022-02-19 16:06:11 +00:00
|
|
|
* @copyright 2020 Ad Aures
|
2021-04-02 17:20:02 +00:00
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
2022-01-04 15:40:27 +00:00
|
|
|
use App\Models\ActorModel;
|
2021-08-23 11:05:16 +00:00
|
|
|
use Modules\Auth\Entities\User;
|
|
|
|
use Modules\Fediverse\Entities\Actor;
|
2021-04-02 17:20:02 +00:00
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! function_exists('user')) {
|
2021-05-12 14:00:25 +00:00
|
|
|
/**
|
|
|
|
* Returns the User instance for the current logged in user.
|
|
|
|
*/
|
|
|
|
function user(): ?User
|
|
|
|
{
|
2021-08-23 11:05:16 +00:00
|
|
|
$authenticate = service('authentication');
|
2021-05-12 14:00:25 +00:00
|
|
|
$authenticate->check();
|
|
|
|
return $authenticate->user();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! function_exists('set_interact_as_actor')) {
|
2021-04-02 17:20:02 +00:00
|
|
|
/**
|
|
|
|
* Sets the actor id of which the user is acting as
|
|
|
|
*/
|
2021-05-14 17:59:35 +00:00
|
|
|
function set_interact_as_actor(int $actorId): void
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
2021-08-23 11:05:16 +00:00
|
|
|
$authenticate = service('authentication');
|
2021-04-02 17:20:02 +00:00
|
|
|
$authenticate->check();
|
|
|
|
|
|
|
|
$session = session();
|
|
|
|
$session->set('interact_as_actor_id', $actorId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! function_exists('remove_interact_as_actor')) {
|
2021-04-02 17:20:02 +00:00
|
|
|
/**
|
|
|
|
* Removes the actor id of which the user is acting as
|
|
|
|
*/
|
2021-05-06 14:00:48 +00:00
|
|
|
function remove_interact_as_actor(): void
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
|
|
|
$session = session();
|
|
|
|
$session->remove('interact_as_actor_id');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! function_exists('interact_as_actor_id')) {
|
2021-04-02 17:20:02 +00:00
|
|
|
/**
|
|
|
|
* Sets the podcast id of which the user is acting as
|
|
|
|
*/
|
2021-05-06 14:00:48 +00:00
|
|
|
function interact_as_actor_id(): int
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
2021-08-23 11:05:16 +00:00
|
|
|
$authenticate = service('authentication');
|
2021-04-02 17:20:02 +00:00
|
|
|
$authenticate->check();
|
|
|
|
|
|
|
|
$session = session();
|
|
|
|
return $session->get('interact_as_actor_id');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! function_exists('interact_as_actor')) {
|
2021-04-02 17:20:02 +00:00
|
|
|
/**
|
|
|
|
* Get the actor the user is currently interacting as
|
|
|
|
*/
|
2021-05-19 16:35:13 +00:00
|
|
|
function interact_as_actor(): Actor | false
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
2021-08-23 11:05:16 +00:00
|
|
|
$authenticate = service('authentication');
|
2021-04-02 17:20:02 +00:00
|
|
|
$authenticate->check();
|
|
|
|
|
|
|
|
$session = session();
|
|
|
|
if ($session->has('interact_as_actor_id')) {
|
2022-02-05 11:40:30 +00:00
|
|
|
return model(ActorModel::class, false)->getActorById($session->get('interact_as_actor_id'));
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! function_exists('can_user_interact')) {
|
2021-05-06 14:00:48 +00:00
|
|
|
function can_user_interact(): bool
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
2021-05-06 14:00:48 +00:00
|
|
|
return (bool) interact_as_actor();
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
}
|