aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg
diff options
context:
space:
mode:
authorDennis Fink2026-11-22 11:11:23 +0100
committerDennis Fink2026-11-22 11:11:23 +0100
commit779d10051556242ba1e70b70f6c6e8f1158e861d (patch)
tree284d8228491f0a7ee9422a2100149adebad5aaa7 /webmentions_ssg
parentef90dc381322122ecfb9af039cf790de92807514 (diff)
downloadwebmentions-ssg-main.tar.gz
webmentions-ssg-main.zip
feat(receiver)!: enrich digest notification emailsHEADmain
Render plain-text digests with source, target, per-Webmention detail links, and a filtered dashboard link while preserving singular and plural wording. Freeze the notified rows before sending so mentions arriving during delivery are left for the next digest. BREAKING CHANGE: enabling `DIGEST_EMAIL` now requires `SERVER_NAME` so background workers can generate absolute administration URLs.
Diffstat (limited to 'webmentions_ssg')
-rw-r--r--webmentions_ssg/config.py10
-rw-r--r--webmentions_ssg/tasks/notifications.py43
-rw-r--r--webmentions_ssg/templates/emails/verified_digest.txt20
3 files changed, 55 insertions, 18 deletions
diff --git a/webmentions_ssg/config.py b/webmentions_ssg/config.py
index 3d05e5d..514432a 100644
--- a/webmentions_ssg/config.py
+++ b/webmentions_ssg/config.py
@@ -236,6 +236,16 @@ def validated_config_overrides(
except (TypeError, ValueError) as exc:
raise type(exc)(f"{key}: {exc}") from exc
+ # Digests are rendered from a background worker without a request host.
+ # Require a public hostname at startup instead of silently omitting links.
+ if config.get("DIGEST_EMAIL") and not (
+ isinstance(config.get("SERVER_NAME"), str) and config["SERVER_NAME"].strip()
+ ):
+ raise RuntimeError(
+ "Configure SERVER_NAME for the Webmentions SSG admin interface "
+ "when DIGEST_EMAIL is enabled."
+ )
+
if type(config["ALLOWLIST_ENABLED"]) is not bool:
raise ValueError("ALLOWLIST_ENABLED must be a boolean.")
diff --git a/webmentions_ssg/tasks/notifications.py b/webmentions_ssg/tasks/notifications.py
index 6a0e6b9..9871349 100644
--- a/webmentions_ssg/tasks/notifications.py
+++ b/webmentions_ssg/tasks/notifications.py
@@ -7,7 +7,7 @@
from datetime import UTC, datetime
import sqlalchemy as sa
-from flask import current_app
+from flask import current_app, render_template
from flask_mail import Message
from ..extensions import db, huey, mail
@@ -17,8 +17,8 @@ from ..models.received import ReceivedWebmention, ReceivedWebmentionStatus
def email_verified_digest() -> None:
"""Send one digest of verified, previously unreported Webmentions.
- Acquire the digest lock before notifying recipients about previously unreported
- verified mentions.
+ Acquire the digest lock before notifying recipients about previously
+ unreported verified mentions.
"""
# Resolve the lock against the current Huey backend, not the import-time one.
with huey.lock_task("send-webmention-digest"):
@@ -28,8 +28,8 @@ def email_verified_digest() -> None:
def _send_digest_locked() -> None:
"""Do the work while the current backend's digest lock is held.
- Collect verified mentions, send the configured message, and persist notification
- timestamps.
+ Collect verified mentions, send the configured message, and persist
+ notification timestamps.
"""
recipient = current_app.config.get("DIGEST_EMAIL")
if not recipient:
@@ -43,24 +43,28 @@ def _send_digest_locked() -> None:
ReceivedWebmention.updated_at <= cutoff,
)
- count = (
- db.session.scalar(
- sa.select(sa.func.count())
- .select_from(ReceivedWebmention)
- .where(*conditions)
+ # Freeze the list before sending. Only rows represented in this email may
+ # be marked as notified, even if new verified mentions arrive meanwhile.
+ mentions = db.session.execute(
+ sa.select(
+ ReceivedWebmention.uuid,
+ ReceivedWebmention.source,
+ ReceivedWebmention.target,
)
- or 0
- )
+ .where(*conditions)
+ .order_by(ReceivedWebmention.updated_at, ReceivedWebmention.uuid)
+ ).all()
- if count == 0:
+ if not mentions:
return
+ count = len(mentions)
+ subject = f"{count} new verified webmention{'s' if count != 1 else ''} on your site"
message = Message(
- subject=f"Webmention digest: {count} new verified",
+ subject=subject,
recipients=[recipient],
- body=(
- f"{count} new Webmentions have been verified.\n\n"
- "Visit your Webmentions administration page to review them.\n"
+ body=render_template(
+ "emails/verified_digest.txt", count=count, mentions=mentions
),
)
@@ -68,7 +72,10 @@ def _send_digest_locked() -> None:
db.session.execute(
sa.update(ReceivedWebmention)
- .where(*conditions)
+ .where(
+ ReceivedWebmention.uuid.in_([mention.uuid for mention in mentions]),
+ *conditions,
+ )
.values(notification_sent_at=cutoff)
.execution_options(synchronize_session="fetch")
)
diff --git a/webmentions_ssg/templates/emails/verified_digest.txt b/webmentions_ssg/templates/emails/verified_digest.txt
new file mode 100644
index 0000000..959a1cf
--- /dev/null
+++ b/webmentions_ssg/templates/emails/verified_digest.txt
@@ -0,0 +1,20 @@
+{# SPDX-FileCopyrightText: 2026 Dennis Fink <me+coding@dennisfink.me> #}
+{# SPDX-License-Identifier: BSD-3-Clause #}
+Hey,
+
+Your site has {{ count }} new verified webmention{{ "s" if count != 1 else "" }}!
+
+{{ "A page on another site links to your content, and we've verified it." if count == 1 else "Other sites are linking to your content, and we've verified the links." }}
+
+YOUR NEW WEBMENTIONS
+--------------------
+{% for mention in mentions %}
+{{ loop.index }}. Mentioned by: {{ mention.source }}
+ Links to: {{ mention.target }}
+ View details: {{ url_for('webmentions.received_detail', webmention_uuid=mention.uuid, _external=True) }}
+
+{% endfor %}
+See all verified webmentions in your dashboard:
+{{ url_for('webmentions.received_list', status='verified', _external=True) }}
+
+— Webmentions SSG