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:
@@ -118,3 +118,36 @@ func (b *Bus) SubscriberCount() int {
|
||||
defer b.mu.RUnlock()
|
||||
return len(b.subscribers)
|
||||
}
|
||||
|
||||
// LikeChanged is the event every surface publishes when a like changes, so
|
||||
// the web and Android apps hear about a like made anywhere, a Subsonic app
|
||||
// included. entityType is "track", "album" or "artist"; the kind is
|
||||
// "<entityType>.liked" or "<entityType>.unliked".
|
||||
func LikeChanged(userID, entityType, entityID string, liked bool) Event {
|
||||
action := "liked"
|
||||
if !liked {
|
||||
action = "unliked"
|
||||
}
|
||||
return Event{
|
||||
Kind: entityType + "." + action,
|
||||
UserID: userID,
|
||||
Data: map[string]any{
|
||||
"entity_type": entityType,
|
||||
"entity_id": entityID,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// LedBy is the entities a like or unlike reports: every one it changed, led
|
||||
// by the one asked for, which is reported even when it was already in that
|
||||
// state (so the asking client always hears back). A like is on the song, so
|
||||
// it can change several copies at once.
|
||||
func LedBy[T comparable](asked T, changed []T) []T {
|
||||
out := []T{asked}
|
||||
for _, c := range changed {
|
||||
if c != asked {
|
||||
out = append(out, c)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user