diff --git a/api/v1_notifications.go b/api/v1_notifications.go index 02c50536..5da66f1f 100644 --- a/api/v1_notifications.go +++ b/api/v1_notifications.go @@ -59,15 +59,6 @@ WITH user_seen as ( ORDER BY seen_at desc LIMIT 10 -), -user_created_at as ( - SELECT - created_at - FROM - users - WHERE - user_id = @user_id - AND is_current ) SELECT n.type, @@ -114,7 +105,7 @@ LEFT JOIN playlists p ON p.playlist_id = (n.data->>'playlist_id')::integer AND p.is_current = true WHERE - ((ARRAY[@user_id] && n.user_ids) OR (n.type = 'announcement' AND n.timestamp > (SELECT created_at FROM user_created_at))) + (ARRAY[@user_id] && n.user_ids) AND (n.type = ANY(@types) OR @types IS NULL) -- Ignore notification types not supported by frontend AND (n.type != ALL(@unsupported_types)) diff --git a/api/v1_notifications_test.go b/api/v1_notifications_test.go index 041a56f8..d0a7e9c3 100644 --- a/api/v1_notifications_test.go +++ b/api/v1_notifications_test.go @@ -423,3 +423,48 @@ func TestV1Notifications_PrivatePlaylist(t *testing.T) { "data.notifications.0.type": "milestone", }) } + +func TestV1Notifications_AnnouncementRequiresUserIdInUserIds(t *testing.T) { + app := emptyTestApp(t) + + fixtures := database.FixtureMap{ + "notification": []map[string]any{ + { + "id": 1, + "specifier": "1", + "group_id": "announcement:target-user-1", + "type": "announcement", + "user_ids": []int{1}, + "data": []byte(`{"title": "For user 1", "short_description": "hi"}`), + }, + { + "id": 2, + "specifier": "2", + "group_id": "announcement:target-user-2", + "type": "announcement", + "user_ids": []int{2}, + "data": []byte(`{"title": "For user 2", "short_description": "bye"}`), + }, + { + "id": 3, + "specifier": "3", + "group_id": "announcement:empty-user-ids", + "type": "announcement", + "user_ids": []int{}, + "data": []byte(`{"title": "Nobody", "short_description": "x"}`), + }, + }, + } + + database.Seed(app.pool.Replicas[0], fixtures) + + status, body := testGet(t, app, "/v1/notifications/"+trashid.MustEncodeHashID(1)) + assert.Equal(t, 200, status) + + jsonAssert(t, body, map[string]any{ + "data.notifications.#": 1, + "data.notifications.0.type": "announcement", + "data.notifications.0.group_id": "announcement:target-user-1", + "data.notifications.0.actions.0.data.title": "For user 1", + }) +}