Fixes wrong refactoring

This commit is contained in:
Vitor Pamplona
2024-04-03 10:20:05 -04:00
parent 638dba770d
commit b88723b68b
2 changed files with 21 additions and 21 deletions
@@ -77,6 +77,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.mapLatest import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.UUID import java.util.UUID
enum class UserSuggestionAnchor { enum class UserSuggestionAnchor {
@@ -200,12 +201,16 @@ open class NewPostViewModel() : ViewModel() {
val noteAuthor = draft?.author val noteAuthor = draft?.author
if (draft != null && noteEvent is DraftEvent && noteAuthor != null) { if (draft != null && noteEvent is DraftEvent && noteAuthor != null) {
accountViewModel.createTempDraftNote(noteEvent, noteAuthor) { innerNote -> viewModelScope.launch(Dispatchers.IO) {
val oldTag = (draft.event as? AddressableEvent)?.dTag() accountViewModel.createTempDraftNote(noteEvent) { innerNote ->
if (oldTag != null) { if (innerNote != null) {
draftTag = oldTag val oldTag = (draft.event as? AddressableEvent)?.dTag()
if (oldTag != null) {
draftTag = oldTag
}
loadFromDraft(innerNote, accountViewModel)
}
} }
loadFromDraft(innerNote, accountViewModel)
} }
} else { } else {
originalNote = replyingTo originalNote = replyingTo
@@ -442,18 +447,22 @@ open class NewPostViewModel() : ViewModel() {
} }
fun sendDraft(relayList: List<Relay>? = null) { fun sendDraft(relayList: List<Relay>? = null) {
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launch {
innerSendPost(relayList, draftTag) sendDraftSync(relayList)
} }
} }
suspend fun sendDraftSync(relayList: List<Relay>? = null) {
innerSendPost(relayList, draftTag)
}
private suspend fun innerSendPost( private suspend fun innerSendPost(
relayList: List<Relay>? = null, relayList: List<Relay>? = null,
localDraft: String?, localDraft: String?,
) { ) = withContext(Dispatchers.IO) {
if (accountViewModel == null) { if (accountViewModel == null) {
cancel() cancel()
return return@withContext
} }
val tagger = NewMessageTagger(message.text, pTags, eTags, originalNote?.channelHex(), accountViewModel!!) val tagger = NewMessageTagger(message.text, pTags, eTags, originalNote?.channelHex(), accountViewModel!!)
@@ -1323,20 +1323,11 @@ class AccountViewModel(val account: Account, val settings: SettingsState) : View
account.deleteDraft(draftTag) account.deleteDraft(draftTag)
} }
fun createTempCachedDraftNote( suspend fun createTempDraftNote(
noteEvent: DraftEvent, noteEvent: DraftEvent,
author: User, onReady: (Note?) -> Unit,
): Note? {
return noteEvent.preCachedDraft(account.signer)?.let { createTempDraftNote(it, author) }
}
fun createTempDraftNote(
noteEvent: DraftEvent,
author: User,
onReady: (Note) -> Unit,
) { ) {
viewModelScope.launch(Dispatchers.IO) { draftNoteCache.update(noteEvent, onReady)
}
} }
fun createTempDraftNote( fun createTempDraftNote(