37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
/**
|
|
* 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.
|
|
*
|
|
* @module
|
|
*/
|
|
|
|
import type { Playlist } from "../../shared/playlist.ts";
|
|
|
|
/**
|
|
* The fields of a playlist's dump that {@link isMemberVisibleTo} needs. A
|
|
* `Dump` has them. For its broadcasts, the playlist service reads only these.
|
|
*/
|
|
export interface PlaylistMember {
|
|
id: string;
|
|
isPrivate: boolean;
|
|
/** The dump's poster, not the playlist's owner. */
|
|
userId: string;
|
|
}
|
|
|
|
/**
|
|
* Checks whether `viewerId` may see `member` in `playlist`. A public dump is
|
|
* visible to all. A private dump is visible only to the playlist's owner, and
|
|
* only if they posted it: moderators don't see it, and neither does the owner
|
|
* once someone else's dump in their playlist goes private. A null or undefined
|
|
* `viewerId` is a signed-out viewer.
|
|
*/
|
|
export function isMemberVisibleTo(
|
|
member: PlaylistMember,
|
|
playlist: Pick<Playlist, "userId">,
|
|
viewerId: string | null | undefined,
|
|
): boolean {
|
|
return !member.isPrivate ||
|
|
(member.userId === viewerId && viewerId === playlist.userId);
|
|
}
|