fix(events): a like made in a Subsonic app reaches the other apps, and an open web tab follows likes and playlist changes (#8077)
The native like endpoints announce a like on the event bus; Subsonic star and unstar announced nothing, so the web and Android apps showed a stale heart until they refetched. Subsonic now publishes the same events, through one shape both surfaces build (eventbus.LikeChanged, eventbus.LedBy). The web listened only for the nightly rebuild and notifications, so an open tab ignored likes and playlist changes made in another tab, on Android or in a Subsonic app. It now refreshes its liked views on any like event and its playlists (and the open one) on playlist.created/updated/deleted/ tracks_changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+3
-14
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/apierror"
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/db/dbq"
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/eventbus"
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/playevents"
|
||||
)
|
||||
|
||||
@@ -49,24 +50,12 @@ func (h *handlers) handleLikeTrack(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
// The like is on the song: every copy it reached changes on
|
||||
// the client too.
|
||||
for _, t := range withTrack(id, liked) {
|
||||
for _, t := range eventbus.LedBy(id, liked) {
|
||||
h.publishLikeEvent(user.ID, t, "track", true)
|
||||
}
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// withTrack is the tracks a like or unlike changed, led by the one asked for,
|
||||
// which is reported even when it was already in that state.
|
||||
func withTrack(id pgtype.UUID, changed []pgtype.UUID) []pgtype.UUID {
|
||||
out := []pgtype.UUID{id}
|
||||
for _, t := range changed {
|
||||
if t != id {
|
||||
out = append(out, t)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (h *handlers) handleUnlikeTrack(w http.ResponseWriter, r *http.Request) {
|
||||
user, ok := requireUser(w, r)
|
||||
if !ok {
|
||||
@@ -87,7 +76,7 @@ func (h *handlers) handleUnlikeTrack(w http.ResponseWriter, r *http.Request) {
|
||||
h.logger.Error("api: soft-delete contextual_likes", "err", err)
|
||||
// Don't fail the response — soft-delete is best-effort.
|
||||
}
|
||||
for _, t := range withTrack(id, unliked) {
|
||||
for _, t := range eventbus.LedBy(id, unliked) {
|
||||
h.publishLikeEvent(user.ID, t, "track", false)
|
||||
}
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
|
||||
Reference in New Issue
Block a user