Merge pull request 'force-action-on-important-notifications' (#1176) from force-action-on-important-notifications into staging
Reviewed-on: #1176
This commit was merged in pull request #1176.
This commit is contained in:
@@ -26,6 +26,22 @@ impl Notification {
|
||||
.await
|
||||
.ok()
|
||||
}
|
||||
|
||||
pub async fn oldest_unread_with_action(db: &SqlitePool, user_id: i64) -> Option<Self> {
|
||||
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,
|
||||
|
||||
@@ -88,17 +88,20 @@ pub struct UserWithDetails {
|
||||
pub allowed_to_steer: bool,
|
||||
pub on_water: bool,
|
||||
pub roles: Vec<String>,
|
||||
pub action_notification: Option<Notification>,
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,21 @@
|
||||
{% include "includes/footer" %}
|
||||
{% endif %}
|
||||
{% include "dynamics/sidebar" %}
|
||||
{% if loggedin_user and loggedin_user.action_notification %}
|
||||
<dialog id="action-notification-modal" class="max-w-screen-sm dark:bg-primary-600 dark:text-white rounded-md">
|
||||
<div class="p-4">
|
||||
<small class="text-gray-600 dark:text-gray-100">
|
||||
<strong>{{ loggedin_user.action_notification.category }}</strong>
|
||||
</small>
|
||||
<div class="my-4">{{ loggedin_user.action_notification.message }}</div>
|
||||
<a href="/notification/{{ loggedin_user.action_notification.id }}/read" class="btn btn-dark w-full mt-3">
|
||||
✓
|
||||
<span class="sr-only">Notification gelesen</span>
|
||||
</a>
|
||||
</div>
|
||||
</dialog>
|
||||
<script>document.getElementById('action-notification-modal').showModal();</script>
|
||||
{% endif %}
|
||||
<script src="/public/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user