Fix new-message unread-count dedupe

This commit is contained in:
Jack Kingsman
2026-01-12 23:43:48 -08:00
parent 5ce5a988c7
commit 05508b7f8a
3 changed files with 48 additions and 34 deletions

File diff suppressed because one or more lines are too long

View File

@@ -13,7 +13,7 @@
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
<link rel="manifest" href="/site.webmanifest" />
<script type="module" crossorigin src="/assets/index-Cp9RQ4Uj.js"></script>
<script type="module" crossorigin src="/assets/index-CvVcf00q.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-DaLCXB8p.css">
</head>
<body>

View File

@@ -34,6 +34,8 @@ const MAX_RAW_PACKETS = 500;
export function App() {
const messageInputRef = useRef<MessageInputHandle>(null);
const activeConversationRef = useRef<Conversation | null>(null);
// Track seen message IDs to prevent duplicate unread increments
const seenMessageIdsRef = useRef<Set<number>>(new Set());
const [health, setHealth] = useState<HealthStatus | null>(null);
const [config, setConfig] = useState<RadioConfig | null>(null);
const [appSettings, setAppSettings] = useState<AppSettings | null>(null);
@@ -129,8 +131,20 @@ export function App() {
// Track for unread counts and sorting
trackNewMessage(msg);
// Count unread for non-active, incoming messages
// Count unread for non-active, incoming messages (with deduplication)
if (!msg.outgoing && !isForActiveConversation) {
// Skip if we've already seen this message ID (prevents duplicate increments)
if (seenMessageIdsRef.current.has(msg.id)) {
return;
}
seenMessageIdsRef.current.add(msg.id);
// Limit set size to prevent memory issues
if (seenMessageIdsRef.current.size > 1000) {
const ids = Array.from(seenMessageIdsRef.current);
seenMessageIdsRef.current = new Set(ids.slice(-500));
}
let stateKey: string | null = null;
if (msg.type === 'CHAN' && msg.conversation_key) {
stateKey = getStateKey('channel', msg.conversation_key);