Private
Public Access
Notify the open stream when new articles arrive
The stream had no way to learn about articles the background poll ingested while the page was open — only a manual reload or navigation ever picked them up. Adds a lightweight "N new articles — click to show" banner: the stream records the highest article id in its current scope (filter/tag/feed) when rendered, and an htmx poll every 30s checks reader:check_new for anything newer in that same scope. It never swaps the list out from under you mid-read — clicking the banner is what actually reloads it. id, not published_at, is the cursor, since a feed can backdate an entry's published date below everything currently on screen while it's still genuinely new to this stream. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
17e7f63e61
commit
03dd37e69d
6 files changed
+139
-4
No files matched your search
@@ -217,3 +217,75 @@ def test_article_rows_carry_their_utc_instant_for_client_side_date_grouping(clie
|
||||
undated_row = re.search(rf'<li id="article-{undated.pk}".*?>', content, flags=re.DOTALL)
|
||||
assert undated_row is not None
|
||||
assert 'data-published-utc=""' in undated_row.group(0)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_check_new_articles_reports_nothing_below_the_given_cursor(client, alice):
|
||||
feed = Feed.objects.create(feed_url="https://example.com/feed.xml")
|
||||
Subscription.objects.create(user=alice, feed=feed)
|
||||
existing = Article.objects.create(feed=feed, guid="existing", title="Existing")
|
||||
|
||||
client.login(username="alice", password="pw-alice-123")
|
||||
response = client.get(reverse("reader:check_new"), {"filter": "all", "since": existing.pk})
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.content.decode().strip() == ""
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_check_new_articles_reports_articles_created_after_the_cursor(client, alice):
|
||||
feed = Feed.objects.create(feed_url="https://example.com/feed.xml")
|
||||
Subscription.objects.create(user=alice, feed=feed)
|
||||
existing = Article.objects.create(feed=feed, guid="existing", title="Existing")
|
||||
Article.objects.create(feed=feed, guid="new-1", title="New one")
|
||||
|
||||
client.login(username="alice", password="pw-alice-123")
|
||||
response = client.get(reverse("reader:check_new"), {"filter": "all", "since": existing.pk})
|
||||
|
||||
content = response.content.decode()
|
||||
assert "1 new article" in content
|
||||
assert "click to show" in content
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_check_new_articles_respects_the_active_tag_scope(client, alice):
|
||||
from apps.articles.models import SubscriptionTag, Tag
|
||||
|
||||
feed_a = Feed.objects.create(feed_url="https://a.example.com/feed.xml")
|
||||
feed_b = Feed.objects.create(feed_url="https://b.example.com/feed.xml")
|
||||
sub_a = Subscription.objects.create(user=alice, feed=feed_a)
|
||||
Subscription.objects.create(user=alice, feed=feed_b)
|
||||
tag = Tag.objects.create(user=alice, name="work")
|
||||
SubscriptionTag.objects.create(user=alice, subscription=sub_a, tag=tag)
|
||||
|
||||
cursor = Article.objects.create(feed=feed_a, guid="cursor", title="Cursor").pk
|
||||
# New in feed_b, which isn't tagged "work" — shouldn't count for this scope.
|
||||
Article.objects.create(feed=feed_b, guid="untagged-new", title="Untagged new")
|
||||
|
||||
client.login(username="alice", password="pw-alice-123")
|
||||
response = client.get(
|
||||
reverse("reader:check_new"), {"filter": "all", "tag": tag.pk, "since": cursor}
|
||||
)
|
||||
|
||||
assert response.content.decode().strip() == ""
|
||||
|
||||
# New in feed_a (tagged "work") — should count.
|
||||
Article.objects.create(feed=feed_a, guid="tagged-new", title="Tagged new")
|
||||
response = client.get(
|
||||
reverse("reader:check_new"), {"filter": "all", "tag": tag.pk, "since": cursor}
|
||||
)
|
||||
assert "1 new article" in response.content.decode()
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_stream_exposes_the_latest_article_id_and_scope_for_the_banner(client, alice):
|
||||
feed = Feed.objects.create(feed_url="https://example.com/feed.xml")
|
||||
Subscription.objects.create(user=alice, feed=feed)
|
||||
article = Article.objects.create(feed=feed, guid="g1", title="Hello")
|
||||
|
||||
client.login(username="alice", password="pw-alice-123")
|
||||
response = client.get(reverse("reader:stream"), {"filter": "all"})
|
||||
content = response.content.decode()
|
||||
|
||||
assert f"since={article.pk}" in content
|
||||
assert "filter=all" in content
|
||||
Reference in new issue
Block a user