Mark the browser tab with a red dot when new articles arrive (#31)

The in-page "new articles" banner is invisible from a background tab.
Every authenticated page now polls a small JSON endpoint
(reader:new_since, every 30s) and redraws the tab's favicon with a red
dot when unread, non-hidden articles from the user's feeds have
appeared since the page loaded. A reload (which is what clicking the
banner does) resets the baseline and the icon.

The endpoint is deliberately not scoped to the stream's current
filter/tag/feed, so the tab lights up for anything new whichever page
is open. Scope is the dot only: no desktop notifications, per the
request. Verified in a dev server enforcing the production CSP: the
icon swapped to the dotted version after a new article arrived and
reset on reload.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ksmithandClaude Sonnet 5.5 committed 2026-11-01 10:18:29 -07:00
1 parent fd494a9c08
commit 0975a7634b
5 files changed
+162 -1

No files matched your search

+24 -1
View File
@@ -5,7 +5,7 @@ from urllib.parse import urlencode
from django.contrib.auth.decorators import login_required
from django.db.models import Max, Q
from django.db.models.functions import Coalesce
from django.http import Http404
from django.http import Http404, JsonResponse
from django.shortcuts import get_object_or_404, redirect, render
from django.urls import reverse
from django.utils import timezone
@@ -258,6 +258,29 @@ def check_new_articles(request):
return render(request, "reader/_new_articles_banner.html", {"new_count": new_count})
@login_required
def new_since(request):
"""Feeds the browser-tab dot (static/js/tab-badge.js) on every page:
without ?since it returns the current highest article id, which the
page keeps as its baseline; with it, how many unread, non-hidden
articles from the user's subscriptions have appeared after that id.
Deliberately not scoped to the stream's current filter/tag/feed — the
tab should light up for anything new, whichever page is open."""
latest_id = Article.objects.aggregate(Max("id"))["id__max"] or 0
try:
since_id = int(request.GET["since"])
except (KeyError, ValueError):
return JsonResponse({"latest_id": latest_id, "new_count": 0})
new_count = (
_base_queryset(request.user)
.filter(id__gt=since_id)
.exclude(user_states__user=request.user, user_states__is_read=True)
.count()
)
return JsonResponse({"latest_id": latest_id, "new_count": new_count})
@login_required
@require_POST
def mark_all_read(request):