From 454dd25681af9de9e08ddc021eb29c25ec1ab2f8 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 30 Apr 2021 07:49:34 -0700 Subject: [PATCH 1/3] Only make notification count red for mentions --- bookwyrm/models/user.py | 13 +++++++++++++ bookwyrm/static/js/bookwyrm.js | 2 ++ bookwyrm/templates/layout.html | 7 +++++-- bookwyrm/views/updates.py | 3 ++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index 3efbd6ac..25726468 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -150,6 +150,19 @@ class User(OrderedCollectionPageMixin, AbstractUser): """for consistent naming""" return not self.is_active + @property + def unread_notification_count(self): + """ count of notifications, for the templates """ + return self.notification_set.filter(read=False).count() + + @property + def has_unread_mentions(self): + """ whether any of the unread notifications are conversations """ + return self.notification_set.filter( + read=False, + notification_type__in=["REPLY", "MENTION", "TAG"], + ).exists() + activity_serializer = activitypub.Person @classmethod diff --git a/bookwyrm/static/js/bookwyrm.js b/bookwyrm/static/js/bookwyrm.js index 485daf15..3659a20e 100644 --- a/bookwyrm/static/js/bookwyrm.js +++ b/bookwyrm/static/js/bookwyrm.js @@ -97,10 +97,12 @@ let BookWyrm = new class { updateCountElement(counter, data) { const currentCount = counter.innerText; const count = data.count; + const hasMentions = data.has_mentions; if (count != currentCount) { this.addRemoveClass(counter.closest('[data-poll-wrapper]'), 'is-hidden', count < 1); counter.innerText = count; + this.addRemoveClass(counter.closest('[data-poll-wrapper]'), 'is-danger', hasMentions); } } diff --git a/bookwyrm/templates/layout.html b/bookwyrm/templates/layout.html index 84482cdf..770666e8 100644 --- a/bookwyrm/templates/layout.html +++ b/bookwyrm/templates/layout.html @@ -135,8 +135,11 @@ {% trans "Notifications" %} - - {{ request.user | notification_count }} + + {{ request.user.unread_notification_count }} diff --git a/bookwyrm/views/updates.py b/bookwyrm/views/updates.py index 34902272..72614562 100644 --- a/bookwyrm/views/updates.py +++ b/bookwyrm/views/updates.py @@ -10,7 +10,8 @@ def get_notification_count(request): """any notifications waiting?""" return JsonResponse( { - "count": request.user.notification_set.filter(read=False).count(), + "count": request.user.unread_notification_count, + "has_mentions": request.user.has_unread_mentions, } ) From 2867d703ccc32dada6f9e85c815e3c04354a9788 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 30 Apr 2021 07:57:38 -0700 Subject: [PATCH 2/3] Fixes python formatting --- bookwyrm/models/user.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index 25726468..2c5bef4a 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -152,12 +152,12 @@ class User(OrderedCollectionPageMixin, AbstractUser): @property def unread_notification_count(self): - """ count of notifications, for the templates """ + """count of notifications, for the templates""" return self.notification_set.filter(read=False).count() @property def has_unread_mentions(self): - """ whether any of the unread notifications are conversations """ + """whether any of the unread notifications are conversations""" return self.notification_set.filter( read=False, notification_type__in=["REPLY", "MENTION", "TAG"], From c373a0b818dfea5ebe8a7aa1e9ce1c409c68bf3d Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 30 Apr 2021 13:38:03 -0700 Subject: [PATCH 3/3] Highlight report notifications --- bookwyrm/models/user.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index 2c5bef4a..7c943bec 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -160,7 +160,7 @@ class User(OrderedCollectionPageMixin, AbstractUser): """whether any of the unread notifications are conversations""" return self.notification_set.filter( read=False, - notification_type__in=["REPLY", "MENTION", "TAG"], + notification_type__in=["REPLY", "MENTION", "TAG", "REPORT"], ).exists() activity_serializer = activitypub.Person