Proposal + design + specs + tasks for the social layer. Adds a `follows` relation (local + federated via ActivityPub), Follow buttons on public profiles, and a `/feed` route showing public activities from followed users. Capabilities: - New: social-follows (the graph + /feed) - Modified: public-profiles (Follow button + counts) - Modified: journal-landing (Feed link on signed-in dashboard) Design picks: - Pull-based feed (no fan-out-on-write) — fine at trails.cool scale - follows keyed by actor IRI, local denorm FK for join perf - Fedify wires Follow/Accept/Undo; we handle the DB side - Remote activity ingestion via polling (not push) — tolerates our downtime without losing activities Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
5 KiB
5 KiB
1. Schema
- 1.1 Add
followstable topackages/db/src/schema/journal.ts:id UUID PK,follower_id TEXT NOT NULL REFERENCES users,followed_actor_iri TEXT NOT NULL(forward-compatible with federation),followed_user_id TEXT REFERENCES users(always populated for local follows in this change),accepted_at TIMESTAMPTZ(always set tonow()in this change but kept nullable for future Pending state),created_at TIMESTAMPTZ DEFAULT now(). Unique(follower_id, followed_actor_iri). Indexes(follower_id, created_at DESC)and(followed_actor_iri) - 1.2 Add
profile_visibility TEXT NOT NULL DEFAULT 'public'('public' | 'private') tojournal.users. Existing rows pick up the default (= public), preserving current effective behavior for everyone - 1.3 Add a small helper
localActorIri(username)returninghttps://{DOMAIN}/users/{username}to keep IRI construction consistent across the codebase - 1.4 Run
pnpm db:pushlocally and confirm migration is clean (no prompts, no ambiguity) - 1.5 Update the privacy manifest to document the
followsrelation (which user follows whom on this instance, when) and the newprofile_visibilitysetting
2. Follow / unfollow API
- 2.1 Add
follow.server.tswithfollowUser(followerId, targetUsername)andunfollowUser(followerId, targetUsername)that resolve the local target, refuse ifprofile_visibility = 'private'or self-follow, write/delete the row, and return the new state - 2.2
POST /api/users/:username/followroute: session-bound, callsfollowUser, returns 200 with new state or 4xx on refusal - 2.3
POST /api/users/:username/unfollowroute: session-bound, callsunfollowUser, returns 200 with new state - 2.4 Unit tests: follow/unfollow happy path, refusal for private profile, self-follow rejected, idempotent follow/unfollow
3. Follower / following collections
- 3.1 Queries for follower list and following list of a given user, paginated (50/page), reverse-chron on
accepted_at - 3.2 Routes
/users/:username/followersand/users/:username/followingrendering paginated lists with display name + handle + small profile link - 3.3 Query + UI for follower and following counts on
/users/:username
4. Social feed
- 4.1 Query
listSocialFeed(followerId, limit, cursor)joiningfollows→activities, returning rows whereaccepted_at IS NOT NULLANDa.visibility = 'public', reverse-chronological bycreated_at - 4.2 Route
/feed(signed-in only; redirects to/auth/loginwhen anonymous) rendering the aggregated cards; reuse the existing activity-card component from the home visitor feed - 4.3 Empty state: "You're not following anyone yet" with a link to the instance public feed at
/ - 4.4 Register the route in
apps/journal/app/routes.ts - 4.5 Add a "Feed" link to the signed-in nav + the personal dashboard header next to "New Activity"
5. Profile page + visibility
- 5.1 Follow / Unfollow button component — state pulled from the viewer's session +
followsrow, action submits to the new API route - 5.2 Integrate on
/users/:usernameabove the public route/activity list; hide for the profile owner - 5.3 Follower/following count display linking to the new collection pages
- 5.4 Update
/users/:usernameloader to gate onprofile_visibility = 'public'AND has-public-content (preserve indistinguishable 404) - 5.5 Add a "Profile visibility" toggle (Public / Private) to
/settings/profile, with a one-line explainer of what each mode does - 5.6 Owner-only redirect or "your profile isn't public yet" view for owners whose profile would 404 to visitors
6. Testing
- 6.1 Unit tests for
listSocialFeedquery: only follows ofaccepted_at IS NOT NULL, onlypublicactivities, pagination boundary - 6.2 E2E: register two local users, A follows B, B posts a public activity → A sees it on
/feed; B posts a private activity → A does not - 6.3 E2E: Follow button transitions (not following → Follow → Unfollow → not following), profile counts update
- 6.4 E2E:
/feedredirects anonymous visitors to/auth/login - 6.5 E2E: empty
/feedrenders the empty state and link to public feed - 6.6 E2E (profile_visibility): owner flips to private →
/users/:usernamereturns 404 even with public content, the Follow button vanishes for any prospective follower. Owner flips back to public → previous behavior restored
7. Rollout
- 7.1 Schema ships via
drizzle-kit push --force— additive only, no row backfill needed (column defaults handle existing users) - 7.2 Post-deploy: smoke-follow bruno (demo-bot) from a test account, confirm bruno's public activity appears on
/feed - 7.3 (Follow-up change)
social-federationadds Fedify, actor objects, signed inbox/outbox, remote follow + ingestion. Thefollowsschema in this change supports those without migration - 7.4 (Follow-up change) Consider a "Local" tab alongside the Following feed that surfaces the instance public feed for signed-in users — not in this change