// An account's preferences, as the appview keeps them // (dev.knotless.getPreferences): one of each kind, told apart by `$type`. import type * as getPreferences from '#lib/lexicons/dev/knotless/getPreferences.ts'; import type * as putPreferences from '#lib/lexicons/dev/knotless/putPreferences.ts'; import { call } from '#lib/data.ts'; export const APPEARANCE_PREF = 'dev.knotless.getPreferences#appearancePref'; export const NOTIFICATION_PREF = 'dev.knotless.getPreferences#notificationPref'; export const THEMES_PREF = 'dev.knotless.getPreferences#themesPref'; /** The notifications among `all`, which the appview always gives. */ export const notificationsOf = ( all: getPreferences.Preferences ): getPreferences.NotificationPref | null => (all.preferences.find((p) => p.$type === NOTIFICATION_PREF) as | getPreferences.NotificationPref | undefined) ?? null; /** The themes people made that `all`'s account added to its own: none until it adds one. */ export const themesOf = (all: getPreferences.Preferences): getPreferences.AddedTheme[] => (all.preferences.find((p) => p.$type === THEMES_PREF) as getPreferences.ThemesPref | undefined) ?.themes ?? []; /** Sets `prefs`, each in its kind's place, answering them all. */ export const putPrefs = (prefs: putPreferences.$InputBody['preferences']) => call('dev.knotless.putPreferences', { preferences: prefs });