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