refactor(badges): derive from snapshot; delete getSidebarBadges IPC chain
Badges were fetched via a dedicated IPC that aggregated counts on the server, while the same data lived in ProfileSnapshot on the client. Two paths to the same answer drift whenever one side mutates between refreshes — the visible symptom being "badge = 1 unread" with an empty inbox after a message gets marked read in another screen. Delete the whole server path. Sidebar badges are now derived on the client from the snapshot via `deriveSidebarBadges(snapshot, companyId)` in `src/shared/sidebar-badges.ts`. One source of truth; drift is physically impossible. Deletions: - database/company-settings.ts::getSidebarBadges (120-line SQL aggregation) - database-base.ts::getSidebarBadges pass-through - ipc-core-read-handlers.ts: handler - preload/index.ts: bridge binding - shared/contracts/channels.ts: channel name - shared/contracts/desktop-api/companies.ts: API signature - shared/contracts/schemas-badges.ts::sidebarBadgesSchema Zod schema - renderer/state/slices/company.ts: `badges` field, `setBadges`, `refreshBadges` - useDataLoader: both getSidebarBadges call sites - useCompanyController: badge reset on company switch - useDesktopEvents: refreshBadges call on granular patches - tests/unit/store.test.ts: refreshBadges test (deleted code) The snapshot's agentMessages already carries board-reader read state via boardReadReceiptMap (`snapshot.ts:39-47` has always LEFT JOIN'd agent_message_reads with agent_id = BOARD_READER_ID). So derivation needs no schema change — the infrastructure was in place, just unused. fix(communication/MessageList): render orphaned-reply messages at the top level The thread-flattening used `filteredMessages.filter(m => !m.parentMessageId)` to pick top-level messages. When an agent replies to a company/incident post with a DM (the CEO prompt explicitly instructs this in wake-reasons/en.ts:119), the DM lands in the direct channel with parentMessageId pointing to a message that lives in another channel. That parent is not in `filteredMessages` for the direct channel, so the reply had no parent to nest under AND was excluded from top-level. The channel rendered as a blank pane even though exactly one message matched — the "clicked Dr. X ↔ Dr. Y, got empty" symptom. Fix: a message is top-level when it either has no parent OR its parent is outside the current filtered view. Replies with in-view parents still nest normally.
This commit is contained in:
1 parent
c83d670050
commit
487f2456ff
14 files changed
+168
-157
No files matched your search
@@ -41,10 +41,22 @@ export function MessageList({
|
||||
const parentRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
const threadedMessages = useMemo(() => {
|
||||
const topLevel = filteredMessages.filter((m) => !m.parentMessageId)
|
||||
// A message is rendered at the top level when it either has no
|
||||
// parent, or its parent is outside the current filtered view
|
||||
// (another channel, beyond the 1000-row snapshot cap, or simply
|
||||
// not loaded yet). Without this second condition, a DM channel
|
||||
// whose earliest message has scrolled off the snapshot would
|
||||
// display as completely empty even though replies for it are
|
||||
// present — the exact "clicked the channel, got a blank pane"
|
||||
// symptom.
|
||||
const idSet = new Set(filteredMessages.map((m) => m.id))
|
||||
const topLevel: AgentMessageRecord[] = []
|
||||
const replyMap = new Map<string, AgentMessageRecord[]>()
|
||||
for (const m of filteredMessages) {
|
||||
if (m.parentMessageId) {
|
||||
const parentInView = m.parentMessageId ? idSet.has(m.parentMessageId) : false
|
||||
if (!m.parentMessageId || !parentInView) {
|
||||
topLevel.push(m)
|
||||
} else {
|
||||
const existing = replyMap.get(m.parentMessageId) ?? []
|
||||
existing.push(m)
|
||||
replyMap.set(m.parentMessageId, existing)
|
||||
|
||||
Reference in new issue
Block a user