feat: notifications say what changed and alert once: a grouped notice names the tracks, grows without re-alerting, and a phone pile lists its titles (M542 #6146-#6151)
release / govulncheck (push) Successful in 14s
release / web (push) Successful in 1m22s
release / go (push) Successful in 1m33s
release / android (push) Failing after 1m42s
release / integration (push) Failing after 4m42s
release / Build signed APK (releases and dev) (push) Successful in 4m55s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Skipped
release / Verify release artifacts (tag releases only) (push) Skipped

- An update to a grouped notice keeps its arrival time and email state, so the
  phone and the email no longer go off again each time it grows.
- Notices carry the names of what changed (newest ten), shown as three and
  "and N more": tracks still missing after the scan's move/replacement fold,
  duplicate groups new to a sweep, songs merged automatically, and the track
  and listener a playback error was for.
- Duplicates found counts only the groups new to that sweep; playback errors
  count reports, not the unresolved total.
- A scan failure says what stopped and links to Admin > Library.
- Android: a pile of more than three alerts lists the newest five titles.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-19 22:44:19 -04:00
co-authored by Claude Opus 5.5
parent 2365514e5b
commit 854c307834
26 changed files with 486 additions and 190 deletions
+11 -12
View File
@@ -6,6 +6,7 @@ import (
"github.com/jackc/pgx/v5/pgtype"
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
"git.fabledsword.com/bvandeusen/minstrel/internal/library"
"git.fabledsword.com/bvandeusen/minstrel/internal/notifications"
"git.fabledsword.com/bvandeusen/minstrel/internal/requests"
)
@@ -66,21 +67,19 @@ func (h *handlers) trackLabel(ctx context.Context, trackID pgtype.UUID) string {
if err != nil {
return ""
}
if a, aerr := q.GetArtistByID(ctx, t.ArtistID); aerr == nil && a.Name != "" {
return a.Name + " – " + t.Title
if a, aerr := q.GetArtistByID(ctx, t.ArtistID); aerr == nil {
return library.TrackLabel(a.Name, t.Title)
}
return t.Title
}
// notifyPlaybackErrors tells admins how many playback errors await review.
// The notice coalesces, so while it is unread a new report only updates the
// count.
func (h *handlers) notifyPlaybackErrors(ctx context.Context) {
n, err := dbq.New(h.pool).CountUnresolvedPlaybackErrors(ctx)
if err != nil {
h.logger.Warn("api: playback_error: count unresolved", "err", err)
return
// notifyPlaybackErrors tells admins a track failed to play, naming it and who
// it failed for (M542). The notice coalesces: while it is unread each report
// adds one to its count and its name to the front of the list.
func (h *handlers) notifyPlaybackErrors(ctx context.Context, trackID pgtype.UUID, user dbq.User) {
p := notifications.Payload{Count: 1}
if name := h.trackLabel(ctx, trackID); name != "" {
p.Items = []string{name + " (" + userLabel(user) + ")"}
}
h.notifier.NotifyLogged(ctx, notifications.KindPlaybackErrors, notifications.ToAdmins(pgtype.UUID{}),
notifications.Payload{Count: n}.Map())
h.notifier.NotifyLogged(ctx, notifications.KindPlaybackErrors, notifications.ToAdmins(pgtype.UUID{}), p.Map())
}
+3 -2
View File
@@ -211,8 +211,9 @@ func TestNotify_PlaybackErrorsCoalesceIntoOneCount(t *testing.T) {
got := inboxOf(t, pool, admin)
wantInbox(t, "admin", got, notifications.KindPlaybackErrors)
if got[0].Payload.Count != 2 {
t.Errorf("count = %d, want 2 unresolved", got[0].Payload.Count)
if got[0].Payload.Count != 2 || len(got[0].Payload.Items) != 2 ||
!strings.HasSuffix(got[0].Payload.Items[0], "(np-play-alice)") {
t.Errorf("payload = %+v, want two reports, each naming the track and alice", got[0].Payload)
}
wantInbox(t, "reporter", inboxOf(t, pool, alice))
}
+1 -1
View File
@@ -130,7 +130,7 @@ func (h *handlers) handleReportPlaybackError(w http.ResponseWriter, r *http.Requ
writeErr(w, apierror.Internal(err))
return
}
h.notifyPlaybackErrors(r.Context())
h.notifyPlaybackErrors(r.Context(), trackID, user)
writeJSON(w, http.StatusCreated, map[string]string{"id": uuidToString(row.ID)})
}