fix: the famous double sending

This commit is contained in:
infi 2026-05-25 03:07:44 +02:00
parent 3efbb9e697
commit 415e17f84d
1 changed files with 18 additions and 1 deletions

View File

@ -101,6 +101,7 @@ class ChannelScreenViewModel(
var denyMessageFieldReasonResource by mutableIntStateOf(R.string.typing_blank) var denyMessageFieldReasonResource by mutableIntStateOf(R.string.typing_blank)
var editingMessage by mutableStateOf<String?>(null) var editingMessage by mutableStateOf<String?>(null)
var isSending by mutableStateOf(false)
var ageGateUnlocked by mutableStateOf<Boolean?>(null) var ageGateUnlocked by mutableStateOf<Boolean?>(null)
var showGeoGate by mutableStateOf(false) var showGeoGate by mutableStateOf(false)
@ -126,6 +127,7 @@ class ChannelScreenViewModel(
this.denyMessageField = false this.denyMessageField = false
this.denyMessageFieldReasonResource = R.string.typing_blank this.denyMessageFieldReasonResource = R.string.typing_blank
this.editingMessage = null this.editingMessage = null
this.isSending = false
this.ageGateUnlocked = channel?.nsfw != true this.ageGateUnlocked = channel?.nsfw != true
this.showGeoGate = when { this.showGeoGate = when {
channel?.nsfw == true && GeoStateProvider.geoState?.isAgeRestrictedGeo == true -> true channel?.nsfw == true && GeoStateProvider.geoState?.isAgeRestrictedGeo == true -> true
@ -324,10 +326,14 @@ class ChannelScreenViewModel(
} }
fun sendPendingMessage() { fun sendPendingMessage() {
if (isSending) return
if (editingMessage != null) { if (editingMessage != null) {
viewModelScope.launch { viewModelScope.launch {
isSending = true
applyMessageEdit() applyMessageEdit()
editingMessage = null editingMessage = null
isSending = false
} }
return return
} }
@ -341,6 +347,7 @@ class ChannelScreenViewModel(
// First we upload (the next 5) attachments... // First we upload (the next 5) attachments...
viewModelScope.launch { viewModelScope.launch {
isSending = true
val attachmentIds = arrayListOf<String>() val attachmentIds = arrayListOf<String>()
val takenAttachments = val takenAttachments =
this@ChannelScreenViewModel.draftAttachments.take(MAX_ATTACHMENTS_PER_MESSAGE) this@ChannelScreenViewModel.draftAttachments.take(MAX_ATTACHMENTS_PER_MESSAGE)
@ -362,6 +369,7 @@ class ChannelScreenViewModel(
} catch (e: Exception) { } catch (e: Exception) {
Log.e("ChannelScreenViewModel", "Failed to upload attachment", e) Log.e("ChannelScreenViewModel", "Failed to upload attachment", e)
attachmentUploadProgress = 0f attachmentUploadProgress = 0f
isSending = false
// TODO show error message // TODO show error message
return@launch return@launch
} }
@ -408,6 +416,8 @@ class ChannelScreenViewModel(
} catch (e: Exception) { } catch (e: Exception) {
Log.e("ChannelScreenViewModel", "Failed to send message", e) Log.e("ChannelScreenViewModel", "Failed to send message", e)
updateItems(listOf(ChannelScreenItem.FailedMessage(prospectiveMessage)) + items.filter { it !is ChannelScreenItem.ProspectiveMessage }) updateItems(listOf(ChannelScreenItem.FailedMessage(prospectiveMessage)) + items.filter { it !is ChannelScreenItem.ProspectiveMessage })
} finally {
isSending = false
} }
} }
} }
@ -434,7 +444,14 @@ class ChannelScreenViewModel(
try { try {
val messages = arrayListOf<Message>() val messages = arrayListOf<Message>()
fetchMessagesFromChannel(currentChannelId, amount, true, before, after, around).let { fetchMessagesFromChannel(
currentChannelId,
amount,
true,
before,
after,
around
).let {
if (it.messages.isNullOrEmpty() || it.messages!!.size < 50) { if (it.messages.isNullOrEmpty() || it.messages!!.size < 50) {
endOfChannel = true endOfChannel = true
} }