diff --git a/src/model/notification.rs b/src/model/notification.rs index 4a3d274b..b7dce964 100644 --- a/src/model/notification.rs +++ b/src/model/notification.rs @@ -194,6 +194,15 @@ ORDER BY read_at DESC, created_at DESC; } } } + + pub(crate) async fn mark_all_read(db: &SqlitePool, user: &User) { + let notifications = Self::for_user(db, user).await; + + for notification in notifications { + notification.mark_read(db).await; + } + } + pub(crate) async fn delete_by_action(db: &sqlx::Pool, action: &str) { sqlx::query!( "DELETE FROM notification WHERE action_after_reading=? and read_at is null", diff --git a/src/tera/notification.rs b/src/tera/notification.rs index da59cccc..e7c0069b 100644 --- a/src/tera/notification.rs +++ b/src/tera/notification.rs @@ -27,6 +27,12 @@ async fn mark_read(db: &State, user: User, notification_id: i64) -> } } -pub fn routes() -> Vec { - routes![mark_read] +#[get("/read/all")] +async fn mark_all_read(db: &State, user: User) -> Flash { + Notification::mark_all_read(db, &user).await; + Flash::success(Redirect::to("/"), "Alle Nachrichten als gelesen markiert") +} + +pub fn routes() -> Vec { + routes![mark_read, mark_all_read] } diff --git a/templates/index.html.tera b/templates/index.html.tera index 573166fc..4e57bd53 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -32,7 +32,7 @@

Nachrichten

{% if loggedin_user.amount_unread_notifications > 10 %}
- Du hast viele ungelesene Benachrichtigungen. Um deine Oberfläche übersichtlich zu halten und wichtige Updates nicht zu verpassen, nimm dir bitte einen Moment Zeit sie zu überprüfen und als gelesen zu markieren (✓). + Du hast viele ungelesene Benachrichtigungen. Um deine Oberfläche übersichtlich zu halten und wichtige Updates nicht zu verpassen, nimm dir bitte in Zukunft einen kurzen Moment Zeit sie zu überprüfen und als gelesen zu markieren (✓).
Du kannst hier ausnahmsweise alle als gelesen markieren.
{% endif %}