From 8c6dad8c48d5d730b102d9de0079fee9752b0d35 Mon Sep 17 00:00:00 2001 From: winter Date: Sun, 19 Jan 2025 22:17:12 +0000 Subject: implement notifications --- routes/note_fragment.php | 5 +++++ routes/notifications.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 routes/notifications.php (limited to 'routes') diff --git a/routes/note_fragment.php b/routes/note_fragment.php index 84f68c6..5fe979a 100644 --- a/routes/note_fragment.php +++ b/routes/note_fragment.php @@ -24,6 +24,7 @@ Router::getInstance()->mount('/fragment/note/:id/:action', function (array $args $interaction = Interaction::create($user->actor, InteractionKind::from($action), $note); $interaction->publish(); $interaction->processTimelineAdditions(); + $interaction->processNotifications(); $active = true; } else { // we are removing the existing one @@ -55,9 +56,12 @@ Router::getInstance()->mount('/fragment/note/:id/reply', function (array $args) ); $reply->inReplyTo = $note; $reply->threadApex = $note->threadApex ?? $note; + // TODO: do mentions properly and not just like this + $reply->mentions = [$note->author]; $reply->save(); $reply->publish(); $reply->processTimelineAdditions(); + $reply->processNotifications(); } render_template('reply_form', ['note' => $note]); }); @@ -78,6 +82,7 @@ Router::getInstance()->mount('/fragment/note', function (array $args) { ); $note->publish(); $note->processTimelineAdditions(); + $note->processNotifications(); } render_template('write_note_form'); }); \ No newline at end of file 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 @@ +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 -- cgit v1.3