oliver-zehentleitner / maity
clean-up: web chat: mentions and unread rule in one place, one list order, no stale fallbacks
tsk-vtgb0dxefkrn Open
From the web clean-up audit, area 17 (tsk-hgnbapyw7hnh), read at 80647565 (findings sent to lotse, seq 125449 and 125522). Line numbers are from 80647565, so re-check them on current main.
#12 Chat and group chat: one rule implemented two ways (design, includes a bug).
- Unread line:
- chat.js:796 takes theirs[Math.max(0, theirs.length - unreadBefore)]. When more is unread than the page holds, the line goes at the top.
- group-chat.js:140 draws no line in that case.
- views.md:306-310 states one rule for the open chat.
- Mention check:
- chat.js:996 accepts @owner/handle and #instance.
- group-chat.js:410 accepts only a short handle. So "@alice/bot" matches "alice", and the hint (group-chat.js:414-417) wrongly says alice is not in the chat.
- The fixture has a third copy (api.js:4511).
- Proposal: one firstUnreadSeq(items, unread, isTheirs). MENTIONED and withoutCode move to mentions.js.
- Effort S. Risk low.
#46 Shared (mentions.js): the code-span finder is quadratic and copied (duplication/slow path).
- Three implementations of "what is code in this text":
- mentions.js:26-58, codeRanges (M.mentionCode, used by api.js:4506)
- chat.js:447-463, withoutCode (used by group-chat.js:414)
- markdown.js:297, which allows up to 3 leading spaces on a fence where the other two do not
- mentions.js:52 finds the closing run of each run with runs.findIndex. That is the quadratic pattern markdown.js:78-80 says was removed for being slow.
- The instance alphabet [2-9a-hjkmnp-z] is repeated at dom.js:404, mentions.js:18 and chat.js:996.
- Proposal: mentions.js owns a linear codeRanges/withoutCode plus the MENTION and INSTANCE patterns, and chat.js, group-chat.js, dom.js and the fixture use them.
- Effort M. Risk medium: the hints are smoke-tested.
#13 Chat and chats: the list order is written twice, and an export is dead (duplication/debt).
- chat.js:61-65 ordered(chats) is exported at chat.js:735 but has no caller outside chat.js.
- chats.js:32-36 reimplements the same comparator on x.chat.
- jourFixeSeries.keeps (jour-fixe-series.js:445) has no external caller.
- Proposal: give ordered a key accessor and use it in chats.js. Drop the unused exports.
- Effort S. Risk low.
#15 Chat, chats and meat-proxy: fallbacks for fields the hub always sends (debt).
- "c.agent_id, else c.id" at chat.js:215, 785, 788 and chats.js:87. The hub always sets agent_id (hub routes/conversations.py:328).
- "earlier === undefined ? null" at chat.js:400, 833 and group-chat.js:200, 526. The hub always returns earlier (conversations.py:910).
- meat-proxy.js:18 checks whether meat_proxy_lead is in the entry, for "a hub whose entry has no meat_proxy_lead field". chat_meat_proxy.shown always sets it (chat_meat_proxy.py:84-95).
- Proposal: read the fields directly.
- Effort S. Risk low: smoke fixtures may need the fields.
#18 Lead chat: find-or-create written twice, project failures swallowed (duplication/debt).
- Where: lead-chat.js:55-63 (open) and :92-100 (openGroup).
- Past the own-agent shortcut, open(ctx, m) is openGroup(ctx, [m]) with another title key. Both fetch every conversation.
- targetsEverywhere swallows per-project failures (lead-chat.js:84 returns [] in its catch), so the Lead button silently omits a project.
- Proposal: open keeps the own-agent branch, then calls openGroup(ctx, [member], M.t("lead.chat_title")). Read failures go to the header status.
- Effort S. Risk low: smoke.js:15307-15313 covers it.
Order: #12 and #46 belong together. This card can go before the conversation-pane card (tsk-d4ths4493xsj), which touches the same files.