Docs for phase 4: now playing (step 8)
CI / validate-monitoring (push) Successful in 9s
CI / lint (push) Successful in 12s
CI / federation-interop (push) Successful in 1m41s
CI / test (push) Successful in 3m23s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 6s
CI / validate-monitoring (push) Successful in 9s
CI / lint (push) Successful in 12s
CI / federation-interop (push) Successful in 1m41s
CI / test (push) Successful in 3m23s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 6s
README: the Sharing page's Now playing section, its three modes and their throttles. federation/README.md: now_playing.py added to the publishing plug-ins list (with a note on why it's not quite the same shape as weekly.py/milestones.py - a periodic scan covering both the profile push and the opt-in post, rather than an event receiver), actors.py added to the layout table, and the worker tasks / interop sections updated for federation.now_playing and the new profile-field check. docs/design/activitypub-phase4.md marked done, with the two points where implementation diverged from the written plan (the key-hashing fix and the now_playing_mode privacy gate). docs/openapi.json unchanged - still current from step 4. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
This commit is contained in:
1 parent
9883111fa1
commit
9f7ada682c
3 files changed
+39
-14
No files matched your search
@@ -104,9 +104,15 @@ Once someone follows, the **Sharing** page's **What to post** section controls w
|
||||
- **Weekly summary**: play count and top artist(s), posted once a week (Monday 09:00 in the user's own time zone, for the Monday–Sunday week that just ended). A live preview on the same page shows what it would say so far.
|
||||
- **Milestones**: total scrobbles, an artist's plays, and a new entry into the all-time top 10 — each posted once, the first time it's reached. History already on file when sharing is turned on, or added by an import, is never posted about retroactively.
|
||||
|
||||
Both are on by default and can be switched off independently. Posts use the same visibility as the profile (followers only by default, or unlisted/public); the **Posts** page lists a user's own posts with delete (sends a `Delete` to whoever received it). "Now playing" isn't posted yet; see `docs/design/activitypub.md`.
|
||||
Both are on by default and can be switched off independently. Posts use the same visibility as the profile (followers only by default, or unlisted/public); the **Posts** page lists a user's own posts with delete (sends a `Delete` to whoever received it).
|
||||
|
||||
Federation is tested in CI against a real GoToSocial server (`scripts/interop/run.sh`), including that a posted weekly summary reaches a follower's timeline with the right content and visibility, and disappears from it when deleted.
|
||||
The Sharing page's **Now playing** section is a separate, three-way choice:
|
||||
|
||||
- **Off** (default): nothing shown or posted.
|
||||
- **Show on my profile**: a "Now playing: *Track* by Artist" field on the profile, refreshed at most every 5 minutes while something's playing and cleared a few minutes after it stops. A `GET` of the profile always shows the truth right now; the push is just so already-following servers don't have to ask.
|
||||
- **Show on my profile and post**: the profile field, plus a post for each track played 30 seconds or more, at most one every 30 minutes, with the previous now-playing post deleted once the new one is confirmed published.
|
||||
|
||||
Federation is tested in CI against a real GoToSocial server (`scripts/interop/run.sh`), including that a posted weekly summary reaches a follower's timeline with the right content and visibility and disappears from it when deleted, and that turning now playing on updates the field GoToSocial has cached for the profile.
|
||||
|
||||
It's **off unless the server enables it**, and then **off for each user** until they switch it on under **Sharing**. To enable it:
|
||||
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
# ActivityPub phase 4: now playing
|
||||
|
||||
**Status: done** on `feature/activitypub` (`7d86bad` … `9883111`). The GoToSocial interop test now covers now playing too: turning it on updates the "Now playing" field GoToSocial has cached for the profile, via the periodic `Update(Person)` push - not just a fresh fetch showing the live truth, which was already covered by the actor route's own tests. As with phases 1-3, a manual pass with a real Mastodon account through a tunnel is still to do before merging.
|
||||
|
||||
Where this differed from the plan:
|
||||
|
||||
- **The now-playing key had to be hashed, not raw.** `artist\x1ftrack\x1fstarted_at` was going straight into `federation_posts.key` (`VARCHAR(64)`), which real track and artist names routinely overflow. Caught by the first Postgres-backed test that used a real track name, not by anything in the plan itself.
|
||||
- **`now_playing_field()` needed its own privacy gate.** It read core's `now_playing` table (populated for every user regardless of federation settings) without checking `now_playing_mode` itself, so a user who'd never turned the feature on at all would still leak what they were listening to if a caller forgot to gate it externally. Found while designing the periodic push task, not by a test written against the plan - the existing tests happened to never combine "something playing" with "mode off". Fixed by moving the gate inside `now_playing_field()` itself, so there's exactly one place that can get this wrong.
|
||||
|
||||
This implements phase 4 of [activitypub.md](activitypub.md): **now playing**, the last of the "still open" decisions there. It builds on [phase 3](activitypub-phase3.md): publishing, delivery and the web UI for posts.
|
||||
|
||||
Chosen (of the doc's three options): **profile field, plus opt-in posts** — the profile field is what a user gets as soon as they turn now playing on at all; posts are a further, separate opt-in on top of that, matching the doc's own "profile field mode, then optional posts" framing.
|
||||
|
||||
@@ -65,6 +65,7 @@ Every ActivityPub ID is built from `FEDERATION_BASE_URL`, never from the incomin
|
||||
| `openapi.py` | OpenAPI descriptions of `web.py`'s endpoints |
|
||||
| `metrics.py` | Federation's own Prometheus metrics |
|
||||
| `cli.py` | `flask federation ...` admin commands |
|
||||
| `actors.py` | Builds a user's actor document body; shared by the live `GET /users/<u>` route and the now-playing `Update(Person)` push, so both render the same shape |
|
||||
| `publishing/` | Posts: shared publish/delete machinery, and one module per kind (see below) |
|
||||
|
||||
## Publishing
|
||||
@@ -88,30 +89,41 @@ the text says, then calls into `base.py`:
|
||||
every threshold already passed without posting, called when a user turns sharing on
|
||||
and after an import finishes, so old history never produces a burst of "milestone"
|
||||
posts.
|
||||
- `publishing/now_playing.py`: not quite the same shape as the other two, since it
|
||||
covers two things at once - a throttled `Update(Person)` push for the profile field
|
||||
(`actors.py` owns the live version shown on a plain `GET`) and, opt-in, a post per
|
||||
track played 30+ seconds. Both are driven by one periodic scan
|
||||
(`federation.now_playing`, every 30 seconds) rather than an event receiver: the
|
||||
throttle windows (5 and 30 minutes) are far longer than the poll interval, and there's
|
||||
no history to react to retroactively the way milestones does.
|
||||
|
||||
Adding a third kind (e.g. now playing) means adding another module here with the same
|
||||
shape — decide when, build the text, call `publishing.publish()` — not touching
|
||||
`base.py`.
|
||||
Adding a fourth kind means adding another module here with the same shape as
|
||||
`weekly.py`/`milestones.py` - decide when, build the text, call `publishing.publish()`
|
||||
- not touching `base.py`.
|
||||
|
||||
## Worker tasks
|
||||
|
||||
`federation.inbox` (process received activities), `federation.deliver` (send queued
|
||||
ones), `federation.inbox.maintenance` (re-queue stalled, prune after 30 days),
|
||||
`federation.gauges` (queue and follower gauges), `federation.milestones` (drain pending
|
||||
milestone checks) and `federation.weekly` (check every sharing user for a due weekly
|
||||
summary, every 15 minutes). All are registered only when federation is on.
|
||||
milestone checks), `federation.weekly` (check every sharing user for a due weekly
|
||||
summary, every 15 minutes) and `federation.now_playing` (push profile updates and posts
|
||||
for users with it on, every 30 seconds). All are registered only when federation is on.
|
||||
|
||||
## Interop
|
||||
|
||||
`scripts/interop/run.sh` runs Scrobbler against a real GoToSocial server on a private
|
||||
`.test` network. `scripts/interop/gotosocial_interop.py` checks the whole follow life
|
||||
cycle, then `run.sh` seeds a scrobble, runs `flask federation post-weekly --now` directly
|
||||
in the `api` container, and runs the driver a second time (`--check-posts`) to confirm
|
||||
the post reaches GoToSocial's home timeline with the right content and `private`
|
||||
(followers-only) visibility, and disappears from it once deleted. CI runs the whole
|
||||
thing on every push. GoToSocial 0.22.1 ignores a Reject of an already-accepted follow (a
|
||||
TODO in its code, fixed on its main branch), so that one check on its side is skipped
|
||||
until a release includes the fix.
|
||||
cycle, then `run.sh` seeds a scrobble and a now-playing track, runs
|
||||
`flask federation post-weekly --now` directly in the `api` container, and runs the
|
||||
driver a second time (`--check-posts`) to confirm: the post reaches GoToSocial's home
|
||||
timeline with the right content and `private` (followers-only) visibility and
|
||||
disappears from it once deleted; and, with now playing turned on, GoToSocial's own
|
||||
stored copy of the account (not a fresh `resolve()` fetch) picks up a "Now playing"
|
||||
field from the periodic `Update(Person)` push. CI runs the whole thing on every push.
|
||||
GoToSocial 0.22.1 ignores a Reject of an already-accepted follow (a TODO in its code,
|
||||
fixed on its main branch), so that one check on its side is skipped until a release
|
||||
includes the fix.
|
||||
|
||||
## Migrations
|
||||
|
||||
|
||||
Reference in new issue
Block a user