From 119517bd3add16bba80780d8e99e2ca65d86ed32 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 26 Jun 2026 18:41:23 +0000 Subject: [PATCH] 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 Claude-Session: https://claude.ai/code/session_016aj4ajZ4uQ58Bqts7riJ5i --- .../amethyst/ui/note/nip22Comments/CommentPostViewModel.kt | 2 +- .../loggedIn/chats/privateDM/send/ChatNewMessageViewModel.kt | 2 +- .../chats/publicChannels/send/ChannelNewMessageViewModel.kt | 2 +- .../loggedIn/discover/nip23LongForm/LongFormPostViewModel.kt | 2 +- .../loggedIn/discover/nip99Classifieds/NewProductViewModel.kt | 2 +- .../amethyst/ui/screen/loggedIn/home/ShortNotePostViewModel.kt | 2 +- .../screen/loggedIn/nests/room/chat/NestNewMessageViewModel.kt | 2 +- .../notifications/publicMessages/NewPublicMessageViewModel.kt | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/nip22Comments/CommentPostViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/nip22Comments/CommentPostViewModel.kt index 7816fe7439..3c3973b09e 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/nip22Comments/CommentPostViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/nip22Comments/CommentPostViewModel.kt @@ -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() } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/send/ChatNewMessageViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/send/ChatNewMessageViewModel.kt index 802cd7915e..c5c94e64c6 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/send/ChatNewMessageViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/privateDM/send/ChatNewMessageViewModel.kt @@ -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() } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/send/ChannelNewMessageViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/send/ChannelNewMessageViewModel.kt index 62fcfe08b4..142c025d54 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/send/ChannelNewMessageViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/send/ChannelNewMessageViewModel.kt @@ -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() } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip23LongForm/LongFormPostViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip23LongForm/LongFormPostViewModel.kt index ef029422c6..cac2107755 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip23LongForm/LongFormPostViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip23LongForm/LongFormPostViewModel.kt @@ -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() } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip99Classifieds/NewProductViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip99Classifieds/NewProductViewModel.kt index 19055e35ba..0cbfe7a650 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip99Classifieds/NewProductViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/nip99Classifieds/NewProductViewModel.kt @@ -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() } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/ShortNotePostViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/ShortNotePostViewModel.kt index 9452082e39..a447dbcdca 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/ShortNotePostViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/ShortNotePostViewModel.kt @@ -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() } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/nests/room/chat/NestNewMessageViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/nests/room/chat/NestNewMessageViewModel.kt index 7090f6df59..44bfb87c27 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/nests/room/chat/NestNewMessageViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/nests/room/chat/NestNewMessageViewModel.kt @@ -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() } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/publicMessages/NewPublicMessageViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/publicMessages/NewPublicMessageViewModel.kt index c84c2b1d05..a97e2068da 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/publicMessages/NewPublicMessageViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/publicMessages/NewPublicMessageViewModel.kt @@ -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() }