Messages: Facebook-style Chats panel and docked chat windows
DevPlace CI / test (pull_request) Failing after 1h7m10s
DevPlace CI / test (pull_request) Failing after 1h7m10s
The topnav Messages icon opens a Chats panel (people search, recent conversations, New message, link to the full page). Picking a person opens a small chat window docked bottom-right; windows minimize to avatar heads with unread counts and survive navigation within the tab. Profile Send Message, the live message toast and message notifications on /notifications open the same window. Phones and /messages keep the full page. Each window is dp-chat in mode="window", sharing one WebSocket through chat/ChatSocketHub.js; chat/ConversationItem.js is the shared row builder. No server changes. The message input becomes [+] [text + emoji] [send] everywhere: + reveals the attach and GIF buttons, which tuck away while typing. Also fixes linked toasts never receiving clicks (pointer-events). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -87,6 +87,10 @@ Live/echoed message bubbles are NEVER injected as raw HTML. `AppChat._buildBubbl
|
||||
|
||||
The messaging frontend is the single self-booting custom element `<dp-chat>` (`static/js/components/AppChat.js`), which replaced the old page-controller trio `MessagesLayout.js`/`MessagesSocket.js`/`MessageSearch.js` (all deleted) and `messages.css` (superseded by `static/css/chat.css`) - see `devplacepy/static/js/CLAUDE.md` for the component roster entry. `MobileNav.js` does **not** own the mobile pane (that duplicate was removed; `dp-chat` is the only pane controller). `templates/messages.html` renders `<dp-chat mode="page" self-uid="..." with-uid="..." conversations-url="/messages/conversations" search-url="/messages/search" send-url="/messages/send" ws-url="/messages/ws" ai-indicator="true">` wrapping the SAME server-rendered `.messages-list`/`.messages-main`/`.messages-thread`/`.message-bubble` markup as before (no-JS/crawler fallback), which the component *adopts* on `connectedCallback` rather than discarding. It owns a `ChatSocket` (`static/js/chat/ChatSocket.js`, exponential backoff, `4013` fast-path, 25s ping), sends over WS with an optimistic pending bubble keyed by `client_id`, reconciles on the echoed `message` frame, applies later `ai_processed` frames in place (compare `dp-content[data-source]`, never rendered `textContent`), injects the Report control on every live incoming bubble, catches up with `{type:"sync"}` on reconnect, and switches conversations without dropping the socket (`GET /messages?with_uid=` JSON + `history.pushState`). Older history loads via `GET /messages?with_uid=&before=` when the thread is scrolled to the top. Mobile: CSS hides the inactive pane from `with-uid` / `.show-list` before JS runs (no stacked FOUC); the composer does not auto-focus on coarse pointers; keyboard inset uses `visualViewport.offsetTop + height`; Enter-to-send is desktop-only. **The send button is disabled while `dp-upload` is busy AND while a genuine new send is in flight** (the send-lock, see "Send dedupe" above) - a `.failed`-bubble retry never engages it, so retrying an old message never blocks typing/sending a new one. Presence in `mode="page"` stays on the page-global `PresenceManager`. An opt-in `ai-indicator="true"` attribute shows "Adjusting..." while `ai_pending` and "Adjusted by AI" when the revision lands. Styling is in `static/css/chat.css` using `variables.css` tokens only, responsive down to 360px.
|
||||
|
||||
**Composer layout (every mode).** The message form is `[+] [composer-tools] [composer-field] [send]`: the `.composer-more-btn` toggles `tools-open` on the form, revealing `.composer-tools` (`dp-upload` and `dp-gif-picker`); typing collapses the tools again unless an upload is in flight or attachments are pending, a starting upload (paste, drop, pick) opens them so the count stays visible, and a send collapses them. The textarea lives inside `.composer-field`, the pill that also holds the emoji button (`ContentEnhancer.initEmojiPickers` appends the button into the field and re-homes the picker popup onto the form, and the GIF panel is positioned against the form too, so neither popup is clipped by the narrow pill). `messages.html` and `AppChat._buildComposer` emit the identical structure.
|
||||
|
||||
**Docked windows (`mode="window"`).** On every page except `/messages`, `dp-chat-dock` (see `devplacepy/static/js/CLAUDE.md`) hosts small `dp-chat mode="window"` elements. Window mode builds its own skeleton (header via `_buildHeader` with avatar and name, no back button, no element ids so several windows can coexist), loads history through the same `GET /messages?with_uid=` JSON the page uses (`_loadConversation`, which also marks the conversation and its notifications read) **before** subscribing to the shared socket, so the reconnect `sync` starts from the newest loaded stamp, and never touches `history`. Its thread always counts as active (`_activePane = "thread"`), so read receipts and the active-conversation marker behave exactly as on the page. No server change was needed: the dock uses only `/messages/conversations`, `/messages/search`, `GET /messages?with_uid=` and `WS /messages/ws`.
|
||||
|
||||
**Auto-scroll never fights a manual scroll-up.** `_startScrollWatcher`/`_stabilizeScroll` force `scrollTop = scrollHeight` on every thread mutation (new bubble, attachment/image finishing loading) ONLY while `_userAtBottom` is true, re-checked every `requestAnimationFrame` up to `STABILIZE_MAX_FRAMES`. The one thing that used to break this: while a multi-frame stabilize loop was in flight (`_stabilizePending`), the real `scroll` event listener (`_bindAutoScroll`) ignored EVERY scroll event outright, including a genuine user wheel/touch scroll-up that happened to land inside that window - so a rapid burst of incoming messages (each restarting the stabilize loop while attachments were still loading) could silently overwrite a user's attempt to scroll up to read history. The fix: every programmatic scroll (`_scrollThreadToEnd`, `_stabilizeScroll`) records the exact `scrollTop` it just set in `_lastForcedScrollTop`; the `scroll` listener only skips its own echo (`_stabilizePending && scrollTop === _lastForcedScrollTop`) and always processes a scroll that lands anywhere else, so a real user scroll-up is detected and `_userAtBottom` flips to `false` immediately, even mid-stabilization. Never gate scroll-intent detection on `_stabilizePending` alone again.
|
||||
|
||||
## Attachments stream live
|
||||
|
||||
Reference in New Issue
Block a user