diff --git a/docs/design/activitypub-phase3.md b/docs/design/activitypub-phase3.md new file mode 100644 index 0000000..245ad30 --- /dev/null +++ b/docs/design/activitypub-phase3.md @@ -0,0 +1,184 @@ +# ActivityPub phase 3: posts + +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:** + +- A user who shares gets two kinds of post, delivered to their followers: a summary of the past week, every Monday morning in their own time zone, and occasional milestone posts. +- Posts are **followers only by default**, following the user's visibility setting. +- Each kind can be switched off, and any post can be deleted. Turning sharing off deletes the posts from followers' servers. +- Existing history never produces posts retroactively. + +Everything is in `scrobbler.federation` except one small addition to the core stats service (§1), and the boundary tests keep holding. + +## 1. Core: stats over a date range + +- `services.stats` gains top artists, top tracks and play counts for an explicit window (`start`, `end`). Today it only knows the rolling periods (`7day` and so on). +- The existing functions keep working, re-expressed on top of the window version. This is a core change and is tested like one. Federation uses it through the public service, as the boundary rules require. + +## 2. Settings and data (migration on the `federation` branch) + +- **`federation_settings` gains:** + - `timezone`: an IANA name such as `Europe/London`, validated with `zoneinfo`. The Sharing page fills it in from the browser the first time. + - `post_weekly_summary`: default on. + - `post_milestones`: default on. +- **`federation_posts`**, one row per post: + - user, `kind` (`weekly` or `milestone`) + - `key`, unique per user, e.g. `weekly:2026-W39` or `milestone:scrobbles:10000` + - the Note's UUID, the visibility it was sent with, plain-text and HTML content + - `created_at`, and `deleted_at` (a tombstone) + + The unique key makes posting **idempotent**: a worker restart or a repeated check can never post twice. +- **`federation_milestone_marks`**: user plus key, with `posted` true or false. It records thresholds already passed, including ones deliberately *not* posted (see §5). +- **`federation_pending_checks`**: user, `since`, `reason`. It's a small queue, filled by event receivers (§5), so receivers never do real work inside a scrobble request. + +## 3. Vocabulary (pure: `protocol/vocab.py`) + +- **`note(...)`**: a `Note` with: + - `id`, `attributedTo`, `content` (HTML) plus `contentMap` (`{"en": …}`) + - `published`, `url` (the UI post page) + - `to` and `cc` from the visibility setting + - `tag` (`Hashtag` objects: `#Scrobbler`, and `#NowPlaying` in phase 4) + - `sensitive: false` +- **`create(...)`**: `Create` wrapping the Note, with the same addressing. +- **`delete(...)`**: `Delete` whose object is a `Tombstone` of the Note (the same shape Mastodon sends). +- **`ordered_collection_page(...)`**, used for outbox paging. +- **Addressing** comes from one function (`protocol/addressing.py`), unit-tested for each visibility: + - followers only: `to` followers, no `cc` + - unlisted: `to` followers, `cc` Public + - public: `to` Public, `cc` followers +- The HTML uses only tags Mastodon keeps (`p`, `br`, `strong`, `em`, `ol`, `li`), and every artist and track name is escaped. A formatting test covers awkward names (`