Skip to content

client: Persist draft messages optimistically and on draft events - #6625

Draft
gpunto wants to merge 3 commits into
developfrom
fix/draft-events-write-through-to-database
Draft

client: Persist draft messages optimistically and on draft events#6625
gpunto wants to merge 3 commits into
developfrom
fix/draft-events-write-through-to-database

Conversation

@gpunto

@gpunto gpunto commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Goal

Stop draft messages from being lost when a request does not complete, and from reappearing after they have been deleted.

Closes AND-1373

Contributes to #6388

Implementation

Aligns three gaps with the iOS SDK (DraftMessagesRepository, DraftUpdaterMiddleware):

  • Create and delete are optimistic. New onCreateDraftMessageRequest / onDeleteDraftMessagesRequest listener hooks, dispatched from doOnStart, so the local write no longer waits for the response and survives a process death mid-request.
  • Result handlers no longer roll back. Success stores the server copy, failure leaves the local draft as is. Previously a permanent create error dropped the draft and a permanent delete error kept it forever.
  • Draft events reach the database. draft.updated / draft.deleted only touched MutableGlobalState, so a draft deleted on another device left its Room row behind and SyncManager re-pushed it on every reconnect. draft.deleted has an empty message id, so deletion keys on cid (or parentId for threads), which needed a new DAO query.

No public API change: neither DraftMessageListener nor MessageRepository is in the API dump.

Testing

Two emulators against the demo backend:

  • Draft deleted on a second device: reappeared after restart on develop, now stays gone.
  • Create and delete failing with an injected 403: draft is kept / removed respectively, and survives a restart.

Unit tests cover both precommit paths and the channel and thread cases for draft.deleted.

@gpunto gpunto added the pr:bug Bug fix label Aug 7, 2026
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

PR checklist ✅

All required conditions are satisfied:

  • Title length is OK (or ignored by label).
  • At least one pr: label exists.
  • Sections ### Goal, ### Implementation, and ### Testing are filled, or the PR is bot-authored.
  • An issue is linked (Linear ticket or GitHub issue), or the PR is bot-authored.

🎉 Great job! This PR is ready for review.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

SDK Size Comparison 📏

SDK Before After Difference Status
stream-chat-android-client 5.96 MB 5.96 MB 0.00 MB 🟢
stream-chat-android-ui-components 11.25 MB 11.25 MB 0.00 MB 🟢
stream-chat-android-compose 12.74 MB 12.74 MB 0.00 MB 🟢

@gpunto
gpunto force-pushed the fix/draft-events-write-through-to-database branch from 7fcb674 to 7d3e3de Compare August 7, 2026 14:49
@sonarqubecloud

sonarqubecloud Bot commented Aug 7, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
71.4% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

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

Labels

pr:bug Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant