CI / validate-monitoring (push) Successful in 14s
CI / lint (push) Successful in 21s
CI / federation-interop (push) Successful in 1m21s
CI / test (push) Successful in 4m2s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 6s
Sharing page gets a "Now playing" section: off / show on profile / show on profile and post, as a single choice matching the settings column - generalised sharing.js's visibility-only radio-group handling to a small RADIO_GROUPS list so now_playing_mode reuses the same fill/ save logic rather than adding a second special case. Public profile API and profile.html gain a live "now playing" field, sourced from the same actors.now_playing_text() the actor document uses and gated the same way (now_playing_mode off means never showing it, whatever's actually playing). Refactored actors.py along the way: now_playing_field() takes settings directly and does its own off-mode gating, rather than build_document() doing it externally - one place decides whether the field is shown, reused by the actor document, the push Update, and now the public profile API. Verified by hand in a real browser: settings round-trip through the Sharing page's new radio group, the public profile page shows "Now playing: Reckoner by Radiohead" once now_playing_mode is on, and the raw actor document (curl, Accept: application/activity+json) carries the same PropertyValue attachment. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
60 lines
2.5 KiB
Python
60 lines
2.5 KiB
Python
"""Actor document building (actors.py): shared by the live GET /users/<u> route and the
|
|
now-playing Update(Person) push."""
|
|
|
|
from scrobbler.federation import actors, sharing
|
|
from scrobbler.federation.protocol import vocab
|
|
from scrobbler.services.scrobbles import TrackInput, update_now_playing
|
|
|
|
URLS = vocab.actor_urls(
|
|
"https://scrobble.test", "alice", "https://scrobble.test/profile.html?u=alice"
|
|
)
|
|
|
|
|
|
def test_now_playing_text_is_none_when_nothing_is_playing(fed_ctx, user):
|
|
assert actors.now_playing_text(user) is None
|
|
|
|
|
|
def test_now_playing_text_shows_the_current_track(fed_ctx, user):
|
|
update_now_playing(user, TrackInput(artist="Radiohead", track="Reckoner"))
|
|
assert actors.now_playing_text(user) == "Reckoner by Radiohead"
|
|
|
|
|
|
def test_now_playing_field_respects_the_mode(fed_ctx, user):
|
|
update_now_playing(user, TrackInput(artist="Radiohead", track="Reckoner"))
|
|
off = sharing.settings_for(user.id)
|
|
assert actors.now_playing_field(user, off) == []
|
|
|
|
sharing.update(user.id, {"enabled": True, "now_playing_mode": "profile"})
|
|
on = sharing.settings_for(user.id)
|
|
assert actors.now_playing_field(user, on) == [("Now playing", "Reckoner by Radiohead")]
|
|
|
|
|
|
def test_build_document_includes_the_now_playing_field(fed_ctx, user):
|
|
sharing.update(
|
|
user.id,
|
|
{"enabled": True, "display_name": "Alice", "bio": "Hi.", "now_playing_mode": "profile"},
|
|
)
|
|
update_now_playing(user, TrackInput(artist="Radiohead", track="Reckoner"))
|
|
settings = sharing.settings_for(user.id)
|
|
doc = actors.build_document(URLS, user, settings)
|
|
assert doc["attachment"] == [
|
|
{"type": "PropertyValue", "name": "Now playing", "value": "Reckoner by Radiohead"}
|
|
]
|
|
|
|
|
|
def test_build_document_has_no_now_playing_field_when_idle(fed_ctx, user):
|
|
sharing.update(user.id, {"enabled": True, "now_playing_mode": "profile"})
|
|
settings = sharing.settings_for(user.id)
|
|
doc = actors.build_document(URLS, user, settings)
|
|
assert doc["attachment"] == []
|
|
|
|
|
|
def test_build_document_never_shows_now_playing_when_the_mode_is_off(fed_ctx, user):
|
|
"""now_playing_mode defaults to off; core's now_playing table is populated for every
|
|
user regardless, so a user who's never turned this on must never leak it."""
|
|
sharing.update(user.id, {"enabled": True})
|
|
update_now_playing(user, TrackInput(artist="Radiohead", track="Reckoner"))
|
|
settings = sharing.settings_for(user.id)
|
|
doc = actors.build_document(URLS, user, settings)
|
|
assert doc["attachment"] == []
|