diff options
| author | winter | 2025-01-19 22:17:12 +0000 |
|---|---|---|
| committer | winter | 2025-01-19 22:17:12 +0000 |
| commit | 8c6dad8c48d5d730b102d9de0079fee9752b0d35 (patch) | |
| tree | 2cfe07a8c7958f78c767fd0d1444c3f8fef70511 /routes/notifications.php | |
| parent | 2d9bd87fb1c565ee161f93219ce2533e8dbffe06 (diff) | |
implement notifications
Diffstat (limited to 'routes/notifications.php')
| -rw-r--r-- | routes/notifications.php | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/routes/notifications.php b/routes/notifications.php new file mode 100644 index 0000000..05fb89d --- /dev/null +++ b/routes/notifications.php @@ -0,0 +1,31 @@ +<?php + +use Digitigrade\HttpResponseStatus\BadRequest; +use Digitigrade\Model\Notification; +use Digitigrade\Model\UserAccount; +use Digitigrade\Router; + +Router::getInstance()->mount('/notifications/partial', function (array $args) { + $user = UserAccount::requireByCurrentSession(); + if (!isset($_GET['since'])) { + throw new BadRequest('get parameter `since` required'); + } + $when = new \DateTimeImmutable($_GET['since']); + $notifs = Notification::findAllForUser($user, since: $when); + + foreach ($notifs as $notif) { + $notif = $notif->toNotifyable(); + render_template('notification', [ + 'title' => $notif->getNotificationTitle(), + 'body' => $notif->getNotificationBody(), + 'imageUrl' => $notif->getNotificationImageUrl(), + 'titleLink' => $notif->getNotificationTitleLink(), + 'imageLink' => $notif->getNotificationImageLink() + ]); + } + + render_template('live_notifications_updater', [ + 'isUpdate' => true, + 'since' => new \DateTimeImmutable() + ]); +});
\ No newline at end of file |
