Page the outbox and serve individual posts (phase 3, step 7)
CI / validate-monitoring (push) Successful in 8s
CI / federation-interop (push) Successful in 1m1s
CI / lint (push) Successful in 1m10s
CI / test (push) Successful in 2m47s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 5s
CI / validate-monitoring (push) Successful in 8s
CI / federation-interop (push) Successful in 1m1s
CI / lint (push) Successful in 1m10s
CI / test (push) Successful in 2m47s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 5s
GET /users/<u>/outbox is now a real OrderedCollection pointing at paged OrderedCollectionPages of 20 Creates, newest first - public and unlisted posts only, since it's unauthenticated. Adds publishing.outbox_page() for the query and publishing.find_by_note_id() to look a post up by its Note's id (the two ActivityPub ids a post has - the wrapping Create's and the embedded Note's - were already generated independently in publish(); finding by the Note's id reuses the existing JSONB-path query pattern already established by activities.undo_block(), rather than adding a new column just for this lookup). GET /users/<u>/posts/<uuid> serves that Note for public and unlisted posts; followers-only and deleted posts 404 (they reach followers by delivery instead); a browser without an ActivityPub Accept is redirected to the UI post page unconditionally, before any lookup, matching actor()'s existing reasoning that a 404-vs-302 difference must never be usable to probe which posts exist. Documents both endpoints in federation/openapi.py and regenerates docs/openapi.json (test_every_api_route_is_documented already enforces this on every new federation route, so it can't wait for the docs step at the end of the phase). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
This commit is contained in:
1 parent
6fd028d108
commit
d4f3607eef
6 files changed
+308
-11
No files matched your search
@@ -18,12 +18,54 @@ from scrobbler.federation.models import FederationActivity, FederationPost
|
||||
from scrobbler.federation.protocol import addressing, vocab
|
||||
|
||||
DEFAULT_TAGS = ("Scrobbler",)
|
||||
OUTBOX_PAGE_SIZE = 20
|
||||
LISTED_VISIBILITIES = ("public", "unlisted") # followers-only posts aren't listed unauthenticated
|
||||
|
||||
|
||||
def _now() -> datetime:
|
||||
return datetime.now(UTC)
|
||||
|
||||
|
||||
def _listed(user_id: int):
|
||||
return (
|
||||
FederationPost.user_id == user_id,
|
||||
FederationPost.deleted_at.is_(None),
|
||||
FederationPost.visibility.in_(LISTED_VISIBILITIES),
|
||||
)
|
||||
|
||||
|
||||
def outbox_page(
|
||||
user_id: int, page: int, per_page: int = OUTBOX_PAGE_SIZE
|
||||
) -> tuple[list[dict], int]:
|
||||
"""Create documents for a user's outbox: public and unlisted posts only, newest
|
||||
first, paged. `page` is 1-based."""
|
||||
conditions = _listed(user_id)
|
||||
total = db.session.scalar(
|
||||
db.select(db.func.count()).select_from(FederationPost).filter(*conditions)
|
||||
)
|
||||
rows = db.session.scalars(
|
||||
db.select(FederationActivity)
|
||||
.join(FederationPost, FederationPost.activity_id == FederationActivity.id)
|
||||
.filter(*conditions)
|
||||
.order_by(FederationActivity.created_at.desc())
|
||||
.limit(per_page)
|
||||
.offset((page - 1) * per_page)
|
||||
).all()
|
||||
return [row.document for row in rows], total
|
||||
|
||||
|
||||
def find_by_note_id(user_id: int, note_id: str) -> FederationPost | None:
|
||||
"""The post whose Note has this id (the URL served at /users/<u>/posts/<uuid>)."""
|
||||
return db.session.scalar(
|
||||
db.select(FederationPost)
|
||||
.join(FederationActivity, FederationActivity.id == FederationPost.activity_id)
|
||||
.filter(
|
||||
FederationPost.user_id == user_id,
|
||||
FederationActivity.document["object"]["id"].as_string() == note_id,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def has_post(user_id: int, kind: str, key: str) -> bool:
|
||||
"""Whether a post with this (user, kind, key) already exists (posted or since
|
||||
deleted). Lets a caller skip expensive work — computing stats, say — before deciding
|
||||
|
||||
Reference in new issue
Block a user