News that finds you, including when nothing of ours is open
The dots covered Reports and Messages from the day those sections existed. The announcement did not: only a chat reply produced an HX-Trigger, so a scheduled run that filed a report or posted into Messages lit a green dot in a corner and said nothing at all. That is precisely the arrival nobody is watching for -- a chat reply is one you asked for a moment ago and are probably looking at. So every kind announces, each with its own once-only flag, and the payload is a list of items rather than of titles, because a notification is a thing you click and a title cannot say where. One arrival, three channels, and they must not all fire. A toast for somebody looking at the page; a count in the tab title while it is hidden, cleared on focus; a system notification for somebody elsewhere entirely. The service worker is the only place that can tell them apart -- the server cannot see whether a window is focused and the page cannot see a push it did not receive -- so it stays quiet when one of its own windows has focus. And web push, hand-rolled against RFC 8291 and RFC 8292 with the cryptography already here for Fernet. It exists because everything else is polled by an open page, and the arrival worth interrupting somebody for is a schedule firing at seven in the morning with the laptop shut. The trade is real and is written down rather than glossed: the POST goes to Google's or Mozilla's push service, the payload is sealed end to end so they cannot read it, and what they do learn is that this server sent something and when. Opt-in per device, off until asked for, and the rest of the system works without it. Nothing else in LLeMbas contacts an outside service on its own. The encryption is tested by decrypting it back with an independent implementation of the specification's other half. There is no other way to know: a push service accepts the POST and forwards bytes it cannot read, so a wrong derivation is a notification that never appears, with a 201 in the log. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -85,6 +85,32 @@ def unread_count(db: DBSession, user: User | None) -> int:
|
||||
)
|
||||
|
||||
|
||||
def unannounced(db: DBSession, user: User | None) -> list[Report]:
|
||||
"""Reports that have arrived and have not been announced yet.
|
||||
|
||||
Separate from `unread_count`, which drives the dot: the dot may be shown for
|
||||
as long as something is unread, while an announcement fires once. Reading
|
||||
them apart is what stops the poll interrupting somebody every ten seconds
|
||||
with the same report until they open it.
|
||||
|
||||
Ordered oldest first, so several arriving between two ticks are announced in
|
||||
the order they were filed.
|
||||
"""
|
||||
if user is None:
|
||||
return []
|
||||
return list(
|
||||
db.scalars(
|
||||
select(Report)
|
||||
.where(
|
||||
Report.owner_id == user.id,
|
||||
Report.unread.is_(True),
|
||||
Report.unread_notified.is_(False),
|
||||
)
|
||||
.order_by(Report.created_at)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def _first_line(body: str) -> str:
|
||||
"""A summary for a model that did not write one.
|
||||
|
||||
@@ -137,6 +163,22 @@ def create(
|
||||
)
|
||||
db.add(report)
|
||||
db.commit()
|
||||
|
||||
# Here rather than at the scheduled-run site, because a report is filed from
|
||||
# two places -- a schedule delivering one, and a model calling `report_write`
|
||||
# in a chat nobody stayed on -- and both are arrivals somebody would want to
|
||||
# know about. `unread` is what says it is news; a report filed with it off
|
||||
# was made by the person reading this screen.
|
||||
if report.unread:
|
||||
from lembas.services import push as push_service
|
||||
|
||||
push_service.announce_later(
|
||||
report.owner_id,
|
||||
title=report.title or "Report filed",
|
||||
body=report.summary or "A report is waiting for you.",
|
||||
url=f"/reports/{report.id}",
|
||||
kind="report",
|
||||
)
|
||||
return report
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user