33 lines
950 B
TypeScript
33 lines
950 B
TypeScript
/**
|
|
* Which of a playlist's dumps a given viewer may see.
|
|
*
|
|
* @module
|
|
*/
|
|
|
|
import type { Playlist } from "../../shared/playlist.ts";
|
|
|
|
/** A playlist's dump, with what deciding who may see it takes. */
|
|
export interface PlaylistMember {
|
|
/** The dump's id. */
|
|
id: string;
|
|
/** Whether the dump is private. */
|
|
isPrivate: boolean;
|
|
/** The id of the dump's poster. */
|
|
userId: string;
|
|
}
|
|
|
|
/**
|
|
* Checks whether `viewerId` sees this member when the playlist is shown to them: a
|
|
* public dump, or a private one of the owner's own, to the owner. Everyone
|
|
* else — moderators too — doesn't see private dumps, and neither does the
|
|
* owner see someone else's dump once it has gone private.
|
|
*/
|
|
export function isMemberVisibleTo(
|
|
member: PlaylistMember,
|
|
playlist: Pick<Playlist, "userId">,
|
|
viewerId: string | null | undefined,
|
|
): boolean {
|
|
return !member.isPrivate ||
|
|
(member.userId === viewerId && viewerId === playlist.userId);
|
|
}
|