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
@@ -2,6 +2,7 @@ import {
startNotificationClient,
subscribeNotifications,
subscribeClientEvents,
subscribeNotificationsCleared,
subscribeReady,
subscribeStatus,
markAllNotificationsRead,
@@ -338,6 +339,18 @@ function clearTable() {
applyTableView();
}
function removeEntriesForClient(clientId) {
if (!clientId) return;
let removed = false;
for (const [uid, entry] of tableState.entries) {
if (entry.item?.clientId === clientId) {
tableState.entries.delete(uid);
removed = true;
}
}
if (removed) applyTableView();
}
// ── Client ID cell (collapsed by default, click to expand) ──────────────────
const CLIENT_ID_SHORT_LEN = 8;
@@ -718,6 +731,7 @@ function connect() {
subscribeNotifications((item) => addNotification(item, true));
subscribeClientEvents((item) => addClientEvent(item));
subscribeNotificationsCleared((clientId) => removeEntriesForClient(clientId));
}
const CLIENT_EVENT_BADGE = {
@@ -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 {