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:
@@ -23,19 +23,11 @@ type Rendered struct {
|
||||
// Payload is what producers put in a notification. Every field is optional;
|
||||
// each kind documents the ones it uses in Render.
|
||||
type Payload struct {
|
||||
RequestID string `json:"request_id,omitempty"`
|
||||
RequestKind string `json:"request_kind,omitempty"` // artist | album | track
|
||||
// Name is what was requested or flagged, as the user would say it:
|
||||
// "WWW", "Moe Shop", "Moe Shop – WWW".
|
||||
// Name is what was flagged, as the user would say it: "Moe Shop – WWW".
|
||||
Name string `json:"name,omitempty"`
|
||||
// Artist and Title are Name's parts, for request_completed: the new-music
|
||||
// summary email groups arrivals by artist. Title is empty for an artist
|
||||
// request.
|
||||
Artist string `json:"artist,omitempty"`
|
||||
Title string `json:"title,omitempty"`
|
||||
ArtistID string `json:"artist_id,omitempty"`
|
||||
AlbumID string `json:"album_id,omitempty"`
|
||||
// Actor is the other person involved: who asked, who flagged.
|
||||
// Albums are new_music's arrivals, the first AlbumsKept of Count.
|
||||
Albums []Arrival `json:"albums,omitempty"`
|
||||
// Actor is the other person involved: who flagged.
|
||||
Actor string `json:"actor,omitempty"`
|
||||
Reason string `json:"reason,omitempty"`
|
||||
// Count is the coalesced kinds' running total since the notice was last
|
||||
@@ -50,6 +42,18 @@ type Payload struct {
|
||||
Detail string `json:"detail,omitempty"`
|
||||
}
|
||||
|
||||
// Arrival is one album new to the library.
|
||||
type Arrival struct {
|
||||
Artist string `json:"artist"`
|
||||
Title string `json:"title"`
|
||||
ArtistID string `json:"artist_id,omitempty"`
|
||||
AlbumID string `json:"album_id,omitempty"`
|
||||
}
|
||||
|
||||
// AlbumsKept is how many arrivals a new_music notice carries. The count says
|
||||
// how many there were in all.
|
||||
const AlbumsKept = 50
|
||||
|
||||
// Map turns a Payload into the map Notify takes, dropping empty fields.
|
||||
func (p Payload) Map() map[string]any {
|
||||
b, _ := json.Marshal(p)
|
||||
@@ -65,33 +69,12 @@ func Render(kind Kind, payload []byte) Rendered {
|
||||
_ = json.Unmarshal(payload, &p)
|
||||
name := p.Name
|
||||
if name == "" {
|
||||
name = "Your request"
|
||||
name = "A track"
|
||||
}
|
||||
|
||||
switch kind {
|
||||
case KindRequestApproved:
|
||||
return Rendered{Title: "Request approved", Body: name + " is on its way.", Link: "/requests"}
|
||||
case KindRequestRejected:
|
||||
body := name + " was declined."
|
||||
if p.Reason != "" {
|
||||
body = name + " was declined: " + p.Reason
|
||||
}
|
||||
return Rendered{Title: "Request declined", Body: body, Link: "/requests"}
|
||||
case KindRequestCompleted:
|
||||
link := "/requests"
|
||||
switch {
|
||||
case p.AlbumID != "":
|
||||
link = "/albums/" + p.AlbumID
|
||||
case p.ArtistID != "":
|
||||
link = "/artists/" + p.ArtistID
|
||||
}
|
||||
return Rendered{Title: "Now in your library", Body: name + " has arrived.", Link: link}
|
||||
case KindRequestPending:
|
||||
who := p.Actor
|
||||
if who == "" {
|
||||
who = "Someone"
|
||||
}
|
||||
return Rendered{Title: "Request to review", Body: who + " asked for " + name + ".", Link: "/admin/requests"}
|
||||
case KindNewMusic:
|
||||
return renderNewMusic(p)
|
||||
case KindQuarantineFlagged:
|
||||
who := p.Actor
|
||||
if who == "" {
|
||||
@@ -160,6 +143,38 @@ func Render(kind Kind, payload []byte) Rendered {
|
||||
}
|
||||
}
|
||||
|
||||
// renderNewMusic: a single album opens itself; several open Home, whose
|
||||
// Recently added row starts with them.
|
||||
func renderNewMusic(p Payload) Rendered {
|
||||
total := max(p.Count, int64(len(p.Albums)))
|
||||
if total == 1 && len(p.Albums) == 1 {
|
||||
a := p.Albums[0]
|
||||
link := "/"
|
||||
if a.AlbumID != "" {
|
||||
link = "/albums/" + a.AlbumID
|
||||
}
|
||||
return Rendered{Title: "New album", Body: TrackLabel(a.Artist, a.Title) + " is in the library.", Link: link}
|
||||
}
|
||||
labels := make([]string, 0, min(len(p.Albums), namesShown))
|
||||
for _, a := range p.Albums[:min(len(p.Albums), namesShown)] {
|
||||
labels = append(labels, TrackLabel(a.Artist, a.Title))
|
||||
}
|
||||
body := "New albums are in the library."
|
||||
if names := nameList(labels, total); names != "" {
|
||||
body = "Now in the library: " + names + "."
|
||||
}
|
||||
return Rendered{Title: plural(total, "new album", "new albums"), Body: body, Link: "/"}
|
||||
}
|
||||
|
||||
// TrackLabel names a track or album as a notice does: "Artist – Title", or
|
||||
// the title alone when the artist is unknown.
|
||||
func TrackLabel(artist, title string) string {
|
||||
if artist == "" {
|
||||
return title
|
||||
}
|
||||
return artist + " – " + title
|
||||
}
|
||||
|
||||
// namesShown is how many of a notice's items its body names.
|
||||
const namesShown = 3
|
||||
|
||||
|
||||
Reference in New Issue
Block a user