From 27109f7bc9023c19b61b839f32370bdca070569a Mon Sep 17 00:00:00 2001 From: Dylan Jeffers Date: Wed, 11 Nov 2026 18:38:32 -0800 Subject: [PATCH] fix(api): hide new notification types from clients that can't parse them The generated SDK throws on an unknown notification type, which fails the whole page. weekly_rotation_featured, weekly_artist_recap and trending_genre broke the notification list on every shipped web and mobile client. Return them only when the caller lists them in `types`. Co-Authored-By: Claude Opus 5.5 --- api/v1_notifications.go | 23 ++++++++++++++++-- api/v1_notifications_test.go | 46 ++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/api/v1_notifications.go b/api/v1_notifications.go index ae9a18ba..50c50a6d 100644 --- a/api/v1_notifications.go +++ b/api/v1_notifications.go @@ -83,6 +83,25 @@ var unsupportedNotificationTypes = []string{ "remix", } +// Shipped clients throw on notification types their generated SDK does not +// know, which empties the whole list. Newer types are returned only when the +// caller asks for them in `types`. +var optInNotificationTypes = []string{ + "weekly_rotation_featured", + "weekly_artist_recap", + "trending_genre", +} + +func excludedNotificationTypes(requested []string) []string { + excluded := append([]string{}, unsupportedNotificationTypes...) + for _, t := range optInNotificationTypes { + if !slices.Contains(requested, t) { + excluded = append(excluded, t) + } + } + return excluded +} + // Share visibility rules between the list and badge. Count only notifications // that the list can display, after bounding the candidate scan. const notificationContentJoinsSQL = ` @@ -263,7 +282,7 @@ FROM ( "limit": notificationUnreadPollLimit, "candidate_limit": notificationReadCandidateLimit, "types": params.Types, - "unsupported_types": unsupportedNotificationTypes, + "unsupported_types": excludedNotificationTypes(params.Types), }).Scan(&unreadCount) }) if err != nil { @@ -624,7 +643,7 @@ limit @limit::int "types": params.Types, "group_id_offset": params.GroupID, "timestamp_offset": params.Timestamp, - "unsupported_types": unsupportedNotificationTypes, + "unsupported_types": excludedNotificationTypes(params.Types), } if usesCandidateLimit { diff --git a/api/v1_notifications_test.go b/api/v1_notifications_test.go index e7bfa668..0c4b9de2 100644 --- a/api/v1_notifications_test.go +++ b/api/v1_notifications_test.go @@ -910,3 +910,49 @@ func TestV1Notifications_UnreadIgnoresOnlyHiddenNotifications(t *testing.T) { } } } + +func TestV1Notifications_OptInTypesHiddenUnlessRequested(t *testing.T) { + app := emptyTestApp(t) + + fixtures := database.FixtureMap{ + "notification": []map[string]any{ + { + "id": 1, + "specifier": "1", + "group_id": "weekly_rotation:2026-46:1", + "type": "weekly_rotation", + "user_ids": []int{1}, + "data": []byte(`{"year": 2026, "week": 46}`), + "timestamp": time.Now().Add(-2 * time.Hour), + }, + { + "id": 2, + "specifier": "1", + "group_id": "weekly_artist_recap:2026-45:1", + "type": "weekly_artist_recap", + "user_ids": []int{1}, + "data": []byte(`{"year": 2026, "week": 45, "play_count": 2}`), + "timestamp": time.Now().Add(-1 * time.Hour), + }, + }, + } + database.Seed(app.pool.Replicas[0], fixtures) + + userPath := "/v1/notifications/" + trashid.MustEncodeHashID(1) + + status, body := testGet(t, app, userPath) + assert.Equal(t, 200, status) + jsonAssert(t, body, map[string]any{ + "data.notifications.#": 1, + "data.notifications.0.type": "weekly_rotation", + "data.unread_count": 1, + }) + + status, body = testGet(t, app, userPath+"?types=weekly_artist_recap&types=weekly_rotation") + assert.Equal(t, 200, status) + jsonAssert(t, body, map[string]any{ + "data.notifications.#": 2, + "data.notifications.0.type": "weekly_artist_recap", + "data.unread_count": 2, + }) +}