From 515acae233d22ec07606d1e6848c034e8a66fc58 Mon Sep 17 00:00:00 2001 From: Matthew Daubney Date: Sat, 26 Sep 2026 17:15:51 +0100 Subject: [PATCH] Settings API and schema for now_playing_mode (phase 4, step 4) now_playing_mode was already in sharing.EDITABLE (step 1), so _settings_body() was already returning it - but SharingSettingsSchema never declared the field, so marshmallow was silently dropping it from every response. Same class of gap phase 3 hit with timezone/ post_weekly_summary/post_milestones. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW --- docs/openapi.json | 20 +++++++++++++++++++- src/scrobbler/federation/schemas.py | 15 +++++++++++++-- tests/test_federation_api.py | 21 +++++++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/docs/openapi.json b/docs/openapi.json index 2dcbd33..d863c4f 100644 --- a/docs/openapi.json +++ b/docs/openapi.json @@ -4394,6 +4394,15 @@ "type": "boolean", "description": "Post scrobble-count, artist-plays and top-10 milestones as you hit them" }, + "now_playing_mode": { + "type": "string", + "enum": [ + "off", + "profile", + "posts" + ], + "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": { "type": "string", "readOnly": true, @@ -4474,6 +4483,15 @@ "type": "boolean", "description": "Post scrobble-count, artist-plays and top-10 milestones as you hit them" }, + "now_playing_mode": { + "type": "string", + "enum": [ + "off", + "profile", + "posts" + ], + "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": { "type": "string", "readOnly": true, @@ -4520,7 +4538,7 @@ }, "kind": { "type": "string", - "description": "weekly or milestone" + "description": "weekly, milestone or now_playing" }, "text": { "type": "string" diff --git a/src/scrobbler/federation/schemas.py b/src/scrobbler/federation/schemas.py index 80a9218..b6fc785 100644 --- a/src/scrobbler/federation/schemas.py +++ b/src/scrobbler/federation/schemas.py @@ -1,6 +1,6 @@ from marshmallow import Schema, ValidationError, fields, validate -from scrobbler.federation.models import VISIBILITIES +from scrobbler.federation.models import NOW_PLAYING_MODES, VISIBILITIES from scrobbler.federation.protocol.schedule import is_valid_timezone @@ -44,6 +44,17 @@ class SharingSettingsSchema(Schema): "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) @@ -89,7 +100,7 @@ class BlockSchema(Schema): class PostSchema(Schema): id = fields.Integer() - kind = fields.String(metadata={"description": "weekly or milestone"}) + kind = fields.String(metadata={"description": "weekly, milestone or now_playing"}) text = fields.String() visibility = fields.String() created_at = fields.DateTime() diff --git a/tests/test_federation_api.py b/tests/test_federation_api.py index 007ab41..495faf5 100644 --- a/tests/test_federation_api.py +++ b/tests/test_federation_api.py @@ -56,6 +56,27 @@ def test_an_unknown_timezone_is_rejected(fed_client, fed_auth): assert response.status_code == 422 +def test_now_playing_mode_defaults_to_off(fed_client, fed_auth): + body = fed_client.get("/api/v1/federation/settings", headers=fed_auth).get_json() + assert body["now_playing_mode"] == "off" + + +@pytest.mark.parametrize("mode", ["off", "profile", "posts"]) +def test_now_playing_mode_can_be_changed(fed_client, fed_auth, mode): + response = fed_client.patch( + "/api/v1/federation/settings", json={"now_playing_mode": mode}, headers=fed_auth + ) + assert response.status_code == 200 + assert response.get_json()["now_playing_mode"] == mode + + +def test_an_unknown_now_playing_mode_is_rejected(fed_client, fed_auth): + response = fed_client.patch( + "/api/v1/federation/settings", json={"now_playing_mode": "always"}, headers=fed_auth + ) + assert response.status_code == 422 + + def test_enable_and_change_settings(fed_client, fed_auth, metric_delta): enabled = metric_delta("scrobbler_federation_sharing_changes_total", change="enabled") response = fed_client.patch(