Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
caa66f7bb1 | ||
|
|
0465ff924b | ||
|
|
815aff5443 | ||
|
|
4306633a42 | ||
|
|
c5c2d9832e | ||
|
|
483c24b565 | ||
|
|
d312fa0074 | ||
|
|
647f6c723b | ||
|
|
81c730813c | ||
|
|
113f28aff1 | ||
|
|
76b81d6ad9 | ||
|
|
44f77a3adf | ||
|
|
b247de011d | ||
|
|
65fc246d55 |
No files matched your search
@@ -206,6 +206,22 @@ THREADS_USERNAME=
|
||||
# Stop checking a note's responses after this many days (default: 90)
|
||||
# BACKFEED_MAX_AGE_DAYS=90
|
||||
|
||||
# =============================================================================
|
||||
# NOTIFICATIONS (v2.14.0, ADR-074; optional)
|
||||
# =============================================================================
|
||||
|
||||
# Apprise URLs to notify, space- or comma-separated
|
||||
# (https://github.com/caronc/apprise/wiki). Empty: notifications off.
|
||||
# Examples: gotifys://gotify.example.com/APPTOKEN ntfys://my-topic
|
||||
# apprises://apprise.example.com/KEY (an apprise-api server)
|
||||
# NOTIFY_URLS=
|
||||
# What to notify: reply, mention, quote, like, repost, bookmark, problems
|
||||
# (a crosspost that failed for good, a silo refusing backfeed)
|
||||
# NOTIFY_EVENTS=reply,mention,quote,problems
|
||||
# Priority of every message, added to URLs that don't set one:
|
||||
# low, moderate, normal, high, emergency (Gotify also takes 0-10)
|
||||
# NOTIFY_PRIORITY=normal
|
||||
|
||||
# =============================================================================
|
||||
# DEBUGGING
|
||||
# =============================================================================
|
||||
|
||||
@@ -7,6 +7,60 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [2.14.0] - 2026-11-10
|
||||
|
||||
Notifications (ADR-074).
|
||||
|
||||
### Added
|
||||
|
||||
- StarPunk can notify you of new responses through [Apprise](https://github.com/caronc/apprise): Gotify, ntfy, Pushover, email, Matrix, Discord and about 100 more, or an apprise-api server. Set `NOTIFY_URLS` to one or more Apprise URLs (e.g. `gotifys://gotify.example.com/APPTOKEN`)
|
||||
- `NOTIFY_EVENTS` chooses what you hear about: `reply`, `mention`, `quote`, `like`, `repost`, `bookmark`, and `problems` (a crosspost that failed for good, or a silo refusing backfeed). Default `reply,mention,quote,problems`. Replies, mentions and quotes come one at a time with their text; likes, reposts and bookmarks are grouped per note
|
||||
- `NOTIFY_PRIORITY` (default `normal`) sets the priority of every message
|
||||
- Received webmentions and backfed responses are notified alike, each once. Responses waiting for moderation say so and link to the admin
|
||||
- Admin → Webmentions shows the notification settings and the last send error, with **Send test notification**
|
||||
|
||||
### Changed
|
||||
|
||||
- New dependency: `apprise` 2.2. Migration 021 marks every existing response as already notified, and responses found by a backfill (or on a crosspost's first check of an older note) are never notified
|
||||
|
||||
## [2.13.4] - 2026-11-10
|
||||
|
||||
### Added
|
||||
|
||||
- The home page, tag pages and the Likes page show each note's like, repost and reply counts next to its date (♥ 3 🔁 1 💬 2), linking to the note's responses. Notes with none show nothing
|
||||
|
||||
### Changed
|
||||
|
||||
- Clicking anywhere on a reply opens it where it was posted (the reply on Bluesky, GoToSocial or Threads, or the page that sent the webmention). The author link and links in the reply still go to their own pages
|
||||
|
||||
### Fixed
|
||||
|
||||
- The "Liked", "Reposted" and "In reply to" lines on notes picked up styles meant for v2.13.2's counts line (both used the class `reaction`). The counts line's classes are now `response-*`
|
||||
|
||||
## [2.13.3] - 2026-11-10
|
||||
|
||||
### Changed
|
||||
|
||||
- Likes and reposts by people who opted out of backfeed (`#nobridge` or `#nobot` in their profile, or Bluesky's "don't show me to logged-out users" label) are counted in a note's totals, without their name or avatar ("+1 on Bluesky"). Before, they were left out entirely, so totals were lower than on the silo
|
||||
|
||||
## [2.13.2] - 2026-11-10
|
||||
|
||||
### Changed
|
||||
|
||||
- Likes, reposts and bookmarks are no longer rows of faces under "Responses". A note shows one line of counts under the post (♥ likes, 🔁 reposts, 💬 replies, bookmarks), and hovering or tapping a count lists who, with where each came from. Threads' anonymous counts are part of the totals ("+1 on Threads"), so the separate "On Threads" line is gone. The Responses section now holds replies, quotes and mentions
|
||||
- Web actions (https://indieweb.org/webactions): each like, repost and reply count is an `<indie-action>` for the note, with links to do the same on the note's crossposts ("Like on Bluesky · GoToSocial · Threads"). The icons show even before anyone has responded, when the note has crossposts
|
||||
|
||||
### Fixed
|
||||
|
||||
- Avatars that GoToSocial hasn't cached (it redirects to the original server) are saved; the redirect is followed through the safe fetcher
|
||||
|
||||
## [2.13.1] - 2026-11-10
|
||||
|
||||
### Fixed
|
||||
|
||||
- Avatars from your own GoToSocial server are saved again. When StarPunk reaches it through the same proxy, its name resolves to an internal address, which the safe fetcher refused. That one server (`GOTOSOCIAL_URL`) is now fetched directly, as crossposting already does
|
||||
- Bluesky avatars are saved again. Bluesky's image CDN refuses some servers' IPv4 addresses (HTTP 403), so avatars are now downloaded from the account's own server (`com.atproto.sync.getBlob`)
|
||||
|
||||
## [2.13.0] - 2026-11-10
|
||||
|
||||
Backfeed: responses to crossposts come back to the note (ADR-073).
|
||||
|
||||
@@ -202,9 +202,9 @@ coordinated through the data volume:
|
||||
|
||||
| Thread | Started when | Coordination | Work |
|
||||
|--------|--------------|--------------|------|
|
||||
| Webmention worker (`webmention_worker.py`) | `WEBMENTION_WORKER_ENABLED` and not testing | Non-blocking `fcntl.flock` on `webmention-worker.lock` next to the database. Only the holder works the queues; the others try again each poll interval. The OS releases the lock if the holder dies, and the new holder resets rows stuck in `sending`. | Validates received webmentions; discovers endpoints and sends queued outgoing webmentions, with retries |
|
||||
| Webmention worker (`webmention_worker.py`) | `WEBMENTION_WORKER_ENABLED` and not testing | Non-blocking `fcntl.flock` on `webmention-worker.lock` next to the database. Only the holder works the queues; the others try again each poll interval. The OS releases the lock if the holder dies, and the new holder resets rows stuck in `sending`. | Validates received webmentions; discovers endpoints and sends queued outgoing webmentions, with retries; saves response avatars (v2.13.0); sends notifications of new responses (v2.14.0, `notifications.py`, ADR-074) |
|
||||
| WebSub worker (`websub_worker.py`) | `WEBSUB_ENABLED` and not testing | Same pattern with `websub-worker.lock` | Verifies subscription intents, delivers topic content (signed with `X-Hub-Signature` when the subscriber gave a secret), retries, expires leases; pings an external hub instead if `WEBSUB_HUB_URL` is set |
|
||||
| Syndication worker (`syndication.py`) | At least one crosspost target configured, and not testing | No file lock. Rows in `syndications` are claimed with a 5-minute `claimed_until` lease by an atomic `UPDATE`, so any process may work a row but only one at a time; a `version` column keeps edits made during a send. Threads token refreshes are serialised with a lock file next to `threads_token.json`. | Creates, updates or deletes the remote post for each (note, target) pair; up to 8 attempts |
|
||||
| Syndication worker (`syndication.py`) | At least one crosspost target configured, and not testing | No file lock. Rows in `syndications` are claimed with a 5-minute `claimed_until` lease by an atomic `UPDATE`, so any process may work a row but only one at a time; a `version` column keeps edits made during a send. Threads token refreshes are serialised with a lock file next to `threads_token.json`. | Creates, updates or deletes the remote post for each (note, target) pair; up to 8 attempts. Then backfeed: checks copies for responses (v2.13.0, `backfeed.py`, ADR-073) |
|
||||
|
||||
All workers run inside an app context, are daemon threads (they end with the
|
||||
process) and sleep for their poll interval when there is nothing to do. Under
|
||||
|
||||
@@ -43,6 +43,7 @@ vulnerabilities (`pip-audit`); check again before each release.
|
||||
| python-dateutil | `4.0.*` | Dates in reply contexts |
|
||||
| feedgen | `1.0.*` | RSS 2.0 feed (`starpunk/feeds/rss.py`); Atom and JSON Feed are generated by StarPunk's own code |
|
||||
| httpx | `0.28.*` | All outbound HTTP; requests to user-supplied URLs go through `webmention_ssrf.safe_get`/`safe_post` |
|
||||
| apprise | `2.2.*` | Notifications to the owner's services (`starpunk/notifications.py`, ADR-074); sends to the URLs the owner configures, outside the SSRF-safe fetcher |
|
||||
| PyJWT[crypto] | `2.15.*` | Verifying OIDC ID tokens (JWKS, RS/ES signatures via `cryptography`) |
|
||||
| python-dotenv | `1.2.*` | Loading `.env` |
|
||||
| Pillow | `13.0.*` | Image validation, resizing and variants |
|
||||
|
||||
@@ -223,6 +223,27 @@ Threads 2 (replies, insights), plus extra pages.
|
||||
While at it, the Threads client moves from `graph.threads.net` to
|
||||
`graph.threads.com`, the host Meta's current documentation uses.
|
||||
|
||||
## Amendments (v2.13.2, 2026-11-10)
|
||||
|
||||
- **Display.** Likes, reposts and bookmarks are a line of counts under the
|
||||
note instead of facepiles in the Responses section. Hovering or focusing
|
||||
a count lists the people (as `u-like` / `u-repost` / `u-bookmark`
|
||||
h-cites) and the silo each came from. Threads' anonymous counts are added
|
||||
to the totals ("+N on Threads") instead of a separate line (Decision 7).
|
||||
- **Web actions.** Each like, repost and reply count is an
|
||||
`<indie-action do="…" with="<permalink>">` whose fallback is a link to
|
||||
the same action on each crosspost. No web-action polyfill is loaded;
|
||||
handlers such as browser extensions can use the markup.
|
||||
|
||||
## Amendments (v2.13.3, 2026-11-10)
|
||||
|
||||
- **Opted-out people are counted.** Their likes, reposts and quotes are
|
||||
still not stored or named (Decision 5), but each check records how many
|
||||
there were on the copy's `syndications` row (`likes_count`,
|
||||
`reposts_count`, `quotes_count`, the columns Threads' counts use), and
|
||||
the counts line adds them to the totals as "N on <silo>". Totals then
|
||||
match the silo.
|
||||
|
||||
## Consequences
|
||||
|
||||
- Responses on all three silos show on the note within 15 minutes for new
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
# ADR-074: Notifications through Apprise
|
||||
|
||||
## Status
|
||||
|
||||
Accepted (v2.14.0, 2026-11-10)
|
||||
|
||||
## Context
|
||||
|
||||
Responses now reach a note from two places: received webmentions
|
||||
(ADR-063) and backfeed from the crossposts (ADR-073). The owner only finds
|
||||
out about them by opening the site or the admin. Crossposts that finally
|
||||
fail, and silos that refuse a backfeed credential, are just as invisible.
|
||||
|
||||
Owners use different notification services. The production site uses
|
||||
Gotify (read on iOS through iGotify). Others use ntfy, Pushover, email,
|
||||
Matrix, Discord and so on. [Apprise](https://github.com/caronc/apprise)
|
||||
covers about 100 of them behind one URL syntax (`gotifys://host/token`,
|
||||
`ntfys://topic`, `mailtos://…`), both as a Python library and as a
|
||||
separate HTTP server (apprise-api).
|
||||
|
||||
Options considered:
|
||||
|
||||
1. **Gotify only.** Simplest for this site, no use to anyone else.
|
||||
2. **Post to an apprise-api server.** Standard, but every owner needs one
|
||||
running, and messages take an extra hop.
|
||||
3. **Embed the Apprise library.** Sends straight to each service; an owner
|
||||
who prefers a central apprise-api can still use its `apprise://` /
|
||||
`apprises://` URL.
|
||||
4. **Gotify plus a generic JSON webhook, hand-written.** No dependency, but
|
||||
every other service needs glue the owner has to write.
|
||||
|
||||
## Decision
|
||||
|
||||
### 1. Embed Apprise
|
||||
|
||||
StarPunk depends on the `apprise` package and sends with it directly.
|
||||
`NOTIFY_URLS` holds one or more Apprise URLs (space- or comma-separated);
|
||||
each message goes to all of them. With no URLs, notifications are off and
|
||||
nothing else changes.
|
||||
|
||||
### 2. What can be notified
|
||||
|
||||
`NOTIFY_EVENTS` is a comma-separated list. Default:
|
||||
`reply,mention,quote,problems`.
|
||||
|
||||
| Event | Sent when |
|
||||
|---|---|
|
||||
| `reply`, `mention`, `quote`, `like`, `repost`, `bookmark` | a response of that type is first shown on a note, or first awaits moderation (received webmention or backfeed alike) |
|
||||
| `problems` | a crosspost fails for good (permanent error or last attempt), or a silo refuses the backfeed credential (ADR-073 Decision 9) |
|
||||
|
||||
### 3. Messages
|
||||
|
||||
Markdown, so services that render it (Gotify, iGotify, ntfy, Matrix…)
|
||||
show links; others get the text.
|
||||
|
||||
- **Replies, mentions, quotes:** one message each. Title "↩ Reply from Ana
|
||||
Lima via Bluesky" (or "💬 Mention from …", "❝ Quote from …"); body the
|
||||
response text (plain, up to 300 characters), then a link to the note's
|
||||
responses (`<permalink>#responses`).
|
||||
- **Likes, reposts, bookmarks:** grouped per note and type in each pass:
|
||||
"♥ 3 new likes on 'Starpunk now supports…'", with up to five names and a
|
||||
link to the note.
|
||||
- **Awaiting moderation:** when `WEBMENTION_AUTO_APPROVE` is off, the title
|
||||
says so and the link goes to the admin webmention page instead.
|
||||
- **Problems:** "⚠ Crosspost to Bluesky failed" / "⚠ Backfeed for Threads
|
||||
stopped" with the error and a link to the note's edit page or the
|
||||
Webmentions page.
|
||||
|
||||
Apprise's Gotify plugin has no click-through link, so the link is in the
|
||||
text.
|
||||
|
||||
### 3a. Priority
|
||||
|
||||
Every message is sent with the same priority, `NOTIFY_PRIORITY` (default
|
||||
`normal`). Apprise takes priority as a `priority` argument in each service
|
||||
URL, with values that differ by service, so StarPunk adds
|
||||
`priority=<NOTIFY_PRIORITY>` to each URL in `NOTIFY_URLS` that doesn't set
|
||||
one itself; a URL can still set its own. Apprise's names (`low`,
|
||||
`moderate`, `normal`, `high`, `emergency`) work for most services; Gotify
|
||||
also takes 0–10 (it maps the names to 0, 3, 5, 8, 10). Different
|
||||
priorities per event can come later.
|
||||
|
||||
### 4. Delivery
|
||||
|
||||
- New column `webmentions.notified_at`. A sweep finds responses with
|
||||
`notified_at IS NULL`, `validation_status = 'valid'`, a moderation status
|
||||
of `approved` or `pending`, and a type in `NOTIFY_EVENTS`, sends them,
|
||||
and sets `notified_at`. Types not selected are marked without sending.
|
||||
- The sweep runs in the webmention worker loop, which already runs in one
|
||||
process at a time (its file lock), so nothing is sent twice by several
|
||||
gunicorn workers. It handles received and backfed responses alike.
|
||||
- A failed send leaves `notified_at` empty, so the next pass (about 10
|
||||
seconds later) retries, with backoff up to 15 minutes. Responses older
|
||||
than 24 hours that still haven't gone out are marked and dropped, with a
|
||||
warning, so an outage doesn't end in a flood. The last error is shown on
|
||||
the admin Webmentions page.
|
||||
- Problems are sent at the moment they happen (from the syndication and
|
||||
backfeed workers) and not retried: they are also in the log and admin.
|
||||
- Sending never blocks or breaks validation, crossposting or backfeed.
|
||||
|
||||
### 5. No floods from history
|
||||
|
||||
- Migration 021 sets `notified_at` on every existing response.
|
||||
- Responses stored by a backfill check (ADR-073 Decision 8) are stored with
|
||||
`notified_at` set.
|
||||
- So are responses found on a crosspost's first check when its note is more
|
||||
than a day old (copies linked after the fact).
|
||||
- Grouping (Decision 3) keeps a busy note to one like message per pass.
|
||||
|
||||
### 6. Admin
|
||||
|
||||
- **Send test notification** on the admin Webmentions page sends a test
|
||||
message to every URL and reports each result.
|
||||
- The page shows whether notifications are on, which events are selected,
|
||||
and the last send error.
|
||||
|
||||
### 7. Configuration
|
||||
|
||||
| Setting | Default | Meaning |
|
||||
|---|---|---|
|
||||
| `NOTIFY_URLS` | empty (off) | Apprise URLs, space- or comma-separated |
|
||||
| `NOTIFY_EVENTS` | `reply,mention,quote,problems` | which events are sent |
|
||||
| `NOTIFY_PRIORITY` | `normal` | priority of every message, added to URLs that don't set one |
|
||||
|
||||
Settings stay in the environment, like the rest of StarPunk's (ADR-052).
|
||||
URLs contain tokens and belong with the other secrets.
|
||||
|
||||
## Consequences
|
||||
|
||||
- One new dependency, `apprise`, with its own (requests, PyYAML, click,
|
||||
Markdown, certifi). It must install on Python 3.14 in the container
|
||||
image; this is checked before the release.
|
||||
- Owners can send to almost any service without writing glue, directly or
|
||||
through apprise-api.
|
||||
- Each response is notified at most once, a few seconds after it appears,
|
||||
and only if its type is selected.
|
||||
- Apprise opens outbound connections to whatever URLs the owner configures,
|
||||
outside the SSRF-safe fetcher. That is intended: the owner chooses these
|
||||
URLs, as with the crosspost targets. A service behind the same reverse
|
||||
proxy as StarPunk may need the deployment's internal-address entry
|
||||
(`extra_hosts`), as GoToSocial does.
|
||||
- Notification text includes other people's names and words, sent to the
|
||||
owner's own services only.
|
||||
|
||||
## Alternatives considered
|
||||
|
||||
- **Gotify only / hand-written webhook.** See Context, options 1 and 4: no
|
||||
dependency, but each service beyond Gotify needs glue the owner writes.
|
||||
- **apprise-api only.** See option 2. Still possible through an
|
||||
`apprises://` URL.
|
||||
- **Sending from where responses are stored** (webmention worker,
|
||||
backfeed) instead of a sweep. Two code paths, no retry, and backfeed
|
||||
runs in every gunicorn worker. Rejected.
|
||||
- **Choosing events in the admin UI.** Possible later; the environment is
|
||||
where StarPunk's settings live today.
|
||||
@@ -5,8 +5,8 @@ records one decision: its context, what was decided, and the consequences.
|
||||
Superseded ADRs are kept as history; their Status line names the ADR that
|
||||
replaced them.
|
||||
|
||||
**Total ADR files**: 69 (68 numbers: ADR-001 to ADR-044 and ADR-050 to
|
||||
ADR-073, with two files numbered ADR-012). See [Numbering](#numbering).
|
||||
**Total ADR files**: 70 (69 numbers: ADR-001 to ADR-044 and ADR-050 to
|
||||
ADR-074, with two files numbered ADR-012). See [Numbering](#numbering).
|
||||
|
||||
Status values: **Accepted** (in force), **Superseded** (replaced by a later
|
||||
ADR), **Deprecated** (withdrawn, nothing replaces it; none at present),
|
||||
@@ -85,6 +85,7 @@ See also [IndieWeb protocols](../architecture/indieweb-protocols.md).
|
||||
| [066](ADR-066-bluesky-syndication.md) | Crossposting to Bluesky | Accepted | Bluesky as a second crosspost target (v2.2.0). |
|
||||
| [069](ADR-069-threads-syndication.md) | Crossposting to Threads | Accepted | Threads as a third target, with automatic token refresh (v2.6.0). |
|
||||
| [070](ADR-070-crosspost-links-and-cards.md) | Links and link cards in crossposts | Accepted | Keep note links in crossposts and build link cards for the linked page (v2.6.3). |
|
||||
| [074](ADR-074-notifications.md) | Notifications through Apprise | Accepted | Notify the owner of new responses and crosspost/backfeed problems via the embedded Apprise library (v2.14.0). |
|
||||
| [073](ADR-073-backfeed.md) | Backfeed of responses to crossposts | Accepted | Poll GoToSocial, Bluesky and Threads for responses to crossposts and store them as webmentions; admin backfill (v2.13.0). |
|
||||
|
||||
### Authentication (current)
|
||||
@@ -168,7 +169,7 @@ was carried out and is not itself superseded.
|
||||
|
||||
## How to create a new ADR
|
||||
|
||||
1. Use the next number after the highest existing one (currently ADR-074).
|
||||
1. Use the next number after the highest existing one (currently ADR-075).
|
||||
2. Name it `ADR-NNN-brief-descriptive-title.md`.
|
||||
3. Follow the format of recent ADRs (e.g. ADR-070, ADR-071):
|
||||
|
||||
|
||||
+21
-1
@@ -21,7 +21,7 @@ is in `../architecture/`; decisions are in `../decisions/` (ADRs).
|
||||
|
||||
## Contents
|
||||
|
||||
[v1.0.0](#v100) · [v1.1.1](#v111) · [v1.1.2](#v112) · [v1.2.0](#v120) · [v1.3.0](#v130) · [v1.3.1](#v131) · [v1.4.0](#v140) · [v1.4.1](#v141) · [v1.4.2](#v142) · [v1.5.0](#v150) · [v1.6.0](#v160) · [v2.0.0](#v200) · [v2.0.1](#v201) · [v2.0.2](#v202) · [v2.1.0](#v210) · [v2.2.0](#v220) · [v2.3.0](#v230) · [v2.3.1](#v231) · [v2.3.2](#v232) · [v2.3.3](#v233) · [v2.4.0](#v240) · [v2.5.0](#v250) · [v2.6.0](#v260) · [v2.6.1](#v261) · [v2.6.2](#v262) · [v2.6.3](#v263) · [v2.6.4](#v264) · [v2.6.5](#v265) · [v2.6.6](#v266) · [v2.6.7](#v267) · [v2.6.8](#v268) · [v2.6.9](#v269) · [v2.7.0](#v270) · [v2.7.1](#v271) · [v2.7.2](#v272) · [v2.8.0](#v280) · [v2.8.1](#v281) · [v2.9.0](#v290) · [v2.10.0](#v2100) · [v2.10.1](#v2101) · [v2.10.2](#v2102) · [v2.11.0](#v2110) · [v2.12.0](#v2120) · [v2.12.1](#v2121) · [v2.13.0](#v2130) · [hotfix](#hotfix)
|
||||
[v1.0.0](#v100) · [v1.1.1](#v111) · [v1.1.2](#v112) · [v1.2.0](#v120) · [v1.3.0](#v130) · [v1.3.1](#v131) · [v1.4.0](#v140) · [v1.4.1](#v141) · [v1.4.2](#v142) · [v1.5.0](#v150) · [v1.6.0](#v160) · [v2.0.0](#v200) · [v2.0.1](#v201) · [v2.0.2](#v202) · [v2.1.0](#v210) · [v2.2.0](#v220) · [v2.3.0](#v230) · [v2.3.1](#v231) · [v2.3.2](#v232) · [v2.3.3](#v233) · [v2.4.0](#v240) · [v2.5.0](#v250) · [v2.6.0](#v260) · [v2.6.1](#v261) · [v2.6.2](#v262) · [v2.6.3](#v263) · [v2.6.4](#v264) · [v2.6.5](#v265) · [v2.6.6](#v266) · [v2.6.7](#v267) · [v2.6.8](#v268) · [v2.6.9](#v269) · [v2.7.0](#v270) · [v2.7.1](#v271) · [v2.7.2](#v272) · [v2.8.0](#v280) · [v2.8.1](#v281) · [v2.9.0](#v290) · [v2.10.0](#v2100) · [v2.10.1](#v2101) · [v2.10.2](#v2102) · [v2.11.0](#v2110) · [v2.12.0](#v2120) · [v2.12.1](#v2121) · [v2.13.0](#v2130) · [v2.13.1](#v2131) · [v2.13.2](#v2132) · [v2.13.3](#v2133) · [v2.13.4](#v2134) · [v2.14.0](#v2140) · [hotfix](#hotfix)
|
||||
|
||||
## v1.0.0
|
||||
|
||||
@@ -426,6 +426,26 @@ OIDC admin login and built-in IndieAuth server.
|
||||
|
||||
- [2026-11-10-backfeed.md](v2.13.0/2026-11-10-backfeed.md) - Backfeed of responses to crossposts (ADR-073), avatar cache, delete tombstones
|
||||
|
||||
## v2.13.1
|
||||
|
||||
- [2026-11-10-avatar-fetch.md](v2.13.1/2026-11-10-avatar-fetch.md) - Avatars from the own GoToSocial server and from Bluesky PDSes
|
||||
|
||||
## v2.13.2
|
||||
|
||||
- [2026-11-10-reaction-counts.md](v2.13.2/2026-11-10-reaction-counts.md) - Likes/reposts as a counts line with hover lists; web actions
|
||||
|
||||
## v2.13.3
|
||||
|
||||
- [2026-11-10-count-opted-out.md](v2.13.3/2026-11-10-count-opted-out.md) - Opted-out people's likes and reposts counted without names
|
||||
|
||||
## v2.13.4
|
||||
|
||||
- [2026-11-10-list-counts.md](v2.13.4/2026-11-10-list-counts.md) - Counts on lists of notes; whole reply card links to the reply; class clash fixed
|
||||
|
||||
## v2.14.0
|
||||
|
||||
- [2026-11-10-notifications.md](v2.14.0/2026-11-10-notifications.md) - Notifications through Apprise (ADR-074)
|
||||
|
||||
## hotfix
|
||||
|
||||
Not a release folder.
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
# v2.13.1: Avatar fetching in production
|
||||
|
||||
## Problem
|
||||
|
||||
After deploying v2.13.0, backfeed stored responses but no avatar was saved:
|
||||
|
||||
- GoToSocial avatars (`https://social.../fileserver/...`):
|
||||
`SSRFBlockedError: Blocked request to private IP: 172.20.0.5`. Inside the
|
||||
container the GoToSocial host resolves to the reverse proxy's internal
|
||||
address (the deployment's hairpin `extra_hosts` entry).
|
||||
- Bluesky avatars (`https://cdn.bsky.app/img/avatar/...`): HTTP 403 from
|
||||
BunnyCDN. From the server, the CDN answers 403 over IPv4 and 200 over
|
||||
IPv6; the container has no IPv6 route. From elsewhere IPv4 works.
|
||||
|
||||
## Fix (`starpunk/avatars.py`, `_download`)
|
||||
|
||||
- The host of `GOTOSOCIAL_URL` is fetched with a plain HTTP client (no
|
||||
redirects, 1 MB limit), as `MastodonClient` already talks to it. Every
|
||||
other host still goes through `safe_get`, so private addresses stay
|
||||
blocked.
|
||||
- `cdn.bsky.app/img/<kind>/plain/<did>/<cid>` URLs are fetched from the
|
||||
account's PDS with `com.atproto.sync.getBlob`; the PDS comes from the DID
|
||||
document (`plc.directory` for `did:plc`, `/.well-known/did.json` for
|
||||
`did:web`). Both requests use `safe_get`. The cache file is still named
|
||||
after the original URL.
|
||||
|
||||
## Verification
|
||||
|
||||
- `tests/test_backfeed.py::test_avatars_from_own_gotosocial_and_bluesky_pds`:
|
||||
own GoToSocial on a private address is fetched, a Bluesky CDN URL is
|
||||
fetched from its PDS, another private address is still refused.
|
||||
- Checked against the real PLC directory and a bsky.network PDS.
|
||||
- From the production server: getBlob over IPv4 returns the image (200).
|
||||
@@ -0,0 +1,32 @@
|
||||
# v2.13.2: Reaction counts and web actions
|
||||
|
||||
## Why
|
||||
|
||||
With backfeed live, notes showed "5 Likes" and "1 Repost" headings over
|
||||
rows of faces (blank until avatars were saved), plus a separate
|
||||
"On Threads: 1 like" line. The owner asked for the usual presentation: a
|
||||
flat count under the post, with who on hover. Web actions
|
||||
(https://indieweb.org/webactions) fit the same line.
|
||||
|
||||
## What changed
|
||||
|
||||
- `templates/partials/responses.html`: `facepile` and `silo_counts` are
|
||||
replaced by `reactions` / `reaction`. Each count is a focusable
|
||||
`.reaction` with an SVG icon; its `.reaction-who` card lists the people
|
||||
(avatar, name, silo) inside a scrollable `.reaction-people`, Threads'
|
||||
anonymous counts, and an `<indie-action>` with links to the crossposts.
|
||||
The reply count has no people list (replies are listed below).
|
||||
- `templates/note.html`: the counts line follows the note's footer; the
|
||||
Responses section shows only when there are replies, quotes or mentions.
|
||||
- `static/css/style.css`: facepile styles replaced by `.reactions`; the card
|
||||
opens on `:hover` and `:focus-within` (tap on touch screens).
|
||||
- `starpunk/avatars.py`: a redirect from the own GoToSocial server (media it
|
||||
hasn't cached) is followed through `safe_get`.
|
||||
|
||||
## Verification
|
||||
|
||||
- `tests/test_backfeed.py` (24 tests): totals include Threads' anonymous
|
||||
count, `<indie-action>` and crosspost links present; redirected avatar
|
||||
saved. Microformats, template and route tests pass.
|
||||
- Rendered locally in headless Chromium in dark and light themes with the
|
||||
like and reply cards open.
|
||||
@@ -0,0 +1,22 @@
|
||||
# v2.13.3: Count opted-out people without naming them
|
||||
|
||||
## Why
|
||||
|
||||
A note's Bluesky copy had 1 like on Bluesky and 0 on the note. The liker's
|
||||
account has the `!no-unauthenticated` label, so backfeed skipped them
|
||||
(ADR-073 Decision 5). Every other Bluesky copy's like and repost counts
|
||||
matched what StarPunk had stored.
|
||||
|
||||
## Change
|
||||
|
||||
`backfeed.hidden_counts(harvest)`: the silo's own counts when it gives no
|
||||
names (Threads), else the number of opted-out likes, reposts and quotes in
|
||||
the harvest. `check()` stores it on the copy's `syndications` row, and the
|
||||
counts line (v2.13.2) already adds those columns to the totals as
|
||||
"N on <silo>". Opted-out people are still not stored.
|
||||
|
||||
## Verification
|
||||
|
||||
`tests/test_backfeed.py::test_people_who_opt_out_are_counted_not_named`:
|
||||
label, `#nobot` and `#nobridge` opt-outs counted (2 likes, 1 repost), not
|
||||
stored, not named on the page; totals include them.
|
||||
@@ -0,0 +1,24 @@
|
||||
# v2.13.4: Counts on lists of notes, reply cards as links
|
||||
|
||||
## What changed
|
||||
|
||||
- `webmention_queries.response_counts(note_ids)`: likes, reposts and
|
||||
replies per note in two grouped queries (shown webmentions, plus the
|
||||
anonymous counts on synced `syndications` rows). `routes/public.py`
|
||||
`attach_response_counts()` runs after `attach_contexts()` on the home,
|
||||
tag and Likes pages.
|
||||
- `partials/responses.html` `list_counts`: icons and numbers in the note's
|
||||
meta line, linking to `<permalink>#responses` (an anchor on the note page).
|
||||
- Reply cards: the date link (already the reply's own URL) stretches over
|
||||
the card with `::after`; author and content links sit above it.
|
||||
- v2.13.2's `.reaction*` classes clashed with the older `.reaction` lines
|
||||
(Liked / Reposted / In reply to, `partials/reaction.html`): the counts
|
||||
line now uses `.response-count*` / `.response-card*` / `.response-*`.
|
||||
|
||||
## Verification
|
||||
|
||||
- `tests/test_backfeed.py::test_home_page_shows_counts`; template, route,
|
||||
microformats and likes/reposts tests pass.
|
||||
- Rendered the home page, a note page and the Likes page in headless
|
||||
Chromium: counts beside the date, quiet notes unchanged, the Liked line
|
||||
laid out as before v2.13.2.
|
||||
@@ -0,0 +1,38 @@
|
||||
# v2.14.0: Notifications (implementation report)
|
||||
|
||||
Implements ADR-074.
|
||||
|
||||
## What changed
|
||||
|
||||
- `starpunk/notifications.py` (new): settings (`urls`, `events`,
|
||||
`with_priority`), `send` (Apprise, Markdown, 15 s timeout, never raises,
|
||||
errors captured with `apprise.LogCapture`), `problem`, and `Sweeper`,
|
||||
which sends due responses, groups likes/reposts/bookmarks per note,
|
||||
marks `notified_at`, backs off after a failure (10 s doubling to 15 min),
|
||||
drops responses older than 24 hours, and records the last error in
|
||||
`site_state.notify_last_error`.
|
||||
- `migrations/021_notifications.sql`: `webmentions.notified_at`, set on all
|
||||
existing rows.
|
||||
- `webmention_worker.py`: runs the sweep each pass (one process holds the
|
||||
worker lock).
|
||||
- `backfeed.py`: `store(..., quiet=True)` inserts new rows as notified;
|
||||
`check()` is quiet for backfill checks and a copy's first check of a note
|
||||
older than a day. A refused credential sends a `problems` message.
|
||||
- `syndication.py`: `_fail` sends a `problems` message when it gives up.
|
||||
- Admin Webmentions page: status (events, services, priority, last error)
|
||||
and **Send test notification** (`POST /admin/notifications/test`).
|
||||
- Settings `NOTIFY_URLS`, `NOTIFY_EVENTS`, `NOTIFY_PRIORITY`; dependency
|
||||
`apprise==2.2.*`.
|
||||
|
||||
## Verification
|
||||
|
||||
- `tests/test_notifications.py` (11 tests): settings parsing and priority
|
||||
injection; one message per reply/mention, likes grouped, unselected types
|
||||
marked, pending moderation linked to the admin; nothing sent twice;
|
||||
failure backoff and retry, last error set and cleared; 24-hour drop; off
|
||||
without URLs; quiet backfill and late first checks; problems (selected or
|
||||
not) and the final crosspost failure; admin status and test button; a
|
||||
real Apprise send (`json://`) to a local server; migration 021.
|
||||
- Webmention, syndication, backfeed, admin and migration tests pass.
|
||||
- Apprise 2.2.0 installs and imports on Python 3.14.
|
||||
- Production Gotify (3.1.1) accepted a message with the StarPunk app token.
|
||||
@@ -4,7 +4,7 @@
|
||||
**Last Updated**: 2026-11-03 (v2.10.1)
|
||||
|
||||
StarPunk uses [Semantic Versioning 2.0.0](https://semver.org/):
|
||||
`MAJOR.MINOR.PATCH`, currently **2.13.0**. Every release is a git tag
|
||||
`MAJOR.MINOR.PATCH`, currently **2.14.0**. Every release is a git tag
|
||||
`vX.Y.Z` and a `CHANGELOG.md` entry. Where the number is stored and how to
|
||||
write the changelog entry is in
|
||||
[version-implementation-guide.md](version-implementation-guide.md); the
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
-- Migration 021: Notifications (v2.14.0, ADR-074)
|
||||
-- When the owner was notified of a response. Everything already stored
|
||||
-- counts as notified, so turning notifications on doesn't send history.
|
||||
|
||||
ALTER TABLE webmentions ADD COLUMN notified_at TIMESTAMP;
|
||||
UPDATE webmentions SET notified_at = CURRENT_TIMESTAMP;
|
||||
@@ -19,6 +19,9 @@ httpx==0.28.*
|
||||
PyJWT[crypto]==2.15.*
|
||||
python-dotenv==1.2.*
|
||||
|
||||
# Notifications (v2.14.0, ADR-074)
|
||||
apprise==2.2.*
|
||||
|
||||
# Images
|
||||
Pillow==13.0.*
|
||||
pillow-heif==1.8.*
|
||||
@@ -465,5 +465,5 @@ def create_app(config=None):
|
||||
|
||||
# Package version (Semantic Versioning 2.0.0)
|
||||
# See docs/standards/versioning-strategy.md for details
|
||||
__version__ = "2.13.0"
|
||||
__version_info__ = (2, 13, 0)
|
||||
__version__ = "2.14.0"
|
||||
__version_info__ = (2, 14, 0)
|
||||
+80
-7
@@ -24,6 +24,9 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
SIZE = 96
|
||||
MAX_BYTES = 1024 * 1024
|
||||
# Bluesky avatar on its CDN: .../img/<kind>/plain/<did>/<cid>[@jpeg]
|
||||
BSKY_CDN_RE = re.compile(
|
||||
r"^https://cdn\.bsky\.app/img/[a-z_]+/plain/(did:(?:plc|web):[A-Za-z0-9._:%-]+)/([a-z2-7]+)(?:@\w+)?$")
|
||||
NAME_RE = re.compile(r"^[0-9a-f]{64}\.webp$")
|
||||
CLEANUP_EVERY = 7 * 24 * 3600
|
||||
|
||||
@@ -56,14 +59,8 @@ def fetch(data_path, url: Optional[str], site_url: str) -> bool:
|
||||
return True
|
||||
from PIL import Image
|
||||
|
||||
from starpunk.webmention_ssrf import safe_get, user_agent
|
||||
|
||||
try:
|
||||
result = safe_get(url, headers={"User-Agent": user_agent(site_url)},
|
||||
max_bytes=MAX_BYTES, max_redirects=5, timeout=10.0, truncate=False)
|
||||
if result.status_code >= 400:
|
||||
raise ValueError(f"HTTP {result.status_code}")
|
||||
with Image.open(io.BytesIO(result.content)) as image:
|
||||
with Image.open(io.BytesIO(_download(url, site_url))) as image:
|
||||
image.load()
|
||||
image = image.convert("RGBA" if "A" in image.getbands() else "RGB")
|
||||
side = min(image.size)
|
||||
@@ -80,6 +77,82 @@ def fetch(data_path, url: Optional[str], site_url: str) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def _own_instance_host() -> Optional[str]:
|
||||
"""Host of the GoToSocial server StarPunk posts to (it may resolve to an internal address)"""
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from flask import current_app
|
||||
return urlparse(current_app.config.get("GOTOSOCIAL_URL") or "").hostname
|
||||
|
||||
|
||||
def _get(url: str, headers: dict) -> bytes:
|
||||
"""GET a public URL through the SSRF-safe fetcher"""
|
||||
from starpunk.webmention_ssrf import safe_get
|
||||
|
||||
result = safe_get(url, headers=headers, max_bytes=MAX_BYTES, max_redirects=5,
|
||||
timeout=10.0, truncate=False)
|
||||
if result.status_code >= 400:
|
||||
raise ValueError(f"HTTP {result.status_code}")
|
||||
return result.content
|
||||
|
||||
|
||||
def _pds(did: str, headers: dict) -> str:
|
||||
"""The PDS that hosts a Bluesky account, from its DID document"""
|
||||
if did.startswith("did:plc:"):
|
||||
doc_url = f"https://plc.directory/{did}"
|
||||
else: # did:web:<host>
|
||||
doc_url = f"https://{did[len('did:web:'):]}/.well-known/did.json"
|
||||
import json
|
||||
|
||||
for service in json.loads(_get(doc_url, headers)).get("service") or []:
|
||||
if service.get("id", "").endswith("#atproto_pds") and service.get("serviceEndpoint"):
|
||||
return service["serviceEndpoint"].rstrip("/")
|
||||
raise ValueError(f"no PDS for {did}")
|
||||
|
||||
|
||||
def _download(url: str, site_url: str) -> bytes:
|
||||
"""
|
||||
The avatar's bytes (v2.13.1):
|
||||
- from StarPunk's own GoToSocial directly, as the crossposting client
|
||||
does: behind the same proxy it resolves to an internal address, which
|
||||
the SSRF-safe fetcher refuses;
|
||||
- Bluesky CDN avatars from the account's PDS (com.atproto.sync.getBlob),
|
||||
because the CDN refuses some servers' IPv4 addresses;
|
||||
- anything else through the SSRF-safe fetcher.
|
||||
"""
|
||||
from urllib.parse import quote, urlparse
|
||||
|
||||
import httpx
|
||||
|
||||
from starpunk import webmention_ssrf
|
||||
from starpunk.webmention_ssrf import user_agent
|
||||
|
||||
headers = {"User-Agent": user_agent(site_url)}
|
||||
own = _own_instance_host()
|
||||
if own and urlparse(url).hostname == own:
|
||||
with httpx.Client(timeout=10.0, transport=webmention_ssrf.TRANSPORT) as http:
|
||||
with http.stream("GET", url, headers=headers) as response:
|
||||
if response.is_redirect:
|
||||
# GoToSocial sends media it hasn't cached to the original
|
||||
# server: that one is fetched like any outside URL (v2.13.2)
|
||||
from urllib.parse import urljoin
|
||||
return _get(urljoin(url, response.headers["location"]), headers)
|
||||
if response.status_code >= 400:
|
||||
raise ValueError(f"HTTP {response.status_code}")
|
||||
data = b""
|
||||
for chunk in response.iter_bytes():
|
||||
data += chunk
|
||||
if len(data) > MAX_BYTES:
|
||||
raise ValueError("too large")
|
||||
return data
|
||||
match = BSKY_CDN_RE.match(url)
|
||||
if match:
|
||||
did, cid = match.groups()
|
||||
url = (f"{_pds(did, headers)}/xrpc/com.atproto.sync.getBlob"
|
||||
f"?did={quote(did, safe=':')}&cid={cid}")
|
||||
return _get(url, headers)
|
||||
|
||||
|
||||
def fill_missing(db_path, data_path, site_url: str, limit: int = 20) -> int:
|
||||
"""Save avatars of shown responses that have no copy yet. Returns how many were tried."""
|
||||
conn = sqlite3.connect(db_path)
|
||||
|
||||
+37
-8
@@ -64,7 +64,9 @@ class Harvest:
|
||||
"""What one check found. complete=False: some list was cut short."""
|
||||
responses: List[Response]
|
||||
complete: bool = True
|
||||
counts: Optional[Dict[str, int]] = None # Threads likes/reposts/quotes
|
||||
# Likes/reposts/quotes shown only as numbers: all of them on Threads
|
||||
# (its API doesn't say who); elsewhere, those by people who opted out
|
||||
counts: Optional[Dict[str, int]] = None
|
||||
|
||||
|
||||
# --- Text -----------------------------------------------------------------
|
||||
@@ -243,11 +245,27 @@ def _display_state(db, note_id: int) -> list:
|
||||
)]
|
||||
|
||||
|
||||
def store(db, note_id: int, target_url: str, origin: str, harvest: Harvest) -> None:
|
||||
def hidden_counts(harvest: Harvest) -> Dict[str, int]:
|
||||
"""
|
||||
Likes, reposts and quotes to show only as numbers: the silo's own counts
|
||||
when it gives no names (Threads), else those by people who opted out
|
||||
(v2.13.3: they're counted, not named)
|
||||
"""
|
||||
if harvest.counts is not None:
|
||||
return harvest.counts
|
||||
hidden = [r.kind for r in harvest.responses if _opted_out(r)]
|
||||
return {k: hidden.count(kind) for k, kind in
|
||||
(("likes", "like"), ("reposts", "repost"), ("quotes", "quote"))}
|
||||
|
||||
|
||||
def store(db, note_id: int, target_url: str, origin: str, harvest: Harvest,
|
||||
quiet: bool = False) -> None:
|
||||
"""
|
||||
Upsert a check's responses for one note and silo. With a complete
|
||||
harvest, that silo's responses for the note that weren't found are
|
||||
marked invalid. Responses from people who opted out are removed.
|
||||
marked invalid. Responses from people who opted out are removed (they
|
||||
are counted instead, see `hidden_counts`). With `quiet`, new responses
|
||||
are stored as already notified (ADR-074 Decision 5).
|
||||
"""
|
||||
from starpunk.webmention_processor import _snippet
|
||||
|
||||
@@ -273,8 +291,9 @@ def store(db, note_id: int, target_url: str, origin: str, harvest: Harvest) -> N
|
||||
INSERT INTO webmentions (
|
||||
source_url, target_url, target_note_id, mention_type, author_name, author_url,
|
||||
author_photo, content_snippet, validation_status, moderation_status,
|
||||
validated_at, source_published, origin, remote_id)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'valid', ?, CURRENT_TIMESTAMP, ?, ?, ?)
|
||||
validated_at, source_published, origin, remote_id, notified_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'valid', ?, CURRENT_TIMESTAMP, ?, ?, ?,
|
||||
CASE WHEN ? THEN CURRENT_TIMESTAMP END)
|
||||
ON CONFLICT(source_url, target_url) DO UPDATE SET
|
||||
target_note_id = excluded.target_note_id,
|
||||
mention_type = excluded.mention_type,
|
||||
@@ -291,7 +310,8 @@ def store(db, note_id: int, target_url: str, origin: str, harvest: Harvest) -> N
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
""",
|
||||
(r.source_url, target_url, note_id, r.kind, r.author_name or None, r.author_url or None,
|
||||
r.author_photo or None, snippet, moderation, r.published, origin, r.remote_id),
|
||||
r.author_photo or None, snippet, moderation, r.published, origin, r.remote_id,
|
||||
1 if quiet else 0),
|
||||
)
|
||||
if dropped:
|
||||
marks = ",".join("?" * len(dropped))
|
||||
@@ -357,8 +377,12 @@ def check(row, target) -> None:
|
||||
db = get_db(current_app)
|
||||
site = current_app.config["SITE_URL"].rstrip("/")
|
||||
harvest = target.client.responses(row["remote_id"], row["remote_url"] or "")
|
||||
store(db, row["note_id"], f"{site}/note/{row['note_slug']}", row["target"], harvest)
|
||||
_store_counts(db, row["id"], harvest.counts)
|
||||
# No notifications for history: a backfill, or a copy's first check on an
|
||||
# older note (e.g. one linked after the fact). ADR-074 Decision 5.
|
||||
quiet = bool(row["backfeed_backfill"]) or (
|
||||
row["backfeed_checked_at"] is None and _age_seconds(row["note_created"]) > DAY)
|
||||
store(db, row["note_id"], f"{site}/note/{row['note_slug']}", row["target"], harvest, quiet=quiet)
|
||||
_store_counts(db, row["id"], hidden_counts(harvest))
|
||||
|
||||
|
||||
def process_due(limit: int = 3) -> int:
|
||||
@@ -382,6 +406,11 @@ def process_due(limit: int = 3) -> int:
|
||||
if _is_denied(e):
|
||||
denied[row["target"]] = f"Needs {SCOPES.get(row['target'], 'read access')}: {e}"
|
||||
current_app.logger.error(f"Backfeed for {row['target']} stopped: {denied[row['target']]}")
|
||||
from starpunk import notifications
|
||||
site = current_app.config["SITE_URL"].rstrip("/")
|
||||
notifications.problem(current_app.config, current_app.config["DATABASE_PATH"],
|
||||
f"Backfeed for {SILO_NAMES.get(row['target'], row['target'])} stopped",
|
||||
denied[row["target"]], f"{site}/admin/webmentions")
|
||||
db.execute("UPDATE syndications SET backfeed_claimed_until = NULL WHERE id = ?", (row["id"],))
|
||||
db.commit()
|
||||
continue
|
||||
|
||||
@@ -149,6 +149,10 @@ def load_config(app, config_override=None):
|
||||
# Backfeed of responses to crossposts (v2.13.0, ADR-073)
|
||||
app.config["BACKFEED_ENABLED"] = os.getenv("BACKFEED_ENABLED", "false").lower() == "true"
|
||||
app.config["BACKFEED_MAX_AGE_DAYS"] = int(os.getenv("BACKFEED_MAX_AGE_DAYS", "90"))
|
||||
# Notifications through Apprise (v2.14.0, ADR-074)
|
||||
app.config["NOTIFY_URLS"] = os.getenv("NOTIFY_URLS", "")
|
||||
app.config["NOTIFY_EVENTS"] = os.getenv("NOTIFY_EVENTS", "reply,mention,quote,problems")
|
||||
app.config["NOTIFY_PRIORITY"] = os.getenv("NOTIFY_PRIORITY", "normal")
|
||||
|
||||
# Apply overrides if provided
|
||||
# CSRF protection for admin and consent forms (v2.11.0); on by default.
|
||||
|
||||
@@ -0,0 +1,236 @@
|
||||
"""
|
||||
Notifications through Apprise (v2.14.0, ADR-074)
|
||||
|
||||
The owner hears about new responses (received webmentions and backfeed
|
||||
alike) and about crossposting problems, on whatever service the Apprise
|
||||
URLs in NOTIFY_URLS point at (Gotify, ntfy, Pushover, email, an
|
||||
apprise-api server…).
|
||||
|
||||
Responses are sent by a sweep (`sweep`) in the webmention worker, which
|
||||
runs in one process at a time: each response with `notified_at` empty is
|
||||
sent once and marked. Likes, reposts and bookmarks are grouped per note.
|
||||
Failed sends are retried with backoff; responses still unsent after 24
|
||||
hours are dropped. Problems (`problem`) are sent at once, without retry.
|
||||
|
||||
Nothing here may break validation, crossposting or backfeed: every send is
|
||||
wrapped, and failures are only logged and shown in the admin.
|
||||
"""
|
||||
|
||||
import html
|
||||
import logging
|
||||
import re
|
||||
import sqlite3
|
||||
import time
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
from urllib.parse import parse_qsl, urlsplit
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
RESPONSE_EVENTS = ("reply", "mention", "quote", "like", "repost", "bookmark")
|
||||
EVENTS = RESPONSE_EVENTS + ("problems",)
|
||||
DEFAULT_EVENTS = "reply,mention,quote,problems"
|
||||
GROUPED = ("like", "repost", "bookmark")
|
||||
DROP_AFTER_HOURS = 24
|
||||
MAX_BACKOFF = 15 * 60
|
||||
SEND_TIMEOUT = 15
|
||||
|
||||
HEADINGS = {
|
||||
"reply": "↩ Reply from {who}",
|
||||
"mention": "💬 Mention from {who}",
|
||||
"quote": "❝ Quote from {who}",
|
||||
}
|
||||
GROUP_HEADINGS = {
|
||||
"like": ("♥", "like", "likes"),
|
||||
"repost": ("🔁", "repost", "reposts"),
|
||||
"bookmark": ("🔖", "bookmark", "bookmarks"),
|
||||
}
|
||||
|
||||
|
||||
# --- Settings ---------------------------------------------------------------------
|
||||
|
||||
def urls(config) -> List[str]:
|
||||
"""NOTIFY_URLS as a list (space- or comma-separated)"""
|
||||
return [u for u in re.split(r"[\s,]+", config.get("NOTIFY_URLS") or "") if u]
|
||||
|
||||
|
||||
def events(config) -> set:
|
||||
"""NOTIFY_EVENTS as a set of known event names"""
|
||||
chosen = {e.strip().lower() for e in (config.get("NOTIFY_EVENTS") or DEFAULT_EVENTS).split(",")}
|
||||
return chosen & set(EVENTS)
|
||||
|
||||
|
||||
def enabled(config) -> bool:
|
||||
return bool(urls(config))
|
||||
|
||||
|
||||
def with_priority(url: str, priority: str) -> str:
|
||||
"""The URL with `priority=` added, unless it sets one itself"""
|
||||
if not priority or any(k == "priority" for k, _ in parse_qsl(urlsplit(url).query)):
|
||||
return url
|
||||
return url + ("&" if "?" in url else "?") + "priority=" + priority
|
||||
|
||||
|
||||
# --- Sending ----------------------------------------------------------------------------
|
||||
|
||||
def _deliver(targets: List[str], title: str, body: str) -> Tuple[bool, str]:
|
||||
"""Send one message to every URL. Returns (all sent, error text)."""
|
||||
import apprise
|
||||
|
||||
sender = apprise.Apprise()
|
||||
bad = [u.split("://", 1)[0] + "://…" for u in targets if not sender.add(u)]
|
||||
if bad:
|
||||
return False, f"Not a usable Apprise URL: {', '.join(bad)}"
|
||||
with apprise.LogCapture(level=logging.WARNING, fmt="%(message)s") as log:
|
||||
result = sender.notify(body, title=title, body_format=apprise.NotifyFormat.MARKDOWN,
|
||||
timeout=SEND_TIMEOUT)
|
||||
return bool(result), log.getvalue().strip()[:500]
|
||||
|
||||
|
||||
def send(config, title: str, body: str) -> Tuple[bool, str]:
|
||||
"""Send to all NOTIFY_URLS at NOTIFY_PRIORITY. Never raises."""
|
||||
targets = [with_priority(u, config.get("NOTIFY_PRIORITY") or "normal") for u in urls(config)]
|
||||
if not targets:
|
||||
return False, "No NOTIFY_URLS set"
|
||||
try:
|
||||
ok, error = _deliver(targets, title, body)
|
||||
except Exception as e: # a broken service mustn't break the caller
|
||||
ok, error = False, f"{type(e).__name__}: {e}"
|
||||
if not ok:
|
||||
logger.warning(f"Notification '{title}' not sent: {error or 'unknown error'}")
|
||||
return ok, error
|
||||
|
||||
|
||||
def problem(config, db_path, title: str, detail: str, link: str) -> None:
|
||||
"""A crosspost or backfeed problem, sent at once if 'problems' is selected"""
|
||||
if not enabled(config) or "problems" not in events(config):
|
||||
return
|
||||
ok, error = send(config, f"⚠ {title}", f"{detail}\n\n[Open in StarPunk]({link})")
|
||||
_record(db_path, ok, error)
|
||||
|
||||
|
||||
def _record(db_path, ok: bool, error: str) -> None:
|
||||
"""Remember the last failure for the admin page (cleared by a success)"""
|
||||
try:
|
||||
conn = sqlite3.connect(db_path)
|
||||
try:
|
||||
conn.execute("INSERT INTO site_state (key, value) VALUES ('notify_last_error', ?) "
|
||||
"ON CONFLICT(key) DO UPDATE SET value = excluded.value",
|
||||
("" if ok else time.strftime("%Y-%m-%d %H:%M:%S UTC ", time.gmtime())
|
||||
+ (error or "unknown error"),))
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
except sqlite3.Error as e:
|
||||
logger.warning(f"Could not record notification result: {e}")
|
||||
|
||||
|
||||
def last_error(db) -> str:
|
||||
row = db.execute("SELECT value FROM site_state WHERE key = 'notify_last_error'").fetchone()
|
||||
return row[0] if row else ""
|
||||
|
||||
|
||||
# --- Messages -----------------------------------------------------------------------------
|
||||
|
||||
def _plain(snippet: Optional[str], limit: int = 300) -> str:
|
||||
text = html.unescape(re.sub(r"<[^>]+>", " ", snippet or ""))
|
||||
text = re.sub(r"\s+", " ", text).strip()
|
||||
return text if len(text) <= limit else text[:limit - 1].rsplit(" ", 1)[0] + "…"
|
||||
|
||||
|
||||
def _note_label(conn, note_id: int) -> str:
|
||||
from starpunk.notes import get_note
|
||||
|
||||
try:
|
||||
note = get_note(id=note_id, load_content=True)
|
||||
label = " ".join((note.title or "").split()) if note else ""
|
||||
except Exception:
|
||||
label = ""
|
||||
return (label[:57] + "…") if len(label) > 60 else (label or "a note")
|
||||
|
||||
|
||||
def _messages(rows, site_url: str, conn) -> List[Tuple[str, str, List[int]]]:
|
||||
"""(title, body, webmention ids) for a batch of responses"""
|
||||
site = site_url.rstrip("/")
|
||||
names = {"gotosocial": "GoToSocial", "bluesky": "Bluesky", "threads": "Threads"}
|
||||
messages, groups = [], {}
|
||||
for row in rows:
|
||||
via = names.get(row["origin"]) if row["origin"] != "webmention" else None
|
||||
who = (row["author_name"] or "someone") + (f" via {via}" if via else "")
|
||||
pending = row["moderation_status"] == "pending"
|
||||
link = (f"{site}/admin/webmentions/{row['id']}" if pending
|
||||
else f"{site}/note/{row['slug']}#responses")
|
||||
if row["mention_type"] in GROUPED:
|
||||
groups.setdefault((row["target_note_id"], row["mention_type"], row["slug"], pending), []).append(
|
||||
(row["id"], row["author_name"] or "someone", link))
|
||||
continue
|
||||
title = HEADINGS.get(row["mention_type"], "Response from {who}").format(who=who)
|
||||
if pending:
|
||||
title += " (awaiting moderation)"
|
||||
text = _plain(row["content_snippet"])
|
||||
body = (f"{text}\n\n" if text else "") + f"On “{_note_label(conn, row['target_note_id'])}”: [open]({link})"
|
||||
messages.append((title, body, [row["id"]]))
|
||||
for (note_id, kind, slug, pending), items in groups.items():
|
||||
icon, one, many = GROUP_HEADINGS[kind]
|
||||
n = len(items)
|
||||
title = f"{icon} {n} new {one if n == 1 else many} on “{_note_label(conn, note_id)}”"
|
||||
if pending:
|
||||
title += " (awaiting moderation)"
|
||||
people = ", ".join(name for _, name, _ in items[:5]) + (f" and {n - 5} more" if n > 5 else "")
|
||||
messages.append((title, f"{people}\n\n[open]({items[0][2]})", [i for i, _, _ in items]))
|
||||
return messages
|
||||
|
||||
|
||||
# --- Sweep ----------------------------------------------------------------------------------
|
||||
|
||||
class Sweeper:
|
||||
"""Sends new responses; one instance per webmention worker"""
|
||||
|
||||
def __init__(self):
|
||||
self._failures = 0
|
||||
self._next_try = 0.0
|
||||
|
||||
def run(self, config, db_path, site_url: str) -> int:
|
||||
"""Send what's due. Returns how many responses were sent."""
|
||||
if not enabled(config) or time.time() < self._next_try:
|
||||
return 0
|
||||
chosen = events(config)
|
||||
conn = sqlite3.connect(db_path)
|
||||
conn.row_factory = sqlite3.Row
|
||||
try:
|
||||
# Too old to be news (an outage, say): drop quietly
|
||||
dropped = conn.execute(
|
||||
f"""UPDATE webmentions SET notified_at = CURRENT_TIMESTAMP
|
||||
WHERE notified_at IS NULL
|
||||
AND received_at < datetime('now', '-{DROP_AFTER_HOURS} hours')""").rowcount
|
||||
if dropped:
|
||||
logger.warning(f"Dropped {dropped} notification(s) older than {DROP_AFTER_HOURS} hours")
|
||||
rows = conn.execute(
|
||||
"""
|
||||
SELECT w.*, n.slug FROM webmentions w JOIN notes n ON n.id = w.target_note_id
|
||||
WHERE w.notified_at IS NULL AND w.validation_status = 'valid'
|
||||
AND w.moderation_status IN ('approved', 'pending')
|
||||
ORDER BY w.id LIMIT 100
|
||||
"""
|
||||
).fetchall()
|
||||
skip = [r["id"] for r in rows if r["mention_type"] not in chosen]
|
||||
if skip:
|
||||
conn.execute(f"UPDATE webmentions SET notified_at = CURRENT_TIMESTAMP "
|
||||
f"WHERE id IN ({','.join('?' * len(skip))})", skip)
|
||||
conn.commit()
|
||||
due = [r for r in rows if r["mention_type"] in chosen]
|
||||
sent = 0
|
||||
for title, body, ids in _messages(due, site_url, conn):
|
||||
ok, error = send(config, title, body)
|
||||
_record(db_path, ok, error)
|
||||
if not ok:
|
||||
self._failures += 1
|
||||
self._next_try = time.time() + min(10 * 2 ** self._failures, MAX_BACKOFF)
|
||||
break
|
||||
self._failures = 0
|
||||
conn.execute(f"UPDATE webmentions SET notified_at = CURRENT_TIMESTAMP "
|
||||
f"WHERE id IN ({','.join('?' * len(ids))})", ids)
|
||||
conn.commit()
|
||||
sent += len(ids)
|
||||
return sent
|
||||
finally:
|
||||
conn.close()
|
||||
@@ -515,6 +515,7 @@ def webmentions():
|
||||
status_filter=status_filter,
|
||||
origin_filter=origin_filter,
|
||||
backfeed=backfeed.status(),
|
||||
notify=_notify_status(),
|
||||
page=page,
|
||||
total_pages=total_pages,
|
||||
user_me=g.me
|
||||
@@ -681,6 +682,34 @@ def revoke_token(token_id):
|
||||
return redirect(url_for("admin.tokens"))
|
||||
|
||||
|
||||
def _notify_status() -> dict:
|
||||
"""Notification settings and last error for the Webmentions page (v2.14.0)"""
|
||||
from starpunk import notifications
|
||||
from starpunk.database import get_db
|
||||
|
||||
return {
|
||||
"enabled": notifications.enabled(current_app.config),
|
||||
"events": sorted(notifications.events(current_app.config)),
|
||||
"priority": current_app.config.get("NOTIFY_PRIORITY") or "normal",
|
||||
"services": [u.split("://", 1)[0] for u in notifications.urls(current_app.config)],
|
||||
"last_error": notifications.last_error(get_db(current_app)),
|
||||
}
|
||||
|
||||
|
||||
@bp.route("/notifications/test", methods=["POST"])
|
||||
@require_auth
|
||||
def notifications_test():
|
||||
"""Send a test notification to every NOTIFY_URLS service (v2.14.0)"""
|
||||
from starpunk import notifications
|
||||
|
||||
ok, error = notifications.send(current_app.config, "StarPunk test notification",
|
||||
"Notifications from StarPunk are working.")
|
||||
notifications._record(current_app.config["DATABASE_PATH"], ok, error)
|
||||
flash("Test notification sent" if ok else f"Test notification failed: {error or 'unknown error'}",
|
||||
"success" if ok else "error")
|
||||
return redirect(url_for("admin.webmentions"))
|
||||
|
||||
|
||||
@bp.route("/backfeed/backfill", methods=["POST"])
|
||||
@require_auth
|
||||
def backfeed_backfill():
|
||||
|
||||
@@ -292,9 +292,23 @@ def index():
|
||||
object.__setattr__(note, '_cached_tags', tags)
|
||||
|
||||
attach_contexts(notes)
|
||||
attach_response_counts(notes)
|
||||
return render_template("index.html", notes=notes)
|
||||
|
||||
|
||||
def attach_response_counts(notes) -> None:
|
||||
"""Give listed notes their like, repost and reply counts (v2.13.4)"""
|
||||
counts = {}
|
||||
if current_app.config.get('WEBMENTION_ENABLED', False) and notes:
|
||||
try:
|
||||
from starpunk.webmention_queries import response_counts
|
||||
counts = response_counts([n.id for n in notes])
|
||||
except Exception as e:
|
||||
current_app.logger.warning(f"Could not count responses: {e}")
|
||||
for note in notes:
|
||||
object.__setattr__(note, 'response_counts', counts.get(note.id))
|
||||
|
||||
|
||||
def attach_contexts(notes) -> None:
|
||||
"""Give likes and reposts the fetched context of the post they point at"""
|
||||
from starpunk.webmention_queries import get_reply_context
|
||||
@@ -320,6 +334,7 @@ def likes():
|
||||
object.__setattr__(note, 'media', get_note_media(note.id))
|
||||
object.__setattr__(note, '_cached_tags', get_note_tags(note.id))
|
||||
attach_contexts(notes)
|
||||
attach_response_counts(notes)
|
||||
return render_template("likes.html", notes=notes)
|
||||
|
||||
|
||||
@@ -467,6 +482,7 @@ def tag(tag: str):
|
||||
media = get_note_media(note.id)
|
||||
object.__setattr__(note, 'media', media)
|
||||
attach_contexts(notes)
|
||||
attach_response_counts(notes)
|
||||
|
||||
return render_template(
|
||||
"tag.html",
|
||||
|
||||
@@ -1464,6 +1464,13 @@ def _fail(db, row, error: SyndicationError) -> None:
|
||||
f"Syndication {row['target']} for note {row['note_id']} failed "
|
||||
f"(attempt {attempts}{', giving up' if failed else ''}): {error}"
|
||||
)
|
||||
if failed: # ADR-074: tell the owner, once, when we give up
|
||||
from starpunk import notifications
|
||||
target = get_targets().get(row["target"])
|
||||
site = current_app.config["SITE_URL"].rstrip("/")
|
||||
notifications.problem(current_app.config, current_app.config["DATABASE_PATH"],
|
||||
f"Crosspost to {target.name if target else row['target']} failed",
|
||||
str(error)[:300], f"{site}/admin/edit/{row['note_id']}")
|
||||
|
||||
|
||||
def _target_title(url: Optional[str]) -> Optional[str]:
|
||||
|
||||
@@ -110,6 +110,47 @@ def get_webmentions_for_note(note_id: int) -> Dict[str, List[Dict[str, Any]]]:
|
||||
return grouped
|
||||
|
||||
|
||||
def response_counts(note_ids: List[int]) -> Dict[int, Dict[str, int]]:
|
||||
"""
|
||||
Likes, reposts and replies per note, for lists of notes (v2.13.4).
|
||||
|
||||
Shown responses (valid and approved) plus the counts silos give without
|
||||
names (Threads; people who opted out of backfeed) on synced crossposts.
|
||||
Notes with none are left out.
|
||||
"""
|
||||
if not note_ids:
|
||||
return {}
|
||||
db = get_db()
|
||||
marks = ','.join('?' * len(note_ids))
|
||||
counts: Dict[int, Dict[str, int]] = {}
|
||||
|
||||
def add(note_id, key, n):
|
||||
if n:
|
||||
counts.setdefault(note_id, {'likes': 0, 'reposts': 0, 'replies': 0})[key] += n
|
||||
|
||||
for row in db.execute(
|
||||
f"""
|
||||
SELECT target_note_id, mention_type, COUNT(*) FROM webmentions
|
||||
WHERE target_note_id IN ({marks}) AND validation_status = 'valid'
|
||||
AND moderation_status = 'approved' AND mention_type IN ('like', 'repost', 'reply')
|
||||
GROUP BY target_note_id, mention_type
|
||||
""",
|
||||
note_ids,
|
||||
):
|
||||
add(row[0], {'like': 'likes', 'repost': 'reposts', 'reply': 'replies'}[row[1]], row[2])
|
||||
for row in db.execute(
|
||||
f"""
|
||||
SELECT note_id, SUM(COALESCE(likes_count, 0)), SUM(COALESCE(reposts_count, 0))
|
||||
FROM syndications WHERE note_id IN ({marks}) AND state = 'synced'
|
||||
GROUP BY note_id
|
||||
""",
|
||||
note_ids,
|
||||
):
|
||||
add(row[0], 'likes', row[1])
|
||||
add(row[0], 'reposts', row[2])
|
||||
return counts
|
||||
|
||||
|
||||
def list_webmentions(
|
||||
status_filter: Optional[str] = None,
|
||||
page: int = 1,
|
||||
|
||||
@@ -83,7 +83,9 @@ class WebmentionWorker(threading.Thread):
|
||||
self._last_processed = None
|
||||
self._lock_file = None
|
||||
from starpunk.avatars import Upkeep
|
||||
from starpunk.notifications import Sweeper
|
||||
self._avatar_upkeep = Upkeep()
|
||||
self._notifier = Sweeper()
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
@@ -118,6 +120,11 @@ class WebmentionWorker(threading.Thread):
|
||||
# Local copies of response avatars (v2.13.0)
|
||||
self._avatar_upkeep.run(self.db_path, self.app.config['DATA_PATH'],
|
||||
self.site_url)
|
||||
# New responses to the owner (v2.14.0, ADR-074)
|
||||
try:
|
||||
self._notifier.run(self.app.config, self.db_path, self.site_url)
|
||||
except Exception as e:
|
||||
logger.error(f"Notification sweep failed: {e}", exc_info=True)
|
||||
|
||||
# Update last processed time
|
||||
if processed > 0:
|
||||
|
||||
+38
-50
@@ -343,63 +343,51 @@ small { display: block; margin-top: var(--spacing-xs); color: var(--color-text-l
|
||||
color: var(--color-text-light);
|
||||
}
|
||||
|
||||
/* Backfed responses and silo counts (v2.13.0) */
|
||||
.webmention-via,
|
||||
.silo-counts {
|
||||
/* Backfed responses (v2.13.0) */
|
||||
.webmention-via {
|
||||
font-size: 0.875rem;
|
||||
color: var(--color-text-light);
|
||||
}
|
||||
|
||||
/* Facepile */
|
||||
.facepile {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
/* Likes, reposts and bookmarks: counts with a hover list (v2.13.2) */
|
||||
.response-counts { display: flex; flex-wrap: wrap; gap: var(--spacing-md); margin-top: var(--spacing-sm); color: var(--color-text-light); font-size: 0.875rem; }
|
||||
.response-count { position: relative; display: inline-flex; align-items: center; gap: 0.3rem; padding-bottom: 0.4rem; cursor: default; }
|
||||
.response-count > svg { width: 1rem; height: 1rem; flex: none; }
|
||||
.response-count:hover, .response-count:focus-within { color: var(--color-text); }
|
||||
.response-count-like:hover > svg, .response-count-like:focus-within > svg { color: #e0245e; }
|
||||
.response-count-repost:hover > svg, .response-count-repost:focus-within > svg { color: #17bf63; }
|
||||
.response-card {
|
||||
display: none; position: absolute; left: 0; top: 100%; z-index: 10;
|
||||
flex-direction: column; gap: 0.4rem; min-width: 13rem; max-width: 20rem;
|
||||
padding: var(--spacing-sm); background: var(--color-bg-alt); border: 1px solid var(--color-border);
|
||||
border-radius: var(--border-radius); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
|
||||
}
|
||||
.response-count:hover .response-card, .response-count:focus-within .response-card { display: flex; }
|
||||
.response-card-title { font-weight: 600; color: var(--color-text); }
|
||||
.response-people { display: flex; flex-direction: column; gap: 0.35rem; max-height: 14rem; overflow-y: auto; }
|
||||
.response-person { display: flex; align-items: center; gap: 0.4rem; min-width: 0; line-height: 1.3; }
|
||||
.response-person .h-card { display: flex; min-width: 0; }
|
||||
.response-person .h-card a { display: inline-flex; align-items: center; gap: 0.4rem; color: var(--color-text); min-width: 0; }
|
||||
.response-person .p-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.response-person img { width: 20px; height: 20px; border-radius: 50%; object-fit: cover; flex: none; }
|
||||
.response-person .webmention-via { margin-left: auto; padding-left: 0.5rem; white-space: nowrap; }
|
||||
.response-anon { color: var(--color-text-light); }
|
||||
.response-elsewhere { display: block; margin-top: 0.15rem; padding-top: 0.4rem; border-top: 1px solid var(--color-border); color: var(--color-text-light); }
|
||||
.response-elsewhere:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
|
||||
.response-elsewhere a { color: var(--color-link); }
|
||||
|
||||
.facepile .face {
|
||||
display: block;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 50%;
|
||||
overflow: hidden;
|
||||
border: 2px solid var(--color-bg);
|
||||
margin-left: -8px;
|
||||
}
|
||||
/* A reply card opens the reply where it was posted (v2.13.4): its date link
|
||||
stretches over the card; the author link and links in the text stay on top */
|
||||
.webmention-reply { position: relative; }
|
||||
.webmention-reply .webmention-date::after { content: ""; position: absolute; inset: 0; }
|
||||
.webmention-reply .webmention-author a, .webmention-reply .e-content a { position: relative; z-index: 1; }
|
||||
.webmention-reply:hover { cursor: pointer; }
|
||||
|
||||
.facepile .face:first-child {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.facepile .face > .h-card,
|
||||
.facepile .face > .h-card > a {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.facepile .face img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.facepile .face-initial {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.facepile .face-overflow {
|
||||
margin-left: var(--spacing-xs);
|
||||
font-size: 0.875rem;
|
||||
color: var(--color-text-light);
|
||||
}
|
||||
/* Counts in lists of notes (v2.13.4) */
|
||||
.list-counts { display: inline-flex; gap: 0.6rem; color: var(--color-text-light); }
|
||||
.note-meta a.list-counts:hover { color: var(--color-text); text-decoration: none; }
|
||||
.list-count { display: inline-flex; align-items: center; gap: 0.2rem; }
|
||||
.list-count > svg { width: 0.85rem; height: 0.85rem; flex: none; }
|
||||
|
||||
/* Generic Mentions */
|
||||
.webmention-mention {
|
||||
|
||||
@@ -12,6 +12,22 @@
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{# Notifications (v2.14.0, ADR-074) #}
|
||||
{% if notify %}
|
||||
<section class="notify-status">
|
||||
<h3>Notifications</h3>
|
||||
{% if notify.enabled %}
|
||||
<p>Sending {{ notify.events|join(', ') }} to {{ notify.services|join(', ') }} at {{ notify.priority }} priority.</p>
|
||||
{% if notify.last_error %}<p class="flash flash-error">Last send failed: {{ notify.last_error }}</p>{% endif %}
|
||||
<form method="POST" action="{{ url_for('admin.notifications_test') }}"><input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<button type="submit" class="button">Send test notification</button>
|
||||
</form>
|
||||
{% else %}
|
||||
<p>Off. Set <code>NOTIFY_URLS</code> to one or more Apprise URLs to be notified of new responses.</p>
|
||||
{% endif %}
|
||||
</section>
|
||||
{% endif %}
|
||||
|
||||
{# Backfeed (v2.13.0, ADR-073) #}
|
||||
{% if backfeed and backfeed.enabled %}
|
||||
<section class="backfeed-status">
|
||||
|
||||
+6
-24
@@ -78,12 +78,16 @@
|
||||
{% endif %}
|
||||
</footer>
|
||||
|
||||
<div id="responses"></div>
|
||||
{{ responses.reactions(likes, reposts, replies, bookmarks, syndications, absolute_url_for('public.note', slug=note.slug)) }}
|
||||
|
||||
<nav class="note-nav">
|
||||
<a href="/">← All notes</a>
|
||||
</nav>
|
||||
|
||||
{# Webmentions section (v1.6.0 Phase 5) - only shown if approved webmentions exist #}
|
||||
{% if webmentions %}
|
||||
{# Webmentions section (v1.6.0 Phase 5): replies, quotes and mentions.
|
||||
Likes, reposts and bookmarks are the counts line above (v2.13.2). #}
|
||||
{% if replies or quotes or mentions %}
|
||||
<section class="webmentions">
|
||||
<h2>Responses</h2>
|
||||
|
||||
@@ -94,27 +98,6 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if likes %}
|
||||
<div class="webmention-group webmention-likes">
|
||||
<h3>{{ likes|length }} {{ 'Like' if likes|length == 1 else 'Likes' }}</h3>
|
||||
{{ responses.facepile(likes, 'u-like') }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if reposts %}
|
||||
<div class="webmention-group webmention-reposts">
|
||||
<h3>{{ reposts|length }} {{ 'Repost' if reposts|length == 1 else 'Reposts' }}</h3>
|
||||
{{ responses.facepile(reposts, 'u-repost') }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if bookmarks %}
|
||||
<div class="webmention-group webmention-bookmarks">
|
||||
<h3>{{ bookmarks|length }} {{ 'Bookmark' if bookmarks|length == 1 else 'Bookmarks' }}</h3>
|
||||
{{ responses.facepile(bookmarks, 'u-bookmark') }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if quotes %}
|
||||
<div class="webmention-group webmention-quotes">
|
||||
<h3>{{ quotes|length }} {{ 'Quote' if quotes|length == 1 else 'Quotes' }}</h3>
|
||||
@@ -130,6 +113,5 @@
|
||||
{% endif %}
|
||||
</section>
|
||||
{% endif %}
|
||||
{{ responses.silo_counts(syndications) }}
|
||||
</article>
|
||||
{% endblock %}
|
||||
@@ -1,6 +1,7 @@
|
||||
{# One note in a list (home, tag pages). v2.3.0 #}
|
||||
{% from "partials/media.html" import display_media %}
|
||||
{% from "partials/reaction.html" import reaction %}
|
||||
{% from "partials/responses.html" import list_counts %}
|
||||
{% macro note_preview(note, author) %}
|
||||
<article class="h-entry note-preview">
|
||||
{# Notes starting with a '# Heading' have a title (Q22; Note.has_title) #}
|
||||
@@ -37,6 +38,7 @@
|
||||
{% for tag in note.tags %}<a class="p-category" rel="tag" href="{{ url_for('public.tag', tag=tag.name) }}">{{ tag.display_name }}</a>{% endfor %}
|
||||
</span>
|
||||
{% endif %}
|
||||
{{ list_counts(note.response_counts if note.response_counts is defined else None, absolute_url_for('public.note', slug=note.slug)) }}
|
||||
{% if author %}
|
||||
{# Single-author site: keep the h-card for parsers, hide it from readers #}
|
||||
<span class="p-author h-card visually-hidden"><a class="p-name u-url" href="{{ author.url or author.me }}">{{ author.name or author.url or author.me }}</a></span>
|
||||
|
||||
@@ -41,22 +41,6 @@
|
||||
</article>
|
||||
{%- endmacro %}
|
||||
|
||||
{# Likes, reposts or bookmarks as a facepile; prop is u-like / u-repost / u-bookmark.
|
||||
Faces past `shown` are hidden on screen but kept for parsers. #}
|
||||
{% macro facepile(items, prop, shown=8) %}
|
||||
<div class="facepile">
|
||||
{% for wm in items %}
|
||||
<span class="face {{ prop }} h-cite"{% if loop.index > shown %} hidden{% endif %}>
|
||||
{{ author_card(wm, photo_size=32, show_name=False) }}
|
||||
<a class="u-url" href="{{ response_url(wm) }}" hidden>{{ response_time(wm) }}</a>
|
||||
</span>
|
||||
{% endfor %}
|
||||
{% if items|length > shown %}
|
||||
<span class="face-overflow">+{{ items|length - shown }} others</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
{%- endmacro %}
|
||||
|
||||
{# A post that mentions this note without replying; also quote posts (v2.13.0) #}
|
||||
{% macro mention(wm) %}
|
||||
<div class="webmention webmention-mention u-mention h-cite">
|
||||
@@ -68,12 +52,75 @@
|
||||
</div>
|
||||
{%- endmacro %}
|
||||
|
||||
{# Like, repost and quote counts a silo reports without saying who (Threads,
|
||||
v2.13.0). Plain text: these aren't people, so no u-like / h-cite. #}
|
||||
{% macro silo_counts(syndications) %}
|
||||
{% for s in syndications or [] if s.likes_count or s.reposts_count or s.quotes_count %}
|
||||
{% set parts = [] %}
|
||||
{% for n, one, many in [(s.likes_count, 'like', 'likes'), (s.reposts_count, 'repost', 'reposts'), (s.quotes_count, 'quote', 'quotes')] if n %}{% set _ = parts.append(n ~ ' ' ~ (one if n == 1 else many)) %}{% endfor %}
|
||||
<p class="silo-counts">On {{ s.name }}: {{ parts|join(' · ') }}</p>
|
||||
{# Likes, reposts, replies and bookmarks: one line of counts under the note,
|
||||
like other sites (v2.13.2). Hovering or focusing a count lists who, and
|
||||
offers the same action on the note's crossposts. Each action is an
|
||||
<indie-action> (https://indieweb.org/webactions) with those silo links as
|
||||
its fallback, so web action handlers can take over. Counts without names
|
||||
(all of Threads; elsewhere people who opted out, v2.13.3) are added to the
|
||||
total. The people stay in the
|
||||
markup as u-like / u-repost / u-bookmark h-cites. #}
|
||||
{% set ICONS = {
|
||||
'like': '<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z"/></svg>',
|
||||
'repost': '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M17 1l4 4-4 4"/><path d="M3 11V9a4 4 0 0 1 4-4h14"/><path d="M7 23l-4-4 4-4"/><path d="M21 13v2a4 4 0 0 1-4 4H3"/></svg>',
|
||||
'reply': '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 11.5a8.4 8.4 0 0 1-9 8.4 8.6 8.6 0 0 1-3.9-.9L3 21l1.9-5.1A8.4 8.4 0 0 1 12 3.1a8.4 8.4 0 0 1 9 8.4z"/></svg>',
|
||||
'bookmark': '<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M6 2h12a1 1 0 0 1 1 1v19l-7-4-7 4V3a1 1 0 0 1 1-1z"/></svg>',
|
||||
} %}
|
||||
{% set VERBS = {'like': 'Like', 'repost': 'Repost', 'reply': 'Reply'} %}
|
||||
|
||||
{% macro reaction(kind, items, prop, anon, one, many, copies=[], permalink='', people=True) %}
|
||||
{% set ns = namespace(total=items|length) %}
|
||||
{% for name, n in anon %}{% set ns.total = ns.total + n %}{% endfor %}
|
||||
{% set verb = VERBS.get(kind) %}
|
||||
{% if ns.total or (verb and copies) %}
|
||||
<span class="response-count response-count-{{ kind }}" tabindex="0">
|
||||
{{ ICONS[kind]|safe }}{% if ns.total %}<span class="response-count-n">{{ ns.total }}</span>{% endif %}<span class="visually-hidden"> {{ ns.total }} {{ one if ns.total == 1 else many }}</span>
|
||||
<span class="response-card" role="tooltip">
|
||||
{% if ns.total %}<span class="response-card-title">{{ ns.total }} {{ one if ns.total == 1 else many }}</span>{% endif %}
|
||||
{% if (people and items) or anon %}
|
||||
<span class="response-people">
|
||||
{% if people %}
|
||||
{% for wm in items %}
|
||||
<span class="response-person {{ prop }} h-cite">{{ author_card(wm, photo_size=20) }}{% if wm.via %}<span class="webmention-via">{{ wm.via }}</span>{% endif %}<a class="u-url" href="{{ response_url(wm) }}" hidden>{{ response_time(wm) }}</a></span>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% for name, n in anon %}<span class="response-anon">{{ '+' if items and people else '' }}{{ n }} on {{ name }}</span>{% endfor %}
|
||||
</span>
|
||||
{% endif %}
|
||||
{% if verb and copies %}
|
||||
<indie-action class="response-elsewhere" do="{{ kind }}" with="{{ permalink }}">{{ verb }} on {% for s in copies %}<a href="{{ s.remote_url }}" rel="noopener">{{ s.name }}</a>{% if not loop.last %} · {% endif %}{% endfor %}</indie-action>
|
||||
{% endif %}
|
||||
</span>
|
||||
</span>
|
||||
{% endif %}
|
||||
{%- endmacro %}
|
||||
|
||||
{% macro reactions(likes, reposts, replies, bookmarks, syndications, permalink) %}
|
||||
{% set anon_likes, anon_reposts = [], [] %}
|
||||
{% for s in syndications or [] %}
|
||||
{% if s.likes_count %}{% set _ = anon_likes.append((s.name, s.likes_count)) %}{% endif %}
|
||||
{% if s.reposts_count %}{% set _ = anon_reposts.append((s.name, s.reposts_count)) %}{% endif %}
|
||||
{% endfor %}
|
||||
{% set copies = (syndications or [])|selectattr('remote_url')|list %}
|
||||
{% if copies or likes or reposts or replies or bookmarks or anon_likes or anon_reposts %}
|
||||
<div class="response-counts">
|
||||
{{ reaction('like', likes or [], 'u-like', anon_likes, 'like', 'likes', copies, permalink) }}
|
||||
{{ reaction('repost', reposts or [], 'u-repost', anon_reposts, 'repost', 'reposts', copies, permalink) }}
|
||||
{# Replies are listed in full below; here just the count and where to reply #}
|
||||
{{ reaction('reply', replies or [], '', [], 'reply', 'replies', copies, permalink, people=False) }}
|
||||
{{ reaction('bookmark', bookmarks or [], 'u-bookmark', [], 'bookmark', 'bookmarks') }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{%- endmacro %}
|
||||
|
||||
{# Compact like / repost / reply counts for lists of notes (v2.13.4); links
|
||||
to the note's responses. `counts` is from webmention_queries.response_counts. #}
|
||||
{% macro list_counts(counts, permalink) %}
|
||||
{% if counts %}
|
||||
<a class="list-counts" href="{{ permalink }}#responses">
|
||||
{%- for key, kind, one, many in [('likes', 'like', 'like', 'likes'), ('reposts', 'repost', 'repost', 'reposts'), ('replies', 'reply', 'reply', 'replies')] if counts[key] -%}
|
||||
<span class="list-count list-count-{{ kind }}" title="{{ counts[key] }} {{ one if counts[key] == 1 else many }}">{{ ICONS[kind]|safe }}{{ counts[key] }}<span class="visually-hidden"> {{ one if counts[key] == 1 else many }}</span></span>
|
||||
{%- endfor -%}
|
||||
</a>
|
||||
{% endif %}
|
||||
{%- endmacro %}
|
||||
+78
-1
@@ -334,7 +334,11 @@ def test_note_page_shows_backfed_responses_quotes_and_counts(app, client, web):
|
||||
page = app.test_client().get(f"/note/{note.slug}").get_data(as_text=True)
|
||||
assert "via GoToSocial" in page
|
||||
assert "1 Quote" in page and "Look at this" in page
|
||||
assert 'class="silo-counts">On GoToSocial: 12 likes · 1 repost<' in page
|
||||
# Likes and reposts are a counts line (v2.13.2): named likes plus the silo's anonymous count
|
||||
assert '<span class="response-count-n">13</span>' in page and "+12 on GoToSocial" in page
|
||||
assert '<span class="response-count-n">1</span>' in page
|
||||
assert f'<indie-action class="response-elsewhere" do="like" with="{SITE}/note/{note.slug}">' in page
|
||||
assert f'Like on <a href="{COPY}"' in page
|
||||
assert 'src="/avatars/' in page and 'src="https://cdn.example/a.png"' not in page
|
||||
|
||||
|
||||
@@ -562,3 +566,76 @@ def test_threads_avatar_kept_while_its_copy_exists(app, client, web):
|
||||
client.harvest = Harvest([again])
|
||||
run(app)
|
||||
assert rows(app, note.id)[0]["author_photo"] == "https://cdn.example/p.jpg?sig=1"
|
||||
|
||||
|
||||
def test_avatars_from_own_gotosocial_and_bluesky_pds(app, web, monkeypatch):
|
||||
"""v2.13.1: own GoToSocial may resolve to a private address; Bluesky CDN avatars come from the PDS"""
|
||||
did, cid = "did:plc:abc123", "bafkreiabc"
|
||||
web.files[f"{GTS}/fileserver/a/avatar.png"] = png()
|
||||
web.files[f"https://plc.directory/{did}"] = json.dumps(
|
||||
{"service": [{"id": "#atproto_pds", "serviceEndpoint": "https://pds.example"}]}).encode()
|
||||
web.files[f"https://pds.example/xrpc/com.atproto.sync.getBlob?did={did}&cid={cid}"] = png("blue")
|
||||
real_resolve = resolve
|
||||
monkeypatch.setattr("starpunk.webmention_ssrf.socket.getaddrinfo",
|
||||
lambda host, *a, **k: [(2, 1, 6, "", ("172.20.0.5", 0))]
|
||||
if host == "social.example" else real_resolve(host))
|
||||
data = app.config["DATA_PATH"]
|
||||
with app.app_context():
|
||||
assert avatars.fetch(data, f"{GTS}/fileserver/a/avatar.png", SITE)
|
||||
assert avatars.fetch(data, f"https://cdn.bsky.app/img/avatar/plain/{did}/{cid}@jpeg", SITE)
|
||||
# Other private addresses stay blocked
|
||||
web.files["https://internal.example/a.png"] = png()
|
||||
monkeypatch.setattr("starpunk.webmention_ssrf.socket.getaddrinfo",
|
||||
lambda host, *a, **k: [(2, 1, 6, "", ("10.0.0.5", 0))])
|
||||
assert not avatars.fetch(data, "https://internal.example/a.png", SITE)
|
||||
|
||||
|
||||
def test_own_gotosocial_redirect_to_remote_avatar_is_followed(app, web, monkeypatch):
|
||||
"""v2.13.2: GoToSocial redirects uncached remote media to the original server"""
|
||||
class Redirecting(FakeWeb):
|
||||
def __call__(self, request):
|
||||
url = f"{request.url.scheme}://{request.headers['host']}{request.url.raw_path.decode()}"
|
||||
if url == f"{GTS}/fileserver/x/avatar.jpeg":
|
||||
return httpx.Response(302, headers={"location": "https://remote.example/avatar.jpeg"})
|
||||
return super().__call__(request)
|
||||
|
||||
fake = Redirecting()
|
||||
fake.files["https://remote.example/avatar.jpeg"] = png()
|
||||
monkeypatch.setattr("starpunk.webmention_ssrf.TRANSPORT", httpx.MockTransport(fake))
|
||||
with app.app_context():
|
||||
assert avatars.fetch(app.config["DATA_PATH"], f"{GTS}/fileserver/x/avatar.jpeg", SITE)
|
||||
|
||||
|
||||
def test_people_who_opt_out_are_counted_not_named(app, client):
|
||||
"""v2.13.3: likes and reposts by people who opted out add to the totals anonymously"""
|
||||
note, sid = crossposted(app)
|
||||
shy = like(5, opted_out=True)
|
||||
client.harvest = Harvest([like(1), shy, like(6, bio="#nobot"),
|
||||
Response(kind="repost", source_url=f"{COPY}#reposted-by-7", remote_id="7",
|
||||
author_name="Quiet", author_bio="#nobridge")])
|
||||
run(app)
|
||||
with app.app_context():
|
||||
s = get_db(app).execute("SELECT likes_count, reposts_count FROM syndications WHERE id = ?",
|
||||
(sid,)).fetchone()
|
||||
assert (s["likes_count"], s["reposts_count"]) == (2, 1)
|
||||
assert [r["source_url"] for r in rows(app, note.id)] == [like(1).source_url]
|
||||
page = app.test_client().get(f"/note/{note.slug}").get_data(as_text=True)
|
||||
assert '<span class="response-count-n">3</span>' in page and "+2 on GoToSocial" in page
|
||||
assert "Liker 5" not in page and "Quiet" not in page
|
||||
|
||||
|
||||
def test_home_page_shows_counts(app, client):
|
||||
"""v2.13.4: lists of notes show like, repost and reply counts, linking to the responses"""
|
||||
note, sid = crossposted(app)
|
||||
with app.app_context():
|
||||
quiet = create_note(content="Nobody saw this", published=True)
|
||||
client.harvest = Harvest([like(1), like(2), reply(3)])
|
||||
run(app)
|
||||
with app.app_context():
|
||||
get_db(app).execute("UPDATE syndications SET likes_count = 1, reposts_count = 2 WHERE id = ?", (sid,))
|
||||
get_db(app).commit()
|
||||
page = app.test_client().get("/").get_data(as_text=True)
|
||||
assert f'href="{SITE}/note/{note.slug}#responses"' in page
|
||||
assert 'title="3 likes"' in page and 'title="2 reposts"' in page and 'title="1 reply"' in page
|
||||
assert f"/note/{quiet.slug}#responses" not in page
|
||||
assert 'id="responses"' in app.test_client().get(f"/note/{note.slug}").get_data(as_text=True)
|
||||
@@ -0,0 +1,251 @@
|
||||
"""
|
||||
Tests for notifications through Apprise (v2.14.0, ADR-074)
|
||||
|
||||
Most tests replace the Apprise send with a recorder. One sends for real
|
||||
through Apprise to a local HTTP server (json://), to check the wiring.
|
||||
"""
|
||||
|
||||
import json
|
||||
import sqlite3
|
||||
import threading
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
|
||||
import pytest
|
||||
|
||||
from starpunk import backfeed, create_app, notifications, syndication
|
||||
from starpunk.backfeed import Harvest, Response
|
||||
from starpunk.database import get_db
|
||||
from starpunk.notes import create_note
|
||||
|
||||
SITE = "https://blog.example.com"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sent(monkeypatch):
|
||||
messages = []
|
||||
|
||||
def deliver(targets, title, body):
|
||||
messages.append({"targets": targets, "title": title, "body": body})
|
||||
return True, ""
|
||||
|
||||
monkeypatch.setattr(notifications, "_deliver", deliver)
|
||||
return messages
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def app(tmp_path):
|
||||
data = tmp_path / "data"
|
||||
app = create_app({
|
||||
"TESTING": True, "SITE_URL": SITE, "ADMIN_ME": "https://example.com",
|
||||
"SESSION_SECRET": "x", "DATA_PATH": data, "NOTES_PATH": data / "notes",
|
||||
"DATABASE_PATH": data / "starpunk.db",
|
||||
"NOTIFY_URLS": "gotifys://gotify.example.com/TOKEN, ntfys://topic?priority=max",
|
||||
"NOTIFY_EVENTS": "reply,mention,like,problems",
|
||||
"NOTIFY_PRIORITY": "high",
|
||||
"CSRF_ENABLED": False,
|
||||
})
|
||||
yield app
|
||||
syndication._client_cache.clear()
|
||||
backfeed.denied.clear()
|
||||
|
||||
|
||||
def note(app, content="Hello world", age_days=0):
|
||||
with app.app_context():
|
||||
n = create_note(content=content, published=True)
|
||||
if age_days:
|
||||
get_db(app).execute("UPDATE notes SET created_at = datetime('now', ?) WHERE id = ?",
|
||||
(f"-{age_days} days", n.id))
|
||||
get_db(app).commit()
|
||||
return n
|
||||
|
||||
|
||||
def response(app, n, kind, name, source, moderation="approved", origin="webmention",
|
||||
snippet=None, hours_ago=0):
|
||||
with app.app_context():
|
||||
get_db(app).execute(
|
||||
"INSERT INTO webmentions (source_url, target_url, target_note_id, mention_type, author_name, "
|
||||
"validation_status, moderation_status, origin, content_snippet, received_at) "
|
||||
"VALUES (?, ?, ?, ?, ?, 'valid', ?, ?, ?, datetime('now', ?))",
|
||||
(source, f"{SITE}/note/{n.slug}", n.id, kind, name, moderation, origin, snippet,
|
||||
f"-{hours_ago} hours"))
|
||||
get_db(app).commit()
|
||||
|
||||
|
||||
def sweep(app, sweeper=None):
|
||||
sweeper = sweeper or notifications.Sweeper()
|
||||
with app.app_context():
|
||||
return sweeper.run(app.config, app.config["DATABASE_PATH"], SITE), sweeper
|
||||
|
||||
|
||||
def unsent(app):
|
||||
with app.app_context():
|
||||
return [r[0] for r in get_db(app).execute(
|
||||
"SELECT source_url FROM webmentions WHERE notified_at IS NULL ORDER BY id")]
|
||||
|
||||
|
||||
# --- Settings --------------------------------------------------------------------------
|
||||
|
||||
def test_settings():
|
||||
config = {"NOTIFY_URLS": " a://x,b://y c://z ", "NOTIFY_EVENTS": "Reply, likes, problems"}
|
||||
assert notifications.urls(config) == ["a://x", "b://y", "c://z"]
|
||||
assert notifications.events(config) == {"reply", "problems"}, "unknown names are ignored"
|
||||
assert notifications.events({}) == {"reply", "mention", "quote", "problems"}
|
||||
assert notifications.with_priority("gotifys://h/T", "high") == "gotifys://h/T?priority=high"
|
||||
assert notifications.with_priority("ntfys://t?tags=x", "5") == "ntfys://t?tags=x&priority=5"
|
||||
assert notifications.with_priority("ntfys://t?priority=max", "low") == "ntfys://t?priority=max"
|
||||
|
||||
|
||||
# --- Sweep -------------------------------------------------------------------------------------
|
||||
|
||||
def test_new_responses_are_sent_once_and_likes_grouped(app, sent):
|
||||
n = note(app, "Starpunk now supports backfeeds")
|
||||
response(app, n, "reply", "Ana", "https://a.example/r", origin="bluesky",
|
||||
snippet="<p>Great & useful!</p>")
|
||||
response(app, n, "like", "Bob", "https://b.example/l")
|
||||
response(app, n, "like", "Cy", "https://c.example/l")
|
||||
response(app, n, "repost", "Dee", "https://d.example/rp") # not selected
|
||||
response(app, n, "mention", "Eve", "https://e.example/m", moderation="pending")
|
||||
count, _ = sweep(app)
|
||||
assert count == 4
|
||||
titles = [m["title"] for m in sent]
|
||||
assert "↩ Reply from Ana via Bluesky" in titles
|
||||
assert "💬 Mention from Eve (awaiting moderation)" in titles
|
||||
assert "♥ 2 new likes on “Starpunk now supports backfeeds”" in titles
|
||||
reply = next(m for m in sent if m["title"].startswith("↩"))
|
||||
assert reply["body"].startswith("Great & useful!")
|
||||
assert f"({SITE}/note/{n.slug}#responses)" in reply["body"]
|
||||
mention = next(m for m in sent if m["title"].startswith("💬"))
|
||||
assert f"{SITE}/admin/webmentions/" in mention["body"], "pending ones link to moderation"
|
||||
assert all(t.endswith("priority=high") or t.endswith("priority=max") for t in sent[0]["targets"])
|
||||
assert unsent(app) == []
|
||||
sent.clear()
|
||||
assert sweep(app)[0] == 0 and sent == [], "nothing is sent twice"
|
||||
|
||||
|
||||
def test_failed_send_is_retried_with_backoff(app, monkeypatch):
|
||||
calls = []
|
||||
monkeypatch.setattr(notifications, "_deliver", lambda t, ti, b: (calls.append(ti), (False, "boom"))[1])
|
||||
n = note(app)
|
||||
response(app, n, "reply", "Ana", "https://a.example/r")
|
||||
count, sweeper = sweep(app)
|
||||
assert count == 0 and unsent(app) == ["https://a.example/r"]
|
||||
assert sweep(app, sweeper)[0] == 0 and len(calls) == 1, "waits before retrying"
|
||||
with app.app_context():
|
||||
assert "boom" in notifications.last_error(get_db(app))
|
||||
sweeper._next_try = 0
|
||||
monkeypatch.setattr(notifications, "_deliver", lambda t, ti, b: (True, ""))
|
||||
assert sweep(app, sweeper)[0] == 1
|
||||
with app.app_context():
|
||||
assert notifications.last_error(get_db(app)) == ""
|
||||
|
||||
|
||||
def test_old_unsent_responses_are_dropped(app, sent):
|
||||
n = note(app)
|
||||
response(app, n, "reply", "Ana", "https://a.example/r", hours_ago=30)
|
||||
assert sweep(app)[0] == 0 and sent == [] and unsent(app) == []
|
||||
|
||||
|
||||
def test_off_without_urls(app, sent):
|
||||
app.config["NOTIFY_URLS"] = ""
|
||||
n = note(app)
|
||||
response(app, n, "reply", "Ana", "https://a.example/r")
|
||||
assert sweep(app)[0] == 0 and unsent(app) == ["https://a.example/r"]
|
||||
|
||||
|
||||
def test_backfill_and_late_first_checks_are_quiet(app, sent):
|
||||
class Client:
|
||||
config_token = "t"
|
||||
def responses(self, remote_id, remote_url, cap=1000):
|
||||
return Harvest([Response(kind="reply", source_url=f"{remote_url}/reply", remote_id="r",
|
||||
author_name="Ana", content_html="<p>hi</p>")])
|
||||
def maintain(self):
|
||||
pass
|
||||
|
||||
app.config.update(GOTOSOCIAL_URL="https://social.example", GOTOSOCIAL_ACCESS_TOKEN="t",
|
||||
BACKFEED_ENABLED=True)
|
||||
syndication._client_cache["https://social.example"] = Client()
|
||||
fresh, old = note(app, "New"), note(app, "Old", age_days=10)
|
||||
with app.app_context():
|
||||
for n, url in ((fresh, "https://social.example/1"), (old, "https://social.example/2")):
|
||||
get_db(app).execute("INSERT INTO syndications (note_id, target, enabled, remote_id, remote_url, "
|
||||
"state) VALUES (?, 'gotosocial', 1, 'x', ?, 'synced')", (n.id, url))
|
||||
get_db(app).commit()
|
||||
backfeed.process_due()
|
||||
assert unsent(app) == ["https://social.example/1/reply"], "only the new note's reply is news"
|
||||
|
||||
|
||||
# --- Problems and admin ----------------------------------------------------------------------------
|
||||
|
||||
def test_problems(app, sent):
|
||||
with app.app_context():
|
||||
notifications.problem(app.config, app.config["DATABASE_PATH"], "Crosspost to Bluesky failed",
|
||||
"HTTP 400", f"{SITE}/admin/edit/1")
|
||||
assert sent[0]["title"] == "⚠ Crosspost to Bluesky failed"
|
||||
assert "HTTP 400" in sent[0]["body"] and "/admin/edit/1" in sent[0]["body"]
|
||||
app.config["NOTIFY_EVENTS"] = "reply"
|
||||
with app.app_context():
|
||||
notifications.problem(app.config, app.config["DATABASE_PATH"], "x", "y", "z")
|
||||
assert len(sent) == 1, "not selected: not sent"
|
||||
|
||||
|
||||
def test_final_crosspost_failure_notifies(app, sent):
|
||||
n = note(app)
|
||||
app.config.update(GOTOSOCIAL_URL="https://social.example", GOTOSOCIAL_ACCESS_TOKEN="t")
|
||||
with app.app_context():
|
||||
cur = get_db(app).execute("INSERT INTO syndications (note_id, target, enabled, state, attempts) "
|
||||
"VALUES (?, 'gotosocial', 1, 'pending', 0)", (n.id,))
|
||||
get_db(app).commit()
|
||||
row = get_db(app).execute("SELECT * FROM syndications WHERE id = ?", (cur.lastrowid,)).fetchone()
|
||||
syndication._fail(get_db(app), row, syndication.SyndicationError("temporary", permanent=False))
|
||||
assert sent == [], "a retry is coming: no message"
|
||||
syndication._fail(get_db(app), row, syndication.SyndicationError("HTTP 422 bad", permanent=True))
|
||||
assert sent and sent[0]["title"] == "⚠ Crosspost to GoToSocial failed"
|
||||
|
||||
|
||||
def test_admin_status_and_test_button(app, sent):
|
||||
from starpunk.auth import create_session
|
||||
|
||||
with app.test_request_context():
|
||||
token = create_session("https://example.com")
|
||||
browser = app.test_client()
|
||||
browser.set_cookie("starpunk_session", token)
|
||||
page = browser.get("/admin/webmentions").get_data(as_text=True)
|
||||
assert "Sending like, mention, problems, reply to gotifys, ntfys at high priority" in page
|
||||
page = browser.post("/admin/notifications/test", follow_redirects=True).get_data(as_text=True)
|
||||
assert "Test notification sent" in page and sent[-1]["title"] == "StarPunk test notification"
|
||||
|
||||
|
||||
# --- Real Apprise -------------------------------------------------------------------------------------
|
||||
|
||||
def test_apprise_delivers_markdown_to_a_service(app):
|
||||
received = []
|
||||
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
def do_POST(self):
|
||||
received.append(json.loads(self.rfile.read(int(self.headers["Content-Length"]))))
|
||||
self.send_response(200)
|
||||
self.end_headers()
|
||||
|
||||
def log_message(self, *args):
|
||||
pass
|
||||
|
||||
server = HTTPServer(("127.0.0.1", 0), Handler)
|
||||
threading.Thread(target=server.handle_request, daemon=True).start()
|
||||
app.config["NOTIFY_URLS"] = f"json://127.0.0.1:{server.server_port}/"
|
||||
ok, error = notifications.send(app.config, "Title", "Body with [a link](https://x.example)")
|
||||
server.server_close()
|
||||
assert ok, error
|
||||
assert received[0]["title"] == "Title" and "a link" in received[0]["message"]
|
||||
app.config["NOTIFY_URLS"] = "notaservice://nope"
|
||||
ok, error = notifications.send(app.config, "t", "b")
|
||||
assert not ok and "Not a usable Apprise URL" in error
|
||||
|
||||
|
||||
def test_migration_021_marks_history(tmp_path):
|
||||
from pathlib import Path
|
||||
|
||||
conn = sqlite3.connect(tmp_path / "db")
|
||||
conn.execute("CREATE TABLE webmentions (id INTEGER PRIMARY KEY, source_url TEXT)")
|
||||
conn.execute("INSERT INTO webmentions (source_url) VALUES ('https://old.example')")
|
||||
conn.executescript((Path(__file__).parent.parent / "migrations" / "021_notifications.sql").read_text())
|
||||
assert conn.execute("SELECT notified_at IS NOT NULL FROM webmentions").fetchone()[0] == 1
|
||||
Reference in new issue
Block a user