77c739960d
Adds a fourth visibility tier alongside private/unlisted/public: "followers" — visible to the author and anyone who follows them, excluded from public search/explore/profile listings and from the anonymous /r/[id] share route, included in the Following feed. The in-app recipe detail gate and the public share route both check follow status directly against the DB rather than the union type alone, since neither previously had any per-viewer access logic for a non-public/non-owner case. Requires the generated migration (0041) to run against a live DB — not applied in this sandbox (no Docker here); run `pnpm db:migrate`. v0.41.0
16 lines
707 B
TypeScript
16 lines
707 B
TypeScript
import { db, userFollows, and, eq } from "@epicure/db";
|
|
|
|
/** True if `followerId` follows `followingId`. Used to gate "followers only"
|
|
* visibility content — the same leftJoin+isNotNull idiom used elsewhere
|
|
* (e.g. the for-you feed's private-author check) collapsed into a single
|
|
* existence check for the single-recipe case. */
|
|
export async function isFollowing(followerId: string, followingId: string): Promise<boolean> {
|
|
if (followerId === followingId) return true;
|
|
const [row] = await db
|
|
.select({ followerId: userFollows.followerId })
|
|
.from(userFollows)
|
|
.where(and(eq(userFollows.followerId, followerId), eq(userFollows.followingId, followingId)))
|
|
.limit(1);
|
|
return !!row;
|
|
}
|