aboutsummaryrefslogtreecommitdiffhomepage
path: root/routes/actor_profile_fragment.php
blob: 9b864d9c785cddd5201f0c1c50294a2400083ea8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php

use Digitigrade\Model\Actor;
use Digitigrade\Model\UserAccount;
use Digitigrade\Router;

Router::getInstance()->mount('/fragment/actor/:id/followButton', function (array $args) {
    $user = UserAccount::requireByCurrentSession();
    $actor = Actor::find($args['id']);

    if ($user->actor->follows($actor)) {
        // already following, therefore unfollow
        $user->actor->unfollow($actor);
    } elseif ($user->actor->followsPending($actor)) {
        // can't actually do anything at this point
        // TODO: cancel request? is this possible?? do i need to modify the protocol
    } else {
        // follow
        $user->actor->follow($actor);
    }

    render_template('actor_profile_follow_button', ['user' => $user, 'actor' => $actor]);
});