diff --git a/bookwyrm/activitystreams.py b/bookwyrm/activitystreams.py
index c1c548d2..1c8f78be 100644
--- a/bookwyrm/activitystreams.py
+++ b/bookwyrm/activitystreams.py
@@ -70,6 +70,10 @@ class ActivityStream(ABC):
.order_by("-published_date")
)
+ def get_unread_count(self, user):
+ """ get the unread status count for this user's feed """
+ return int(r.get(self.unread_id(user)))
+
def populate_stream(self, user):
""" go from zero to a timeline """
pipeline = r.pipeline()
diff --git a/bookwyrm/static/js/shared.js b/bookwyrm/static/js/shared.js
index d390f482..1f26aba6 100644
--- a/bookwyrm/static/js/shared.js
+++ b/bookwyrm/static/js/shared.js
@@ -61,9 +61,9 @@ function polling(el, delay) {
function updateCountElement(el, data) {
const currentCount = el.innerText;
- const count = data[el.getAttribute('data-poll')];
+ const count = data.count;
if (count != currentCount) {
- addRemoveClass(el, 'hidden', count < 1);
+ addRemoveClass(el.closest('[data-poll-wrapper]'), 'hidden', count < 1);
el.innerText = count;
}
}
diff --git a/bookwyrm/templates/feed/feed.html b/bookwyrm/templates/feed/feed.html
index 5ad18db6..77b593fe 100644
--- a/bookwyrm/templates/feed/feed.html
+++ b/bookwyrm/templates/feed/feed.html
@@ -26,6 +26,10 @@
+
+ {% blocktrans %}load 0 unread status(es){% endblocktrans %}
+
+
{# announcements and system messages #}
{% if request.user.show_goal and not goal and tab == 'home' %}
{% now 'Y' as year %}
diff --git a/bookwyrm/templates/layout.html b/bookwyrm/templates/layout.html
index e57f6152..d08b1820 100644
--- a/bookwyrm/templates/layout.html
+++ b/bookwyrm/templates/layout.html
@@ -139,8 +139,8 @@
{% trans "Notifications" %}
-
- {{ request.user | notification_count }}
+
+ {{ request.user | notification_count }}
diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py
index 76622799..44db6892 100644
--- a/bookwyrm/urls.py
+++ b/bookwyrm/urls.py
@@ -37,7 +37,8 @@ urlpatterns = [
re_path(r"^api/v1/instance/?$", views.instance_info),
re_path(r"^api/v1/instance/peers/?$", views.peers),
# polling updates
- re_path("^api/updates/notifications/?$", views.Updates.as_view()),
+ re_path("^api/updates/notifications/?$", views.get_notification_count),
+ re_path("^api/updates/stream/(?P[a-z]+)/?$", views.get_unread_status_count),
# authentication
re_path(r"^login/?$", views.Login.as_view()),
re_path(r"^register/?$", views.Register.as_view()),
diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py
index f1ebfc4c..3439304f 100644
--- a/bookwyrm/views/__init__.py
+++ b/bookwyrm/views/__init__.py
@@ -33,6 +33,6 @@ from .shelf import shelve, unshelve
from .site import Site
from .status import CreateStatus, DeleteStatus
from .tag import Tag, AddTag, RemoveTag
-from .updates import Updates
+from .updates import get_notification_count, get_unread_status_count
from .user import User, EditUser, Followers, Following
from .wellknown import webfinger, nodeinfo_pointer, nodeinfo, instance_info, peers
diff --git a/bookwyrm/views/updates.py b/bookwyrm/views/updates.py
index 83b680c0..5bcb26b9 100644
--- a/bookwyrm/views/updates.py
+++ b/bookwyrm/views/updates.py
@@ -1,20 +1,24 @@
""" endpoints for getting updates about activity """
from django.contrib.auth.decorators import login_required
from django.http import JsonResponse
-from django.utils.decorators import method_decorator
-from django.views import View
-# pylint: disable= no-self-use
-@method_decorator(login_required, name="dispatch")
-class Updates(View):
- """ so the app can poll """
+from bookwyrm import activitystreams
- def get(self, request):
- """ any notifications waiting? """
- return JsonResponse(
- {
- "notifications": request.user.notification_set.filter(
- read=False
- ).count(),
- }
- )
+@login_required
+def get_notification_count(request):
+ """ any notifications waiting? """
+ return JsonResponse({
+ "count": request.user.notification_set.filter(
+ read=False
+ ).count(),
+ })
+
+@login_required
+def get_unread_status_count(request, stream):
+ """ any unread statuses for this feed? """
+ stream = activitystreams.streams.get(stream)
+ if not stream:
+ return JsonResponse({})
+ return JsonResponse({
+ "count": stream.get_unread_count(request.user)
+ })