feat(collab): handle CLIENT_MESSAGE suggestUserName on the client#6
Conversation
… client
Adds src/collab/clientMessage.ts, the client-side counterpart of the Go
server's HandleClientMessage (COLLABROOM CLIENT_MESSAGE family),
mirroring the original Etherpad pad.handleClientMessage behavior:
- suggestUserName: when a received suggestion targets this (still
unnamed) user, adopt the name locally, send a USERINFO_UPDATE back to
the server, and emit user:info:updated on the editor bus.
- padoptions: tolerated as a no-op (pad-wide settings unsupported).
- unknown payload types and malformed frames are ignored without
throwing.
extractClientMessagePayload unwraps both wire framings used on this
stack (server->client ["message", data] arrays and client->server
{event, data} objects) as well as already-unwrapped COLLABROOM
messages, so hosts can plug in at any level.
Sending suggestions is not implemented because this package has no
user list UI (EpUserBadge is display-only); the sending side lives in
the host's pad_userlist.
Tests run in a new "unit" vitest project (node) alongside the existing
"storybook" browser project; pnpm test now runs both.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
Code Review by Qodo
1. Handler may throw
|
PR Summary by QodoHandle COLLABROOM CLIENT_MESSAGE suggestUserName on the client WalkthroughsDescription• Add client-side handler for COLLABROOM CLIENT_MESSAGE payloads, including suggestUserName. • Adopt suggested name for unnamed users, then send USERINFO_UPDATE and emit a bus event. • Add Node-based unit test project in Vitest alongside existing Storybook browser tests. Diagramgraph TD
S{{"Go collab server"}} --> F["Wire frame"] --> X["extractPayload"] --> H["ClientMessage handler"] --> U["setMyUserName()"]
H --> M["sendMessage(USERINFO_UPDATE)"] --> S
H --> B(("editorBus")) --> L["Host listeners"]
subgraph Legend
direction LR
_ext{{"External"}} ~~~ _fn["Module/Function"] ~~~ _bus(("Event bus"))
end
High-Level AssessmentThe following are alternative approaches to this PR: 1. Implement inside an existing collab client class
2. Add runtime schema validation (e.g., zod/io-ts) for frames
Recommendation: The current approach (small, host-injected handler + tolerant frame unwrapping) is a good fit for a UI component library that shouldn’t own the transport layer. Consider optional schema validation only if future CLIENT_MESSAGE payloads become more complex or need better error reporting. File ChangesEnhancement (2)
Tests (1)
Other (2)
|
Summary
Client-side counterpart to the Go server's COLLABROOM
CLIENT_MESSAGEhandling (etherpad-go#276/#280): when another user suggests a name for an unnamed user (suggestUserName), the targeted client now adopts the name and propagates aUSERINFO_UPDATE, mirroring the originalpad_userlist/padbehavior.src/collab/clientMessage.ts(exported as./collab/clientMessage.js):createClientMessageHandler({getMyUserInfo, setMyUserName, sendMessage, bus?})— adopts a suggested name whenunnamedIdmatches this user and the user has no name yet; sendsUSERINFO_UPDATE; emitsuser:info:updatedon the editor bus.extractClientMessagePayload/handleFrame— tolerant unwrapping of all wire framings (socket.io-style array frames from the Go relay,{event,data}objects, bare COLLABROOM payloads).padoptionsand unknown payload types are tolerated as no-ops (no settings feature built).unitvitest project alongside the existingstorybookbrowser project; 12 new unit tests.Test plan
pnpm typecheck,pnpm buildcleanCI=true pnpm test— 16 files, 94 tests passed (15 story files + the new unit file)🤖 Generated with Claude Code