Add deterministic daily weather brief

This commit is contained in:
zv
2026-06-11 20:27:10 +02:00
parent 47a292b26e
commit 49265e7c51
16 changed files with 590 additions and 60 deletions

View File

@@ -3,6 +3,7 @@ import type { WarningPushSubscription } from "@/types/notifications";
interface PushStore {
subscriptions: Map<string, WarningPushSubscription>;
sentWarningIds: Map<string, Set<string>>;
sentMorningBriefDates: Map<string, Set<string>>;
}
const globalStore = globalThis as typeof globalThis & { __wtrPushStore?: PushStore };
@@ -12,6 +13,7 @@ function getStore() {
globalStore.__wtrPushStore = {
subscriptions: new Map(),
sentWarningIds: new Map(),
sentMorningBriefDates: new Map(),
};
}
return globalStore.__wtrPushStore;
@@ -25,6 +27,7 @@ export function removePushSubscription(endpoint: string) {
const store = getStore();
store.subscriptions.delete(endpoint);
store.sentWarningIds.delete(endpoint);
store.sentMorningBriefDates.delete(endpoint);
}
export function getPushSubscriptions() {
@@ -53,3 +56,14 @@ export function pruneSentWarnings(activeWarningIds: Set<string>) {
});
});
}
export function hasSentMorningBrief(endpoint: string, dateKey: string) {
return getStore().sentMorningBriefDates.get(endpoint)?.has(dateKey) ?? false;
}
export function markMorningBriefSent(endpoint: string, dateKey: string) {
const store = getStore();
const sentDates = store.sentMorningBriefDates.get(endpoint) ?? new Set<string>();
sentDates.add(dateKey);
store.sentMorningBriefDates.set(endpoint, sentDates);
}