Commit 5e02a15d authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Make soundmarks with no anthem yet discoverable via /nearby

Previously /soundmarks/nearby only returned soundmarks that already
had an active song, so a brand new soundmark (created by a super
admin, no fallback song_id set, no proposals yet) was invisible to
the Nearby page - there was no way for anyone to ever discover it and
make the first proposal. Now it's included with song: null, and the
webapp shows a "propose one" prompt instead of a play button for that
case.
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019i3NAUkLkHNbsPg5vKfzF9
parent 8b2ac79a
Pipeline #1055 passed with stage
in 3 minutes and 54 seconds
......@@ -180,18 +180,18 @@ def get_nearby_soundmarks(
):
"""Soundmarks whose own trigger radius currently contains (lat, lon), closest first - this
is what the webapp polls as the user moves, to find 'the anthem playing here' rather than
a caller-supplied search radius. Includes soundmarks that only have user proposals and no
admin-set song_id, since a winning proposal is just as real an anthem as an admin pick."""
a caller-supplied search radius. Includes soundmarks with no active song at all (no
admin-set fallback, no proposals yet) so they're still discoverable - otherwise nobody
could ever be the first to propose a song for a brand new soundmark; the webapp shows those
with a "propose one" prompt instead of a play button."""
all_marks = db.query(Soundmark).all()
matches = []
for sm in all_marks:
if sm.latitude is None or sm.longitude is None:
continue
entry = _serialize(sm, db)
if not entry["song"]:
continue
dist = _haversine_meters(lat, lon, sm.latitude, sm.longitude)
if dist <= sm.radius_meters:
entry = _serialize(sm, db)
entry["distance_meters"] = dist
matches.append(entry)
matches.sort(key=lambda m: m["distance_meters"])
......
......@@ -243,14 +243,17 @@ def test_nearby_excludes_marks_outside_their_radius(client, db_session, auth_as)
assert "Far Mark" not in names
def test_nearby_excludes_soundmarks_with_no_anthem(client, db_session, auth_as):
def test_nearby_includes_soundmarks_with_no_anthem_yet(client, db_session, auth_as):
"""Discoverable with song=None rather than hidden entirely - otherwise nobody could ever
make the first proposal for a brand new soundmark."""
headers, _ = auth_as()
_make_soundmark(db_session, name="Empty Mark", latitude=37.7749, longitude=-122.4194, radius_meters=200, song_id=None)
response = client.get("/soundmarks/nearby", params={"lat": 37.7749, "lon": -122.4194}, headers=headers)
assert response.status_code == 200
names = {m["name"] for m in response.json()["soundmarks"]}
assert "Empty Mark" not in names
matches = {m["name"]: m for m in response.json()["soundmarks"]}
assert "Empty Mark" in matches
assert matches["Empty Mark"]["song"] is None
# ---- Streaming (cross-user, unlike /library/stream) ----
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment