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
127 lines
4.7 KiB
Python
127 lines
4.7 KiB
Python
from marshmallow import Schema, ValidationError, fields, validate
|
|
|
|
from scrobbler.federation.models import NOW_PLAYING_MODES, VISIBILITIES
|
|
from scrobbler.federation.protocol.schedule import is_valid_timezone
|
|
|
|
|
|
def _valid_timezone(value: str) -> None:
|
|
if not is_valid_timezone(value):
|
|
raise ValidationError("Not a known time zone.")
|
|
|
|
|
|
class SharingSettingsSchema(Schema):
|
|
enabled = fields.Boolean(metadata={"description": "Share listening on the fediverse"})
|
|
visibility = fields.String(
|
|
validate=validate.OneOf(VISIBILITIES),
|
|
metadata={
|
|
"description": (
|
|
"Who sees posts: `followers` (default), `unlisted` (anyone visiting the "
|
|
"profile, not public timelines) or `public`. Followers-only is only as private "
|
|
"as who may follow: see `manually_approves_followers`."
|
|
)
|
|
},
|
|
)
|
|
manually_approves_followers = fields.Boolean()
|
|
discoverable = fields.Boolean(metadata={"description": "May appear in profile directories"})
|
|
indexable = fields.Boolean(metadata={"description": "Posts may be indexed for search"})
|
|
display_name = fields.String(allow_none=True, validate=validate.Length(max=100))
|
|
bio = fields.String(allow_none=True, validate=validate.Length(max=500))
|
|
timezone = fields.String(
|
|
validate=_valid_timezone,
|
|
metadata={
|
|
"description": (
|
|
"IANA time zone, e.g. `Europe/London`. Decides when a week ends for the "
|
|
"weekly summary."
|
|
),
|
|
"example": "Europe/London",
|
|
},
|
|
)
|
|
post_weekly_summary = fields.Boolean(
|
|
metadata={"description": "Post a weekly summary of your listening"}
|
|
)
|
|
post_milestones = fields.Boolean(
|
|
metadata={
|
|
"description": "Post scrobble-count, artist-plays and top-10 milestones as you hit them"
|
|
}
|
|
)
|
|
now_playing_mode = fields.String(
|
|
validate=validate.OneOf(NOW_PLAYING_MODES),
|
|
metadata={
|
|
"description": (
|
|
'`off` (default): nothing. `profile`: a "Now playing" field on your '
|
|
"profile, refreshed at most every 5 minutes and cleared when you stop. "
|
|
"`posts`: the profile field, plus a post for each track played 30+ "
|
|
"seconds, at most one every 30 minutes, replacing the last one."
|
|
)
|
|
},
|
|
)
|
|
handle = fields.String(dump_only=True, metadata={"example": "@alice@scrobble.example"})
|
|
actor_url = fields.String(dump_only=True)
|
|
profile_url = fields.String(dump_only=True)
|
|
followers = fields.Integer(dump_only=True, metadata={"description": "Accepted followers"})
|
|
pending_followers = fields.Integer(
|
|
dump_only=True, metadata={"description": "Waiting for approval"}
|
|
)
|
|
|
|
|
|
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()
|
|
|
|
|
|
class SharingSettingsUpdateSchema(SharingSettingsSchema):
|
|
"""Any subset of the editable settings (read-only fields are rejected)."""
|
|
|
|
|
|
class FollowerSchema(Schema):
|
|
id = fields.Integer()
|
|
state = fields.String(validate=validate.OneOf(["pending", "accepted"]))
|
|
handle = fields.String(metadata={"example": "@bob@mastodon.example"})
|
|
display_name = fields.String(allow_none=True)
|
|
actor_url = fields.String()
|
|
server = fields.String(metadata={"example": "mastodon.example"})
|
|
since = fields.DateTime(metadata={"description": "When they followed (or asked to)"})
|
|
|
|
|
|
class FollowerListArgsSchema(Schema):
|
|
state = fields.String(load_default=None, validate=validate.OneOf(["pending", "accepted"]))
|
|
|
|
|
|
class BlockSchema(Schema):
|
|
id = fields.Integer()
|
|
handle = fields.String()
|
|
display_name = fields.String(allow_none=True)
|
|
actor_url = fields.String()
|
|
since = fields.DateTime()
|
|
|
|
|
|
class PostSchema(Schema):
|
|
id = fields.Integer()
|
|
kind = fields.String(metadata={"description": "weekly, milestone or now_playing"})
|
|
text = fields.String()
|
|
visibility = fields.String()
|
|
created_at = fields.DateTime()
|
|
deleted_at = fields.DateTime(allow_none=True)
|
|
|
|
|
|
class WeeklyPreviewSchema(Schema):
|
|
text = fields.String()
|
|
html = fields.String()
|
|
|
|
|
|
class PublicPostSchema(Schema):
|
|
"""A public or unlisted post, for the web UI's post page (post.html)."""
|
|
|
|
text = fields.String()
|
|
html = fields.String()
|
|
created_at = fields.DateTime()
|
|
display_name = fields.String()
|
|
handle = fields.String(metadata={"example": "@alice@scrobble.example"})
|
|
profile_url = fields.String()
|