fix: key messages by networkId:room to prevent collision across networks

Two networks sharing a room name (e.g. "general") were clobbering each
other's message lists. Now keyed by `${networkId}:${room}` throughout
the web store, MessagePane, and Sidebar DM detection.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Fredrik Johansson
2026-06-29 16:55:16 +02:00
parent dab5387cbd
commit f5fb0862ff
3 changed files with 19 additions and 11 deletions

View File

@@ -283,14 +283,14 @@ export const useWaste = create<WasteState>((set, get) => ({
case 'message_received': {
if (msg.message) {
const m = msg.message
const room = m.room
const key = `${msg.network_id}:${m.room}`
const fromId = String(m.from)
set(s => {
const existing = s.messages[room] ?? []
const existing = s.messages[key] ?? []
if (m.mid && existing.some(e => e.mid === m.mid)) return s
const prev = s.peerStatus[fromId] ?? {}
return {
messages: { ...s.messages, [room]: [...existing, m] },
messages: { ...s.messages, [key]: [...existing, m] },
peerStatus: { ...s.peerStatus, [fromId]: { ...prev, lastSeen: m.ts } },
}
})
@@ -378,16 +378,17 @@ export const useWaste = create<WasteState>((set, get) => ({
const room = msg.room
const incoming = (msg.messages ?? []) as ChatMessage[]
if (!room || incoming.length === 0) break
const key = `${msg.network_id}:${room}`
set(s => {
const existing = s.messages[room] ?? []
const existing = s.messages[key] ?? []
const existingMids = new Set(existing.map(m => m.mid).filter(Boolean))
const fresh = incoming.filter(m => !m.mid || !existingMids.has(m.mid))
if (fresh.length === 0) return s
const merged = [...fresh, ...existing].sort((a, b) => a.ts - b.ts)
const cutoff = fresh[fresh.length - 1]?.ts ?? 0
return {
messages: { ...s.messages, [room]: merged },
historyCutoff: { ...s.historyCutoff, [room]: cutoff },
messages: { ...s.messages, [key]: merged },
historyCutoff: { ...s.historyCutoff, [key]: cutoff },
}
})
break