feat: new-music notices come from the scanner; request notices and the original specs go
release / web (push) Failing after 1m29s
release / go (push) Successful in 1m55s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 4m22s
release / android (push) Successful in 4m57s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / Build signed APK (push) Canceled after 4m23s
release / web (push) Failing after 1m29s
release / go (push) Successful in 1m55s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 4m22s
release / android (push) Successful in 4m57s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / Build signed APK (push) Canceled after 4m23s
Request notifications (approved, declined, completed, pending) are removed
along with the request flow that produced them. A new_music kind takes the
"new music arrived" slot: when a scan or a watcher batch finishes, the
scanner claims every album not yet announced (albums.announced_at) and tells
every user about the ones that are new: an album with a track on disk and
no track older than itself. The first import into an empty library, and an
album formed only by retagging tracks already held, announce nothing. One
notice per scan, carrying up to 50 albums and the total; it is never
coalesced, so a notice already emailed can't quietly absorb later arrivals.
It feeds the daily summary email, grouped by artist. Defaults: inbox and
email on, phone off.
Migration 0103 deletes request-kind notification rows and prefs, swaps the
kind CHECKs to new_music, and adds albums.announced_at with every album
held marked announced, so the first scan after it announces nothing old.
Web and Android: labels, the Android "Requests" settings section becomes
"New music", the shade channel your_requests becomes new_music (the old one
is deleted at startup), and "/" opens Home in the app. TrackLabel moves to
the notifications package. docs/smart-music-{server,client}-spec.md are
deleted per the operator; an Android comment loses the word "exchanges".
Grimoire #7666, #7671.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -82,14 +82,14 @@ func TestNotify_WritesARowAndNudgesOnlyThatUser(t *testing.T) {
|
||||
defer unsub()
|
||||
|
||||
n := notifications.New(pool, bus, nil)
|
||||
require.NoError(t, n.Notify(ctx, notifications.KindRequestApproved,
|
||||
notifications.ToUser(alice), map[string]any{"request_id": "r1", "title": "WWW"}))
|
||||
require.NoError(t, n.Notify(ctx, notifications.KindNewMusic,
|
||||
notifications.ToUser(alice), map[string]any{"count": 1, "name": "WWW"}))
|
||||
|
||||
rows := rowsFor(t, q, alice)
|
||||
require.Len(t, rows, 1)
|
||||
require.Equal(t, "request_approved", rows[0].Kind)
|
||||
require.Equal(t, "new_music", rows[0].Kind)
|
||||
require.False(t, rows[0].ReadAt.Valid)
|
||||
require.JSONEq(t, `{"request_id":"r1","title":"WWW"}`, string(rows[0].Payload))
|
||||
require.JSONEq(t, `{"count":1,"name":"WWW"}`, string(rows[0].Payload))
|
||||
require.Empty(t, rowsFor(t, q, bob))
|
||||
|
||||
select {
|
||||
@@ -106,17 +106,17 @@ func TestNotify_AdminKindReachesAdminsOnly_AndNeverTheExcepted(t *testing.T) {
|
||||
pool := testPool(t)
|
||||
q := dbq.New(pool)
|
||||
ctx := context.Background()
|
||||
requester := mkUser(t, q, "admin-requester", true)
|
||||
flagger := mkUser(t, q, "admin-flagger", true)
|
||||
other := mkUser(t, q, "admin-other", true)
|
||||
plain := mkUser(t, q, "plain", false)
|
||||
|
||||
n := notifications.New(pool, nil, nil)
|
||||
// A plain user named directly must still get nothing: the kind is admin-only.
|
||||
to := notifications.ToAdmins(requester)
|
||||
to := notifications.ToAdmins(flagger)
|
||||
to.Users = []pgtype.UUID{plain}
|
||||
require.NoError(t, n.Notify(ctx, notifications.KindRequestPending, to, nil))
|
||||
require.NoError(t, n.Notify(ctx, notifications.KindQuarantineFlagged, to, nil))
|
||||
|
||||
require.Empty(t, rowsFor(t, q, requester), "the admin who filed it needs no notice")
|
||||
require.Empty(t, rowsFor(t, q, flagger), "the admin who flagged it needs no notice")
|
||||
require.Len(t, rowsFor(t, q, other), 1)
|
||||
require.Empty(t, rowsFor(t, q, plain))
|
||||
}
|
||||
@@ -183,18 +183,37 @@ func TestNotify_ACoalescedUpdateMergesNamesAndKeepsItsArrival(t *testing.T) {
|
||||
require.True(t, emailed.Valid, "an emailed notice is not emailed again because it grew")
|
||||
}
|
||||
|
||||
func TestNotify_RequestKindsNeverCoalesce(t *testing.T) {
|
||||
// Each scan's new music is its own notice: one already emailed in the daily
|
||||
// summary must not quietly take in albums that arrive after it.
|
||||
func TestNotify_NewMusicNeverCoalesces(t *testing.T) {
|
||||
pool := testPool(t)
|
||||
q := dbq.New(pool)
|
||||
ctx := context.Background()
|
||||
alice := mkUser(t, q, "alice", false)
|
||||
n := notifications.New(pool, nil, nil)
|
||||
for _, id := range []string{"r1", "r2"} {
|
||||
require.NoError(t, n.Notify(ctx, notifications.KindRequestCompleted, notifications.ToUser(alice), map[string]any{"request_id": id}))
|
||||
for range 2 {
|
||||
require.NoError(t, n.Notify(ctx, notifications.KindNewMusic, notifications.ToUser(alice), map[string]any{"count": 1}))
|
||||
}
|
||||
require.Len(t, rowsFor(t, q, alice), 2)
|
||||
}
|
||||
|
||||
func TestNotify_EveryoneReachesEveryUser(t *testing.T) {
|
||||
pool := testPool(t)
|
||||
q := dbq.New(pool)
|
||||
ctx := context.Background()
|
||||
admin := mkUser(t, q, "admin", true)
|
||||
plain := mkUser(t, q, "plain", false)
|
||||
n := notifications.New(pool, nil, nil)
|
||||
require.NoError(t, n.Notify(ctx, notifications.KindNewMusic, notifications.ToEveryone(), map[string]any{"count": 1}))
|
||||
require.Len(t, rowsFor(t, q, admin), 1)
|
||||
require.Len(t, rowsFor(t, q, plain), 1)
|
||||
|
||||
// An admin kind addressed to everyone still reaches admins only.
|
||||
require.NoError(t, n.Notify(ctx, notifications.KindScanFailed, notifications.ToEveryone(), map[string]any{"count": 1}))
|
||||
require.Len(t, rowsFor(t, q, admin), 2)
|
||||
require.Len(t, rowsFor(t, q, plain), 1)
|
||||
}
|
||||
|
||||
func TestNotify_InboxOffStoresNothing_AndDefaultsApplyWithoutAPref(t *testing.T) {
|
||||
pool := testPool(t)
|
||||
q := dbq.New(pool)
|
||||
@@ -202,12 +221,12 @@ func TestNotify_InboxOffStoresNothing_AndDefaultsApplyWithoutAPref(t *testing.T)
|
||||
muted := mkUser(t, q, "muted", false)
|
||||
fresh := mkUser(t, q, "fresh", false)
|
||||
require.NoError(t, q.UpsertNotificationPref(ctx, dbq.UpsertNotificationPrefParams{
|
||||
UserID: muted, Kind: "request_rejected", Inbox: false, Phone: true, Email: true,
|
||||
UserID: muted, Kind: "new_music", Inbox: false, Phone: true, Email: true,
|
||||
}))
|
||||
|
||||
n := notifications.New(pool, nil, nil)
|
||||
to := notifications.Recipients{Users: []pgtype.UUID{muted, fresh}}
|
||||
require.NoError(t, n.Notify(ctx, notifications.KindRequestRejected, to, nil))
|
||||
require.NoError(t, n.Notify(ctx, notifications.KindNewMusic, to, nil))
|
||||
|
||||
require.Empty(t, rowsFor(t, q, muted), "inbox off is off, whatever phone and email say")
|
||||
require.Len(t, rowsFor(t, q, fresh), 1)
|
||||
@@ -220,7 +239,7 @@ func TestMarkRead_ScopedToTheOwner_AndIdempotent(t *testing.T) {
|
||||
alice := mkUser(t, q, "alice", false)
|
||||
mallory := mkUser(t, q, "mallory", false)
|
||||
n := notifications.New(pool, nil, nil)
|
||||
require.NoError(t, n.Notify(ctx, notifications.KindRequestApproved, notifications.ToUser(alice), nil))
|
||||
require.NoError(t, n.Notify(ctx, notifications.KindNewMusic, notifications.ToUser(alice), nil))
|
||||
id := rowsFor(t, q, alice)[0].ID
|
||||
|
||||
got, err := q.MarkNotificationRead(ctx, dbq.MarkNotificationReadParams{ID: id, UserID: mallory})
|
||||
@@ -271,7 +290,7 @@ func TestRetention_TrimsOldReadRowsAndAncientUnreadOnes(t *testing.T) {
|
||||
readAt = *read
|
||||
}
|
||||
_, err := pool.Exec(ctx,
|
||||
`INSERT INTO user_notifications (user_id, kind, created_at, read_at) VALUES ($1, 'request_approved', $2, $3)`,
|
||||
`INSERT INTO user_notifications (user_id, kind, created_at, read_at) VALUES ($1, 'new_music', $2, $3)`,
|
||||
user, created, readAt)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user