feat: per-category email prefs, admin ops webhooks, per-user feature toggles (v0.61.0)
- Notification email preferences: every push category (follow, comment, reply, reaction, rating, mention, leftoverExpiring, shoppingList) now has an independent email toggle, plus a Weekly Digest toggle. Previously email sent unconditionally whenever the recipient had one; now gated the same way push already was. The weekly-digest cron route excludes opted-out users. - Admin-only site-wide webhooks (Admin → Webhooks): new signups, support tickets, and reports filed can now fire an HMAC-signed HTTP webhook (Slack/Discord/ops alerting), independent of the existing per-user webhooks (which stay scoped to a user's own recipe/meal-plan/shopping-list events). Signing/delivery logic factored into lib/webhook-delivery.ts and shared by both dispatchers instead of duplicated. - Settings → Features: users can hide Nutrition, Pantry, Meal Plan, Shopping Lists, Collections, or Messages from their own nav. Purely cosmetic — hidden pages stay reachable by direct link, nothing is access-restricted. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,11 +4,20 @@ export type NotificationCategory =
|
||||
| "follow" | "comment" | "reply" | "reaction" | "rating" | "mention"
|
||||
| "leftoverExpiring" | "shoppingList";
|
||||
|
||||
export type NotificationPrefs = Record<NotificationCategory, boolean>;
|
||||
export type NotificationPrefs = {
|
||||
follow: boolean; comment: boolean; reply: boolean; reaction: boolean; rating: boolean; mention: boolean;
|
||||
leftoverExpiring: boolean; shoppingList: boolean;
|
||||
followEmail: boolean; commentEmail: boolean; replyEmail: boolean; reactionEmail: boolean;
|
||||
ratingEmail: boolean; mentionEmail: boolean; leftoverExpiringEmail: boolean; shoppingListEmail: boolean;
|
||||
weeklyDigestEmail: boolean;
|
||||
};
|
||||
|
||||
const DEFAULT_PREFS: NotificationPrefs = {
|
||||
follow: true, comment: true, reply: true, reaction: true, rating: true, mention: true,
|
||||
leftoverExpiring: true, shoppingList: true,
|
||||
followEmail: true, commentEmail: true, replyEmail: true, reactionEmail: true,
|
||||
ratingEmail: true, mentionEmail: true, leftoverExpiringEmail: true, shoppingListEmail: true,
|
||||
weeklyDigestEmail: true,
|
||||
};
|
||||
|
||||
export async function getNotificationPrefs(userId: string): Promise<NotificationPrefs> {
|
||||
@@ -17,6 +26,10 @@ export async function getNotificationPrefs(userId: string): Promise<Notification
|
||||
return {
|
||||
follow: row.follow, comment: row.comment, reply: row.reply, reaction: row.reaction,
|
||||
rating: row.rating, mention: row.mention, leftoverExpiring: row.leftoverExpiring, shoppingList: row.shoppingList,
|
||||
followEmail: row.followEmail, commentEmail: row.commentEmail, replyEmail: row.replyEmail,
|
||||
reactionEmail: row.reactionEmail, ratingEmail: row.ratingEmail, mentionEmail: row.mentionEmail,
|
||||
leftoverExpiringEmail: row.leftoverExpiringEmail, shoppingListEmail: row.shoppingListEmail,
|
||||
weeklyDigestEmail: row.weeklyDigestEmail,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -25,3 +38,14 @@ export async function isNotificationCategoryEnabled(userId: string, category: No
|
||||
const prefs = await getNotificationPrefs(userId);
|
||||
return prefs[category];
|
||||
}
|
||||
|
||||
/** Same as isNotificationCategoryEnabled, but for the email variant of the category. */
|
||||
export async function isEmailCategoryEnabled(userId: string, category: NotificationCategory): Promise<boolean> {
|
||||
const prefs = await getNotificationPrefs(userId);
|
||||
return prefs[`${category}Email`];
|
||||
}
|
||||
|
||||
export async function isWeeklyDigestEnabled(userId: string): Promise<boolean> {
|
||||
const prefs = await getNotificationPrefs(userId);
|
||||
return prefs.weeklyDigestEmail;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user