diff options
| author | winter | 2025-01-26 19:47:22 +0000 |
|---|---|---|
| committer | winter | 2025-01-26 19:47:22 +0000 |
| commit | 7d3f35b1895dd3fe08af0f5fe403ff339acd2456 (patch) | |
| tree | 26c59b9b18793f9678cc115420762aa7695c2071 | |
| parent | df5ead7bd4adac405811b91fed1e5f0b3775206b (diff) | |
send desktop notifications
| -rw-r--r-- | Digitigrade/Model/Interaction.php | 2 | ||||
| -rw-r--r-- | Digitigrade/Model/Note.php | 2 | ||||
| -rw-r--r-- | routes/notifications.php | 3 | ||||
| -rw-r--r-- | templates/head_tags.php | 1 | ||||
| -rw-r--r-- | templates/notification.php | 11 | ||||
| -rw-r--r-- | templates/notifications_panel.php | 3 |
6 files changed, 18 insertions, 4 deletions
diff --git a/Digitigrade/Model/Interaction.php b/Digitigrade/Model/Interaction.php index 883bf6c..902dbc0 100644 --- a/Digitigrade/Model/Interaction.php +++ b/Digitigrade/Model/Interaction.php @@ -69,7 +69,7 @@ class Interaction extends PushableModel implements Notifyable { return '/@/' . $this->target->author->getFullHandle() . '/note/' . $this->target->id; } public function getNotificationBody(): ?string { - return $this->target->plainContent; + return isset($this->target->summary) ? ('[' . $this->target->summary . ']') : $this->target->plainContent; } public function getNotificationImageUrl(): ?string { return $this->author->avatar ?? '/static/default-avatar.png'; diff --git a/Digitigrade/Model/Note.php b/Digitigrade/Model/Note.php index 017cd3e..7da6d8e 100644 --- a/Digitigrade/Model/Note.php +++ b/Digitigrade/Model/Note.php @@ -204,7 +204,7 @@ class Note extends PushableModel implements TimelineIncludeable, Notifyable { return '/@/' . $this->author->getFullHandle() . '/note/' . $this->id; } public function getNotificationBody(): ?string { - return $this->plainContent; + return isset($this->summary) ? "[$this->summary]" : $this->plainContent; } public function getNotificationImageUrl(): ?string { return $this->author->avatar ?? '/static/default-avatar.png'; diff --git a/routes/notifications.php b/routes/notifications.php index c7b9414..11a73fb 100644 --- a/routes/notifications.php +++ b/routes/notifications.php @@ -22,7 +22,8 @@ Router::getInstance()->mount('/notifications/partial', function (array $args) { 'body' => $notif->getNotificationBody(), 'imageUrl' => $notif->getNotificationImageUrl(), 'titleLink' => $notif->getNotificationTitleLink(), - 'imageLink' => $notif->getNotificationImageLink() + 'imageLink' => $notif->getNotificationImageLink(), + 'unread' => true ]); } diff --git a/templates/head_tags.php b/templates/head_tags.php index 88ac6ff..47fcef0 100644 --- a/templates/head_tags.php +++ b/templates/head_tags.php @@ -1,6 +1,7 @@ <link rel="stylesheet" href="/static/style.css"> <link rel="stylesheet" href="https://fonts.bunny.net/css?family=dm-sans:400,400i,800,800i"> <meta name="viewport" content="width=device-width, initial-scale=1"> +<meta name="theme-color" content="#3b005e"> <script src="https://unpkg.com/htmx.org@2.0.4"></script> <script src="https://unpkg.com/hyperscript.org@0.9.13"></script> <script src="/static/language-switch.js" defer></script>
\ No newline at end of file diff --git a/templates/notification.php b/templates/notification.php index a010ff9..a23a3a6 100644 --- a/templates/notification.php +++ b/templates/notification.php @@ -20,4 +20,15 @@ <?php endif; ?> <span class="body"><?= htmlspecialchars($body) ?></span> </div> + <div hidden class="notifier" <?php if ($unread): ?> _=" + on load + set title to innerText of previous .title + set body to innerText of previous .body + set icon to @src of previous <img/> + set titleLink to previous <a/> + js(title, body, icon, titleLink) + let n = new Notification(title, { body: body, icon: icon }) + n.addEventListener('click', () => titleLink.click()) + end + " <?php endif; ?>></div> </div>
\ No newline at end of file diff --git a/templates/notifications_panel.php b/templates/notifications_panel.php index 98a04e3..574a295 100644 --- a/templates/notifications_panel.php +++ b/templates/notifications_panel.php @@ -3,7 +3,8 @@ use Digitigrade\Model\Notification; $notifications = Notification::findAllForUser($user, 50); ?> -<div id="notificationsPanel"> +<div id="notificationsPanel" + _="on load js if (Notification.permission == 'default') Notification.requestPermission() end"> <h2><?= __('notifications.heading') ?></h2> <?php call_template('live_notifications_updater', ['since' => new \DateTimeImmutable()]); ?> <div class="items"> |
