From 0ccd59f8a76d22993af335c31fb1885558b45647 Mon Sep 17 00:00:00 2001 From: Philipp Hofer Date: Sat, 3 Jan 2026 22:11:11 +0100 Subject: [PATCH] force an action on important notifications --- src/model/notification.rs | 16 ++++++++++++++++ src/model/user/mod.rs | 3 +++ templates/base.html.tera | 15 +++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/src/model/notification.rs b/src/model/notification.rs index cf7b893..253db16 100644 --- a/src/model/notification.rs +++ b/src/model/notification.rs @@ -26,6 +26,22 @@ impl Notification { .await .ok() } + + pub async fn oldest_unread_with_action(db: &SqlitePool, user_id: i64) -> Option { + sqlx::query_as!( + Self, + "SELECT id, user_id, message, read_at, created_at, category, link, action_after_reading + FROM notification + WHERE user_id = ? AND read_at IS NULL AND action_after_reading IS NOT NULL + ORDER BY created_at ASC + LIMIT 1", + user_id + ) + .fetch_optional(db) + .await + .unwrap() + } + pub async fn create_with_tx( db: &mut Transaction<'_, Sqlite>, user: &User, diff --git a/src/model/user/mod.rs b/src/model/user/mod.rs index 7c38a31..2cd1fed 100644 --- a/src/model/user/mod.rs +++ b/src/model/user/mod.rs @@ -88,17 +88,20 @@ pub struct UserWithDetails { pub allowed_to_steer: bool, pub on_water: bool, pub roles: Vec, + pub action_notification: Option, } impl UserWithDetails { pub async fn from_user(user: User, db: &SqlitePool) -> Self { let allowed_to_steer = user.allowed_to_steer(db).await; + let action_notification = Notification::oldest_unread_with_action(db, user.id).await; Self { on_water: user.on_water(db).await, roles: user.roles(db).await, amount_unread_notifications: user.amount_unread_notifications(db).await, allowed_to_steer, + action_notification, user, } } diff --git a/templates/base.html.tera b/templates/base.html.tera index f3c4303..79cacce 100644 --- a/templates/base.html.tera +++ b/templates/base.html.tera @@ -53,6 +53,21 @@ {% include "includes/footer" %} {% endif %} {% include "dynamics/sidebar" %} + {% if loggedin_user and loggedin_user.action_notification %} + +
+ + {{ loggedin_user.action_notification.category }} + +
{{ loggedin_user.action_notification.message }}
+ + ✓ + Notification gelesen + +
+
+ + {% endif %}