Files
Scrobbler/src/scrobbler/federation/ids.py
T
mattandClaude Sonnet 5 b16ba116c4
CI / validate-monitoring (push) Successful in 8s
CI / lint (push) Successful in 13s
CI / federation-interop (push) Successful in 1m1s
CI / test (push) Successful in 2m26s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 6s
Publishing core: post, fan out, delete (phase 3, step 4)
federation/publishing/base.py:
- publish(user_id, username, kind, key, text=, html=): idempotent —
  refuses (returns None, doesn't post) if the user has stopped sharing
  or a post with that key already exists, including when two worker
  passes race (caught as a duplicate-key error at commit, not raised).
  Builds Note + Create addressed from the user's current visibility,
  stores both, and fans out one delivery per distinct accepted
  follower's inbox (shared inbox preferred).
- delete_post(user_id, username, post): sends Delete(Tombstone) to the
  same followers and tombstones the row; a no-op if already deleted.
  Addressed by the post's own visibility at the time it was posted,
  not the user's current setting.
- delete_all_for(user_id, username): deletes every live post, for
  turning sharing off.

Wired into PATCH /settings: turning sharing off now deletes every live
post *before* rejecting followers (reject_all removes the followers
that accepted_inboxes() needs). The phase 2 farewell-actor mechanism
already covers these deliveries with no changes, since it just checks
for any pending delivery on the user's activities.

Small supporting changes: activities.store() made public (used from
publishing now, not just activities.py's own narrow helpers);
followers.accepted_inboxes() for fan-out; ids.py gains
followers_url/note_url/post_page_url; sharing.settings_for()'s unsaved
default object now sets every field a caller might read, not just the
ones the old callers happened to need.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
2026-09-26 11:51:06 +01:00

51 lines
1.4 KiB
Python

"""Our ActivityPub IDs, all built from FEDERATION_BASE_URL (never the request)."""
from flask import current_app
def base_url() -> str:
return current_app.extensions["federation"].base_url
def actor_id(username: str) -> str:
return f"{base_url()}/users/{username}"
def followers_url(username: str) -> str:
return f"{actor_id(username)}/followers"
def key_id(username: str) -> str:
return f"{actor_id(username)}#main-key"
def instance_actor_id() -> str:
return f"{base_url()}/actor"
def instance_key_id() -> str:
return f"{instance_actor_id()}#main-key"
def activity_url(activity_uuid: str) -> str:
return f"{base_url()}/activities/{activity_uuid}"
def note_url(username: str, post_uuid: str) -> str:
"""The Note's ActivityPub id (served at /users/<u>/posts/<uuid>)."""
return f"{actor_id(username)}/posts/{post_uuid}"
def post_page_url(username: str, post_uuid: str) -> str:
"""Where a browser following the Note's `url` lands, in the web UI."""
return f"{current_app.config['UI_BASE_URL']}/post.html?id={post_uuid}"
def username_from_actor_id(uri: str | None) -> str | None:
"""`<base>/users/<name>` -> name; None for anything else."""
prefix = f"{base_url()}/users/"
if not uri or not uri.startswith(prefix):
return None
name = uri[len(prefix) :]
return name if name and "/" not in name and "#" not in name and "?" not in name else None