feat: Save unsent chat message as draft#5686
Merged
Merged
Conversation
6 tasks
Store the message input text in the ViewModel (backed by SavedStateHandle) so it persists when navigating away and returning to the chat screen. - Add draftMessage StateFlow to MessageViewModel - Initialize TextFieldState from ViewModel draft when route message is empty - Sync text field changes back to ViewModel via snapshotFlow - Clear draft when message is successfully sent
Copilot
AI
changed the title
[WIP] Add feature to save unsent chat message as draft
feat: Save unsent chat message as draft
May 31, 2026
- Store savedStateHandle as private val so setDraftMessage/clearDraftMessage can access it after construction (was causing compilation error) - Replace continuous collectAsStateWithLifecycle of draft with one-time StateFlow.value read for rememberTextFieldState initialization, eliminating unnecessary recompositions on every keystroke Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
❌ 1 Tests Failed:
View the top 1 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Saves unsent chat message text as a draft so it persists across navigation (e.g., switching contacts and coming back). The draft is stored in the ViewModel's
SavedStateHandle, surviving both navigation and process death.Changes
MessageViewModel.ktsavedStateHandleas aprivate valproperty for post-construction accessdraftMessageStateFlow backed bySavedStateHandlepersistencesetDraftMessage()/clearDraftMessage()methodsMessage.ktrememberTextFieldStatewith the saved draft (one-time read ofStateFlow.value— avoids recomposition cycle)snapshotFlow+LaunchedEffectDesign Decisions
rememberTextFieldStateonly uses itsinitialTextparam on first composition (no saved state). Continuously collecting the draft flow would trigger unnecessary recompositions on every keystroke via the sync loop.SavedStateHandlesurvives navigation/process death (ViewModel scope);rememberTextFieldStateinternally usesrememberSaveablefor config changes (composable scope). Both stay in sync via thesnapshotFlow.clearDraftMessage()on send: Redundant with the snapshotFlow sync but documents intent clearly.