From 843ec94bf6f785239da9124dadf73cebe632a601 Mon Sep 17 00:00:00 2001 From: MarekWo Date: Fri, 2 Jan 2026 06:24:08 +0100 Subject: [PATCH] fix: Update DM badge using conversations endpoint instead of updates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed DM badge update logic to use /api/dm/conversations endpoint instead of /api/dm/updates?last_seen={} which was causing incorrect unread counts (showing 99+, then 2, when there should be 0). The new approach: - Fetches all conversations with their unread counts - Sums up unread messages across all conversations - Updates badge without full page reload (avoiding viewport corruption) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- app/templates/index.html | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/templates/index.html b/app/templates/index.html index 717b775..fbd6ebd 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -196,11 +196,16 @@ // Update DM badges when modal is closed (without full page reload) dmModal.addEventListener('hidden.bs.modal', async function () { try { - // Fetch latest DM unread counts - const response = await fetch('/api/dm/updates?last_seen={}'); + // Fetch latest DM conversations with unread counts + const response = await fetch('/api/dm/conversations'); if (response.ok) { const data = await response.json(); - const totalUnread = data.total_unread || 0; + + // Calculate total unread by summing unread counts from all conversations + let totalUnread = 0; + if (data.conversations && Array.isArray(data.conversations)) { + totalUnread = data.conversations.reduce((sum, conv) => sum + (conv.unread || 0), 0); + } // Update the green DM badge on notification bell const bellContainer = document.getElementById('notificationBell');