feat: add tomorrow weather brief notifications
This commit is contained in:
@@ -4,6 +4,7 @@ interface PushStore {
|
||||
subscriptions: Map<string, WarningPushSubscription>;
|
||||
sentWarningIds: Map<string, Set<string>>;
|
||||
sentMorningBriefDates: Map<string, Set<string>>;
|
||||
sentTomorrowBriefDates: Map<string, Set<string>>;
|
||||
}
|
||||
|
||||
const globalStore = globalThis as typeof globalThis & { __wtrPushStore?: PushStore };
|
||||
@@ -14,6 +15,7 @@ function getStore() {
|
||||
subscriptions: new Map(),
|
||||
sentWarningIds: new Map(),
|
||||
sentMorningBriefDates: new Map(),
|
||||
sentTomorrowBriefDates: new Map(),
|
||||
};
|
||||
}
|
||||
return globalStore.__wtrPushStore;
|
||||
@@ -28,6 +30,7 @@ export function removePushSubscription(endpoint: string) {
|
||||
store.subscriptions.delete(endpoint);
|
||||
store.sentWarningIds.delete(endpoint);
|
||||
store.sentMorningBriefDates.delete(endpoint);
|
||||
store.sentTomorrowBriefDates.delete(endpoint);
|
||||
}
|
||||
|
||||
export function getPushSubscriptions() {
|
||||
@@ -67,3 +70,14 @@ export function markMorningBriefSent(endpoint: string, dateKey: string) {
|
||||
sentDates.add(dateKey);
|
||||
store.sentMorningBriefDates.set(endpoint, sentDates);
|
||||
}
|
||||
|
||||
export function hasSentTomorrowBrief(endpoint: string, dateKey: string) {
|
||||
return getStore().sentTomorrowBriefDates.get(endpoint)?.has(dateKey) ?? false;
|
||||
}
|
||||
|
||||
export function markTomorrowBriefSent(endpoint: string, dateKey: string) {
|
||||
const store = getStore();
|
||||
const sentDates = store.sentTomorrowBriefDates.get(endpoint) ?? new Set<string>();
|
||||
sentDates.add(dateKey);
|
||||
store.sentTomorrowBriefDates.set(endpoint, sentDates);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user