fix: only resolve the draft note when there is a version to save

The versions collector resolved draftNote = account.getOrCreateDraftNote(...)
on every emission, including the content-less initial tick (~1s after the
composer opens). That touched the lateinit account before any user input; if
it were ever unset at that moment the throw would kill the collectLatest
coroutine and silently stop all draft saves for that composer.

Move the resolve inside the `if (it > 0)` guard, co-located with the save, so
account is only read once a real edit exists. The open-a-draft-then-send-
without-editing case is still covered by the explicit refresh in load().

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016aj4ajZ4uQ58Bqts7riJ5i
This commit is contained in:
Claude
2026-06-26 18:41:23 +00:00
parent 94b99e0973
commit 119517bd3a
8 changed files with 8 additions and 8 deletions
@@ -145,9 +145,9 @@ open class CommentPostViewModel :
init {
viewModelScope.launch(Dispatchers.IO) {
draftTag.versions.collectLatest {
draftNote = account.getOrCreateDraftNote(draftTag.current)
// don't save the first
if (it > 0) {
draftNote = account.getOrCreateDraftNote(draftTag.current)
sendDraftSync()
}
}
@@ -138,9 +138,9 @@ class ChatNewMessageViewModel :
init {
viewModelScope.launch(Dispatchers.IO) {
draftTag.versions.collectLatest {
draftNote = account.getOrCreateDraftNote(draftTag.current)
// don't save the first
if (it > 0) {
draftNote = account.getOrCreateDraftNote(draftTag.current)
accountViewModel.launchSigner {
sendDraftSync()
}
@@ -121,9 +121,9 @@ open class ChannelNewMessageViewModel :
init {
viewModelScope.launch(Dispatchers.IO) {
draftTag.versions.collectLatest {
draftNote = account.getOrCreateDraftNote(draftTag.current)
// don't save the first
if (it > 0) {
draftNote = account.getOrCreateDraftNote(draftTag.current)
accountViewModel.launchSigner {
sendDraftSync()
}
@@ -140,9 +140,9 @@ class LongFormPostViewModel :
init {
viewModelScope.launch(Dispatchers.IO) {
draftTag.versions.collectLatest {
draftNote = account.getOrCreateDraftNote(draftTag.current)
// don't save the first
if (it > 0) {
draftNote = account.getOrCreateDraftNote(draftTag.current)
accountViewModel.launchSigner {
sendDraftSync()
}
@@ -126,9 +126,9 @@ open class NewProductViewModel :
init {
viewModelScope.launch(Dispatchers.IO) {
draftTag.versions.collectLatest {
draftNote = account.getOrCreateDraftNote(draftTag.current)
// don't save the first
if (it > 0) {
draftNote = account.getOrCreateDraftNote(draftTag.current)
accountViewModel.launchSigner {
sendDraftSync()
}
@@ -195,9 +195,9 @@ open class ShortNotePostViewModel :
init {
viewModelScope.launch(Dispatchers.IO) {
draftTag.versions.collectLatest {
draftNote = account.getOrCreateDraftNote(draftTag.current)
// don't save the first
if (it > 0) {
draftNote = account.getOrCreateDraftNote(draftTag.current)
accountViewModel.launchSigner {
sendDraftSync()
}
@@ -126,9 +126,9 @@ open class NestNewMessageViewModel :
init {
viewModelScope.launch(Dispatchers.IO) {
draftTag.versions.collectLatest {
draftNote = account.getOrCreateDraftNote(draftTag.current)
// don't save the first
if (it > 0) {
draftNote = account.getOrCreateDraftNote(draftTag.current)
accountViewModel.launchSigner {
sendDraftSync()
}
@@ -141,9 +141,9 @@ class NewPublicMessageViewModel :
init {
viewModelScope.launch(Dispatchers.IO) {
draftTag.versions.collectLatest {
draftNote = account.getOrCreateDraftNote(draftTag.current)
// don't save the first
if (it > 0) {
draftNote = account.getOrCreateDraftNote(draftTag.current)
accountViewModel.launchSigner {
sendDraftSync()
}