Add deterministic daily weather brief
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user