Barazo AppView backend
barazo.forum
1import { eq } from 'drizzle-orm'
2import type { Database } from '../db/index.js'
3import { userPreferences } from '../db/schema/user-preferences.js'
4
5// ---------------------------------------------------------------------------
6// Types
7// ---------------------------------------------------------------------------
8
9export interface BlockMuteLists {
10 blockedDids: string[]
11 mutedDids: string[]
12}
13
14// ---------------------------------------------------------------------------
15// Loader
16// ---------------------------------------------------------------------------
17
18/**
19 * Load the authenticated user's block and mute lists from their preferences.
20 *
21 * Returns empty lists when:
22 * - The user is not authenticated (userDid is undefined)
23 * - No preferences row exists for the user
24 *
25 * @param userDid - The DID of the authenticated user, or undefined if unauthenticated
26 * @param db - The Drizzle database instance
27 */
28export async function loadBlockMuteLists(
29 userDid: string | undefined,
30 db: Database
31): Promise<BlockMuteLists> {
32 if (!userDid) {
33 return { blockedDids: [], mutedDids: [] }
34 }
35
36 const rows = await db
37 .select({
38 blockedDids: userPreferences.blockedDids,
39 mutedDids: userPreferences.mutedDids,
40 })
41 .from(userPreferences)
42 .where(eq(userPreferences.did, userDid))
43
44 const prefs = rows[0]
45 return {
46 blockedDids: prefs?.blockedDids ?? [],
47 mutedDids: prefs?.mutedDids ?? [],
48 }
49}