Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions api/v1_notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
46 changes: 46 additions & 0 deletions api/v1_notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}