mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-10 08:27:04 +00:00
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:
+1
-1
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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()
|
||||
}
|
||||
|
||||
+1
-1
@@ -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()
|
||||
}
|
||||
|
||||
+1
-1
@@ -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()
|
||||
}
|
||||
|
||||
+1
-1
@@ -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()
|
||||
}
|
||||
|
||||
+1
-1
@@ -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()
|
||||
}
|
||||
|
||||
+1
-1
@@ -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()
|
||||
}
|
||||
|
||||
+1
-1
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user