aboutsummaryrefslogtreecommitdiffhomepage
path: root/routes/actor.php
blob: 51c0e1a1bda65c6dd783edf85b8a8b8ede9f6699 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php

use Digitigrade\HttpResponseStatus\NotFound;
use Digitigrade\HttpResponseStatus\TemporaryRedirect;
use Digitigrade\Model\Actor;
use Digitigrade\Model\Note;
use Digitigrade\Router;

Router::getInstance()->mount('/user/:handle', function (array $args) {
    $actor = Actor::findLocalByHandle($args['handle']);
    if ($actor == null) {
        throw new NotFound("i don't know any local user called " . $args['handle']);
    }
    if (str_contains($_SERVER['HTTP_ACCEPT'], 'text/html')) {
        throw new TemporaryRedirect(path_to_uri("/@/$actor->handle"));
    }
    json_response($actor);
});

Router::getInstance()->mount('/user/:handle/basicFeed', function (array $args) {
    $actor = Actor::findLocalByHandle($args['handle']);
    $notes = Note::findAllWithAuthor($actor);
    // TODO: implement pagination
    json_response([
        'page' => 1,
        'totalPages' => 1,
        'nextPage' => null,
        'previousPage' => null,
        'items' => array_map(function (Note $note) {
            return $note->uri;
        }, $notes)
    ]);
});

Router::getInstance()->mount('/user/:handle/fullFeed', function (array $args) {
    $actor = Actor::findLocalByHandle($args['handle']);
    $notes = Note::findAllWithAuthor($actor);
    // TODO: implement pagination here as well
    json_response([
        'page' => 1,
        'totalPages' => 1,
        'nextPage' => null,
        'previousPage' => null,
        'items' => $notes
    ]);
});