diff --git a/README.md b/README.md index 0421f6a..1faecda 100644 --- a/README.md +++ b/README.md @@ -92,14 +92,21 @@ Imports run in the background in the `worker` service. The page shows progress, Unlike live scrobbles, imports keep plays of any age. They still skip rows with no artist or track, and plays dated in the future. Plays already in your history are skipped, so importing again is safe. -## Sharing on the fediverse (in development) +## Sharing on the fediverse Users can make their profile findable from Mastodon and other fediverse apps as `@name@`, and be followed: - Follows are accepted automatically, or wait for approval if the user turns that on. - The **Followers** page lists requests, followers and blocked accounts, with approve, decline, remove, block and unblock. -Posts (weekly summaries, milestones, now playing) are still being built; see `docs/design/activitypub.md`. Federation is tested in CI against a real GoToSocial server (`scripts/interop/run.sh`). +Once someone follows, the **Sharing** page's **What to post** section controls what they see: + +- **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`. + +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. It's **off unless the server enables it**, and then **off for each user** until they switch it on under **Sharing**. To enable it: diff --git a/docs/design/activitypub-phase3.md b/docs/design/activitypub-phase3.md index 245ad30..cfe57e3 100644 --- a/docs/design/activitypub-phase3.md +++ b/docs/design/activitypub-phase3.md @@ -1,5 +1,13 @@ # ActivityPub phase 3: posts +**Status: done** on `feature/activitypub` (`bc717c2` … `860d4d0`). The GoToSocial interop test now covers posts too: a weekly summary reaches a follower's home timeline as `private` with the expected content, and disappears from it when deleted. As with phases 1-2, a manual pass with a real Mastodon account through a tunnel is still to do before merging. + +Where this differed from the plan: + +- **A top-10 entry needs a real top 10 first.** With fewer than `TOP_N` distinct artists, every first play of a new artist would trivially "enter the top 10" — caught by a test that used the real (unpatched) thresholds instead of always overriding them down for speed. Nothing is posted until a user actually has that many distinct artists. +- **`post_now()` is a separate path from the normal check.** `flask federation post-weekly --now` and the Sharing page's preview both need the week still *in progress*, not the last one whose Monday-09:00 gate has passed; they share the posting logic (`_post_for_window`) with the normal `check_and_post`, but compute a different window. +- **The Note's `url` needed the username, not just the post's id.** `post.html` (the UI page a browser lands on) has no other way to know whose post to look up; caught while wiring up the UI, not by a test written against the plan. + This implements phase 3 of [activitypub.md](activitypub.md): **weekly summaries** and **milestones**. Now playing is phase 4. It builds on [phase 2](activitypub-phase2.md): followers, signed delivery and retries. **Outcome:** diff --git a/src/scrobbler/federation/README.md b/src/scrobbler/federation/README.md index 98925e5..cfd8b90 100644 --- a/src/scrobbler/federation/README.md +++ b/src/scrobbler/federation/README.md @@ -60,18 +60,58 @@ Every ActivityPub ID is built from `FEDERATION_BASE_URL`, never from the incomin | `keys.py` | Key pairs, created once and encrypted at rest | | `sharing.py` | Per-user settings, and who is sharing | | `ids.py` | Our ActivityPub ids, all from `FEDERATION_BASE_URL` | -| `web.py` | The endpoints other servers call | +| `web.py` | The endpoints other servers call, including a paged outbox and individual posts | | `api.py` and `schemas.py` | `/api/v1/federation/*` for the web UI | | `openapi.py` | OpenAPI descriptions of `web.py`'s endpoints | | `metrics.py` | Federation's own Prometheus metrics | +| `cli.py` | `flask federation ...` admin commands | +| `publishing/` | Posts: shared publish/delete machinery, and one module per kind (see below) | + +## Publishing + +`publishing/base.py` is the only place that knows how to actually post: build the +`Note`/`Create`, store it, address it from the user's current visibility, and fan it out +to accepted followers' inboxes. It's idempotent (one row per `(user, kind:key)`, via +`federation_posts`' unique constraint) and used for both publishing and deleting. + +Each *kind* of post is its own small module that only decides **when** to post and what +the text says, then calls into `base.py`: + +- `publishing/weekly.py`: once a week (`check_and_post`/`check_all`, the + `federation.weekly` worker task), for the Monday–Sunday week whose posting gate has + passed. `post_now()` instead posts the week still in progress immediately, ignoring the + gate — used by `flask federation post-weekly --user --now` and `preview()` (a + read-only variant for the Sharing page's live preview, never stored). +- `publishing/milestones.py`: scrobble-count, artist-plays and top-10-entry thresholds, + each posted once. A live scrobble queues a `FederationPendingCheck` row (collapsing + repeats), drained by the `federation.milestones` worker task. `set_baseline()` marks + 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. + +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`. ## Worker tasks -`federation.inbox` (process received activities), `federation.deliver` (send queued ones), `federation.inbox.maintenance` (re-queue stalled, prune after 30 days) and `federation.gauges` (queue and follower gauges). All are registered only when federation is on. +`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. ## Interop -`scripts/interop/run.sh` runs Scrobbler against a real GoToSocial server on a private `.test` network and checks the whole follow life cycle. CI runs it 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. +`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. ## Migrations