Skip to content

fix(chunter): clear the other open chat input when a shared draft is sent - #11121

Open
MichaelUray wants to merge 1 commit into
hcengineering:developfrom
MichaelUray:fix/chat-draft-sync-sidebar
Open

MichaelUray wants to merge 1 commit into
hcengineering:developfrom
MichaelUray:fix/chat-draft-sync-sidebar

Conversation

@MichaelUray

Copy link
Copy Markdown
Contributor

Fixes #7363

Problem and change

A channel open in the main view and in the sidebar shows the same message draft, including the pre-generated message _id. Both inputs took the draft object straight from draftsStore, so they shared one mutable object, and onUpdate() writes into it in place. After a send, the sending editor is cleared before the message is created, and that empty update was written into the shared object. When the other input then saw the created message, its content no longer matched the sent message, so it kept the sent text and only got a new _id. In addition its clear() reset the draft state but not the bound editor content, and the created-message query only ran in inputs that were opened with an existing draft, so sending from the sidebar never reached the main view.

Each input now works on its own copy of the stored draft, clear() also resets the editor content, and the created-message query also runs while the input holds unsent content. Whichever input sends the message, the other one is emptied if it still shows the sent content; text typed there afterwards is kept as a new draft.

Tests

No unit test (Svelte wiring). Checked manually on a self-hosted instance in a real browser, each case twice: with the same channel open in the main view and in the sidebar, sending the draft from either side empties the other input immediately and typing there starts fresh; text added only in the other input after the send is kept and can be sent as a separate message.

…sent

A channel open in the main view and in the sidebar shows the same message draft, including the pre-generated message _id. Both inputs took the draft object straight from draftsStore, so they shared one mutable object, and onUpdate() writes into it in place. After a send, the sending editor is cleared before the message is created, and that empty update was written into the shared object. When the other input then saw the created message, its content no longer matched the sent message, so it kept the sent text and only got a new _id. In addition its clear() reset the draft state but not the bound editor content, and the created-message query only ran in inputs that were opened with an existing draft, so sending from the sidebar never reached the main view.

Each input now works on its own copy of the stored draft, clear() also resets the editor content, and the created-message query also runs while the input holds unsent content. Whichever input sends the message, the other one is emptied if it still shows the sent content; text typed there afterwards is kept as a new draft.

Fixes hcengineering#7363

Signed-off-by: Michael Uray <michaeluray@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Message appears as draft in chat sidebar even after sending in channel

1 participant