Files
gerbeur/shared/settings.ts
khannurien 708d113013 v4: a /community page shows the site's week and month, from the same figures as the digests, and every recurring server task is a job of one scheduler — the digests' top dumps and community section (who joined, the new public playlists, the chat and the totals) existed only in emails. community-service.ts now gathers them for a period from listTopDumps, listNewUsers and listNewPublicPlaylists, each in its own service and returning the API's Dump, PublicUser and Playlist; the digest builds its sections from the same call, its email-only DumpRow and DUMP_COLS replaced by one Dump mapper that networkOf uses too, and links its community section to the page. The page, /community for the last week and /community/monthly for the month, signed in only and linked from the avatar menu, reads GET /api/community?period=, which serves figures kept in memory and recomputed every GERBEUR_COMMUNITY_REFRESH_MINUTES (15 by default). It shows the four figures, the top dumps and the new playlists as live cards, and the new members as UserCards, the follow tab's user row made shared. Its words are the emails' own: the messages both use are renamed from email.digest.* to digest.*, as digest.weekly.off was. api/lib/scheduler.ts's startJobs runs the digests, the community refresh, the WebSocket ping, the typing expiry and the rate-limit sweep, which main.ts starts, so none of them runs on import any more. PERIOD_MS moves to shared/settings.ts. community is reserved as a category slug, and migration 0022 renames a category that had it, with renameReservedCategories moved out of 0021 into reserved-slugs.ts. A group's dump or playlist cards now fill its column. 262 backend tests and 678 frontend tests pass, and deno check, tsc, eslint, doc:lint and i18n:compile --strict are clean; checked in screenshots in Smooth light at 1280 and 390px, Smooth dark with mocked playlists, Brutalist dark at 390px and Kanagawa dark at 1280px.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 11:42:01 +00:00

77 lines
2.3 KiB
TypeScript

/**
* A user's settings follow their account from browser to browser, and the
* server reads some of them itself (a digest is drawn in its reader's style).
* This module types them for `GET` and `PATCH /api/me/settings`; the
* client keeps them with its session.
*
* @module
*/
import type { ColorScheme, StyleName } from "./theme.ts";
/**
* Returned by `GET /api/me/settings`, and by a `PATCH` once applied.
* The client's `useSettings` reads it from the session.
*/
export interface UserSettings {
/**
* Null until the user picks one, so the instance's default style
* (`GERBEUR_DEFAULT_STYLE`) applies, and so a browser's earlier choice can be
* carried over on first sign-in.
*/
style: StyleName | null;
/** Null until the user picks one, which reads as "auto". */
colorScheme: ColorScheme | null;
/** Whether the weekly digest is sent. */
digestWeekly: boolean;
/** Whether the monthly recap is sent. */
digestMonthly: boolean;
}
/**
* Sent to `PATCH /api/me/settings` with the settings to change; the
* others keep their value.
*/
export type UpdateSettingsRequest = Partial<UserSettings>;
/** The settings of a user who never changed any. Digests are on by default. */
export const DEFAULT_SETTINGS: UserSettings = {
style: null,
colorScheme: null,
digestWeekly: true,
digestMonthly: true,
};
/** Lists how often a digest can come: weekly, or monthly as a recap. */
export const DIGEST_CADENCES = ["weekly", "monthly"] as const;
/**
* One of the {@link DIGEST_CADENCES}. An unsubscribe link names one, which
* turns off its setting alone.
*/
export type DigestCadence = typeof DIGEST_CADENCES[number];
const DAY_MS = 86_400_000;
/**
* How long each cadence's period lasts, rolling: a digest covers the one just
* ended, and the `/community` page the one ending now.
*/
export const PERIOD_MS: Record<DigestCadence, number> = {
weekly: 7 * DAY_MS,
monthly: 30 * DAY_MS,
};
/** Checks whether `value` is a {@link DigestCadence}. */
export function isDigestCadence(value: unknown): value is DigestCadence {
return typeof value === "string" &&
(DIGEST_CADENCES as readonly string[]).includes(value);
}
/** Names the setting that switches each cadence of digest. */
export const DIGEST_SETTING: Record<
DigestCadence,
"digestWeekly" | "digestMonthly"
> = {
weekly: "digestWeekly",
monthly: "digestMonthly",
};