diff options
Diffstat (limited to 'routes')
| -rw-r--r-- | routes/note_fragment.php | 3 | ||||
| -rw-r--r-- | routes/public_timelines.php | 15 | ||||
| -rw-r--r-- | routes/timelines.php | 48 |
3 files changed, 51 insertions, 15 deletions
diff --git a/routes/note_fragment.php b/routes/note_fragment.php index a992a61..4d8c1a6 100644 --- a/routes/note_fragment.php +++ b/routes/note_fragment.php @@ -22,6 +22,7 @@ Router::getInstance()->mount('/fragment/note/:id/:action', function (array $args // we are adding a new interaction $interaction = Interaction::create($user->actor, InteractionKind::from($action), $note); $interaction->publish(); + $interaction->processTimelineAdditions(); $active = true; } else { // we are removing the existing one @@ -47,6 +48,7 @@ Router::getInstance()->mount('/fragment/note/:id/reply', function (array $args) $reply->threadApex = $note->threadApex ?? $note; $reply->save(); $reply->publish(); + $reply->processTimelineAdditions(); } render_template('reply_form', ['note' => $note]); }); @@ -58,6 +60,7 @@ Router::getInstance()->mount('/fragment/note', function (array $args) { // TODO: summary field, post language, privacy, etc $note = Note::create($author->actor, $_POST['content'], 'unk'); $note->publish(); + $note->processTimelineAdditions(); } render_template('write_note_form'); });
\ No newline at end of file diff --git a/routes/public_timelines.php b/routes/public_timelines.php deleted file mode 100644 index b60f141..0000000 --- a/routes/public_timelines.php +++ /dev/null @@ -1,15 +0,0 @@ -<?php - -use Digitigrade\Router; -use Digitigrade\Timeline\GlobalTimeline; -use Digitigrade\Timeline\LocalTimeline; - -Router::getInstance()->mount('/feed/global', function (array $args) { - $items = (new GlobalTimeline())->getPage(); - render_template('timeline', ['kind' => 'global', 'items' => $items]); -}); - -Router::getInstance()->mount('/feed/local', function (array $args) { - $items = (new LocalTimeline())->getPage(); - render_template('timeline', ['kind' => 'local', 'items' => $items]); -});
\ No newline at end of file diff --git a/routes/timelines.php b/routes/timelines.php new file mode 100644 index 0000000..f70c0d6 --- /dev/null +++ b/routes/timelines.php @@ -0,0 +1,48 @@ +<?php + +use Digitigrade\HttpResponseStatus\BadRequest; +use Digitigrade\HttpResponseStatus\TemporaryRedirect; +use Digitigrade\Model\UserAccount; +use Digitigrade\Router; +use Digitigrade\Timeline\GlobalTimeline; +use Digitigrade\Timeline\HomeTimeline; +use Digitigrade\Timeline\LocalTimeline; + +Router::getInstance()->mount('/feed/global', function (array $args) { + $items = (new GlobalTimeline())->getPage(); + render_template('timeline', ['kind' => 'global', 'items' => $items]); +}); + +Router::getInstance()->mount('/feed/local', function (array $args) { + $items = (new LocalTimeline())->getPage(); + render_template('timeline', ['kind' => 'local', 'items' => $items]); +}); + +Router::getInstance()->mount('/feed/home', function (array $args) { + $user = UserAccount::findByCurrentSession(); + if ($user == null) { + throw new TemporaryRedirect('/feed/global'); + } + $items = (new HomeTimeline($user))->getPage(); + render_template('timeline', ['kind' => 'home', 'items' => $items]); +}); + +Router::getInstance()->mount('/feed/home/partial', function (array $args) { + $user = UserAccount::requireByCurrentSession(); + if (!isset($_GET['since'])) { + throw new BadRequest('get parameter `since` required'); + } + $when = new \DateTimeImmutable($_GET['since']); + $items = (new HomeTimeline($user))->getItemsSince($when); + + foreach ($items as $item) { + $item->getReason()?->renderAsHtml(); + $item->getObject()->renderAsHtml(); + } + + render_template('live_timeline_updater', [ + 'kind' => 'home', + 'isUpdate' => true, + 'since' => new \DateTimeImmutable() + ]); +});
\ No newline at end of file |
