Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (codex): broadcast removed event from removeByMetadata (#1615)
[._.]/ Adam Eivy3782e4647c9e
diff --git a/server/services/notifications.js b/server/services/notifications.jsindex c174fffe01..f4f4ad78cb 100644--- a/server/services/notifications.js+++ b/server/services/notifications.js@@ -196,18 +196,22 @@ export async function removeNotification(id) {export async function removeByMetadata(field, value) {return withLock(async () => {const data = await loadNotifications();- const before = data.notifications.length;+ // Capture the ids being removed so live clients can prune their local list.+ // Emitting only 'count-changed' updates the unread badge but leaves the+ // removed items rendered in the notification center until a reload — the+ // socket bridge fans 'removed' (not 'count-changed') to the client list.+ const removedIds = data.notifications.filter(n => n.metadata?.[field] === value).map(n => n.id);data.notifications = data.notifications.filter(n => n.metadata?.[field] !== value);- const removed = before - data.notifications.length;- if (removed > 0) {+ if (removedIds.length > 0) {await saveNotifications(data);- console.log(`🔔 Removed ${removed} notifications with ${field}=${value}`);+ console.log(`🔔 Removed ${removedIds.length} notifications with ${field}=${value}`);+ for (const id of removedIds) notificationEvents.emit('removed', { id });notificationEvents.emit('count-changed', await getUnreadCount());}- return { success: true, removed };+ return { success: true, removed: removedIds.length };});}diff --git a/server/services/notifications.test.js b/server/services/notifications.test.jsindex 3ae003f931..e33e994bc4 100644--- a/server/services/notifications.test.js+++ b/server/services/notifications.test.js@@ -257,6 +257,31 @@ describe('notifications', () => {expect(result.success).toBe(true)expect(result.removed).toBe(0)})++ it('should emit a removed event per id so live clients prune their list', async () => {+ const removedSpy = vi.fn()+ const countSpy = vi.fn()+ notificationEvents.on('removed', removedSpy)+ notificationEvents.on('count-changed', countSpy)++ await removeByMetadata('memoryId', 'mem-1')++ expect(removedSpy).toHaveBeenCalledWith({ id: 'n1' })+ expect(countSpy).toHaveBeenCalled()++ notificationEvents.off('removed', removedSpy)+ notificationEvents.off('count-changed', countSpy)+ })++ it('should not emit a removed event when nothing matches', async () => {+ const removedSpy = vi.fn()+ notificationEvents.on('removed', removedSpy)++ await removeByMetadata('memoryId', 'nonexistent')++ expect(removedSpy).not.toHaveBeenCalled()+ notificationEvents.off('removed', removedSpy)+ })})describe('markAsRead', () => {