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
11 changes: 1 addition & 10 deletions api/v1_notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down
45 changes: 45 additions & 0 deletions api/v1_notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
})
}
Loading