From fa8564350ada258d7914f0c57d4e18ee3cde5979 Mon Sep 17 00:00:00 2001
From: Jonathan Weth <git@jonathanweth.de>
Date: Sun, 27 Mar 2022 11:21:20 +0200
Subject: [PATCH] Show scheduled notifications on dashboard not before time

---
 CHANGELOG.rst          | 1 +
 aleksis/core/models.py | 2 +-
 aleksis/core/views.py  | 4 +++-
 3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 8cb401a23..6be885dbe 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -23,6 +23,7 @@ Fixed
   * Added locales-all to base image and note to docs
 * The icons in the account menu were still the old ones.
 * Due to a merge error, the once removed account menu in the sidenav appeared again.
+* Scheduled notifications were shown on dashboard before time.
 
 Changed
 ~~~~~~~
diff --git a/aleksis/core/models.py b/aleksis/core/models.py
index 7c555b409..754c4fea9 100644
--- a/aleksis/core/models.py
+++ b/aleksis/core/models.py
@@ -309,7 +309,7 @@ class Person(ExtensibleModel):
     @property
     def unread_notifications(self) -> QuerySet:
         """Get all unread notifications for this person."""
-        return self.notifications.filter(read=False)
+        return self.notifications.filter(read=False, send_at__lte=timezone.now())
 
     @property
     def unread_notifications_count(self) -> int:
diff --git a/aleksis/core/views.py b/aleksis/core/views.py
index 32e83c374..cb5a9169c 100644
--- a/aleksis/core/views.py
+++ b/aleksis/core/views.py
@@ -219,7 +219,9 @@ def index(request: HttpRequest) -> HttpResponse:
     notifications = person.notifications.filter(send_at__lte=timezone.now()).order_by("-created")[
         :5
     ]
-    unread_notifications = person.notifications.all().filter(read=False).order_by("-created")
+    unread_notifications = person.notifications.filter(
+        send_at__lte=timezone.now(), read=False
+    ).order_by("-created")
 
     context["activities"] = activities
     context["notifications"] = notifications
-- 
GitLab