Web UI for now playing (phase 4, step 5)
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
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
This commit is contained in:
1 parent
515acae233
commit
f04e53a972
10 files changed
+98
-20
No files matched your search
@@ -13,23 +13,28 @@ from scrobbler.services.scrobbles import get_now_playing
|
||||
NOW_PLAYING_FIELD = "Now playing"
|
||||
|
||||
|
||||
def now_playing_field(user) -> list[tuple[str, str]]:
|
||||
"""The actor's now-playing `PropertyValue` field. Empty when nothing's playing
|
||||
(`get_now_playing` already excludes expired tracks).
|
||||
|
||||
Doesn't look at the user's now_playing_mode: core's now_playing table is populated
|
||||
for every user regardless of federation settings, so a caller must gate this itself
|
||||
(build_document does) rather than leak listening activity for users who never turned
|
||||
now playing on at all.
|
||||
"""
|
||||
def now_playing_text(user) -> str | None:
|
||||
""" "Track by Artist", or None if nothing unexpired is playing (`get_now_playing`
|
||||
already excludes expired tracks). Doesn't look at now_playing_mode: core's
|
||||
now_playing table is populated for every user regardless of federation settings, so
|
||||
a caller must gate this itself (now_playing_field does) rather than leak listening
|
||||
activity for users who never turned now playing on at all."""
|
||||
playing = get_now_playing(user)
|
||||
if playing is None:
|
||||
return None
|
||||
return f"{playing.track} by {playing.artist}"
|
||||
|
||||
|
||||
def now_playing_field(user, settings) -> list[tuple[str, str]]:
|
||||
"""The actor's now-playing `PropertyValue` field: empty unless now_playing_mode is
|
||||
on and something's actually playing."""
|
||||
if settings.now_playing_mode == "off":
|
||||
return []
|
||||
return [(NOW_PLAYING_FIELD, f"{playing.track} by {playing.artist}")]
|
||||
text = now_playing_text(user)
|
||||
return [(NOW_PLAYING_FIELD, text)] if text else []
|
||||
|
||||
|
||||
def build_document(urls: vocab.ActorUrls, user, settings) -> dict:
|
||||
fields = now_playing_field(user) if settings.now_playing_mode != "off" else []
|
||||
return vocab.person(
|
||||
urls,
|
||||
username=user.username,
|
||||
@@ -40,5 +45,5 @@ def build_document(urls: vocab.ActorUrls, user, settings) -> dict:
|
||||
discoverable=settings.discoverable,
|
||||
indexable=settings.indexable,
|
||||
published=settings.created_at.isoformat().replace("+00:00", "Z"),
|
||||
fields=fields,
|
||||
fields=now_playing_field(user, settings),
|
||||
)
|
||||
@@ -5,7 +5,7 @@ from flask_smorest import Blueprint, abort
|
||||
|
||||
from scrobbler.api.decorators import authenticated
|
||||
from scrobbler.extensions import db
|
||||
from scrobbler.federation import activities, ids, publishing, sharing
|
||||
from scrobbler.federation import activities, actors, ids, publishing, sharing
|
||||
from scrobbler.federation import followers as follower_state
|
||||
from scrobbler.federation import metrics as fed_metrics
|
||||
from scrobbler.federation.models import FederationBlock, FederationFollower, FederationPost
|
||||
@@ -175,6 +175,9 @@ def public_profile(username):
|
||||
"username": user.username,
|
||||
"display_name": settings.display_name or user.username,
|
||||
"bio": settings.bio,
|
||||
"now_playing": actors.now_playing_text(user)
|
||||
if settings.now_playing_mode != "off"
|
||||
else None,
|
||||
**{k: v for k, v in _identity(user.username).items() if k != "profile_url"},
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,9 @@ class PublicProfileSchema(Schema):
|
||||
username = fields.String()
|
||||
display_name = fields.String()
|
||||
bio = fields.String(allow_none=True)
|
||||
now_playing = fields.String(
|
||||
allow_none=True, metadata={"description": '"Track by Artist", or null'}
|
||||
)
|
||||
handle = fields.String(metadata={"example": "@alice@scrobble.example"})
|
||||
actor_url = fields.String()
|
||||
|
||||
|
||||
Reference in new issue
Block a user