clear notification by toggling them off and back on

This commit is contained in:
KingKDot
2026-05-15 18:57:23 -05:00
parent 5aa3a304a8
commit b68aa4a4c7
6 changed files with 72 additions and 4 deletions
@@ -34,6 +34,7 @@ let notificationHandlers = new Set();
let statusHandlers = new Set();
let unreadHandlers = new Set();
let clientEventHandlers = new Set();
let notificationsClearedHandlers = new Set();
let lastHistory = [];
function emitStatus(status) {
@@ -69,6 +70,17 @@ function emitClientEvent(item) {
}
}
function emitNotificationsCleared(clientId) {
if (Array.isArray(lastHistory) && lastHistory.length) {
lastHistory = lastHistory.filter((item) => item.clientId !== clientId);
}
for (const handler of notificationsClearedHandlers) {
try {
handler(clientId);
} catch {}
}
}
function shouldNotify() {
return localStorage.getItem(STORAGE_KEY) === "1";
}
@@ -319,6 +331,10 @@ function handleMessage(payload) {
emitClientEvent(payload);
showClientEventDesktopNotification(payload);
}
if (payload.type === "notifications_cleared" && payload.clientId) {
console.log("[notifications] cleared for", payload.clientId);
emitNotificationsCleared(payload.clientId);
}
}
let msgpackLoadPromise = null;
@@ -439,6 +455,11 @@ export function subscribeClientEvents(handler) {
return () => clientEventHandlers.delete(handler);
}
export function subscribeNotificationsCleared(handler) {
notificationsClearedHandlers.add(handler);
return () => notificationsClearedHandlers.delete(handler);
}
export function subscribeUnread(handler) {
unreadHandlers.add(handler);
try {