v4: a playlist's dump count is of the dumps the viewer may see — it counted every dump in the playlist, so a card said "3 dumps" over a page listing two, and told everyone how many private dumps a playlist held. The lists (/playlists, a profile's playlists and followed ones, the search, a dump's playlists, the add-to-playlist panel) now count by isMemberVisibleTo's rule, in SQL as VISIBLE_DUMP_COUNT (lib/playlist-members.ts): the public dumps, and for the owner their own private ones. GET /api/playlists and /api/users/:key/follow/playlists read the optional sign-in for it. The community page and the digests count the public dumps, their figures being the same for every reader. Live, playlist_created and playlist_updated carry each socket's own count: broadcastChange builds the owner's message and the others' apart. playlist_dumps_updated loses its dumpCount, a client counting the dumps it is sent.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
/**
|
||||
* Decides which of a playlist's dumps a viewer may see. The playlist service
|
||||
* filters its listings with it, and the WebSocket service filters each
|
||||
* client's `playlist_dumps_updated` message the same way.
|
||||
* filters its listings with it, the WebSocket service filters each client's
|
||||
* `playlist_dumps_updated` message the same way, and the queries that list
|
||||
* playlists count their dumps by the same rule.
|
||||
*
|
||||
* @module
|
||||
*/
|
||||
@@ -34,3 +35,28 @@ export function isMemberVisibleTo(
|
||||
return !member.isPrivate ||
|
||||
(member.userId === viewerId && viewerId === playlist.userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* The `dump_count` column of a query on `playlists p`: how many of the
|
||||
* playlist's dumps the viewer may see, by {@link isMemberVisibleTo}'s rule.
|
||||
* Its `?` takes the viewer's id, or `""` for a signed-out one, and comes
|
||||
* before the query's other parameters, the column being in its select list.
|
||||
*/
|
||||
export const VISIBLE_DUMP_COUNT = `(SELECT COUNT(*) FROM playlist_dumps pd
|
||||
INNER JOIN dumps d ON d.id = pd.dump_id
|
||||
WHERE pd.playlist_id = p.id
|
||||
AND (d.is_private = 0 OR (d.user_id = p.user_id AND p.user_id = ?))
|
||||
) as dump_count`;
|
||||
|
||||
/**
|
||||
* Returns how many of `members` the viewer may see in `playlist`, the
|
||||
* `dumpCount` the playlist has for them.
|
||||
*/
|
||||
export function countVisibleTo(
|
||||
members: PlaylistMember[],
|
||||
playlist: Pick<Playlist, "userId">,
|
||||
viewerId: string | null | undefined,
|
||||
): number {
|
||||
return members.filter((m) => isMemberVisibleTo(m, playlist, viewerId))
|
||||
.length;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user