fix: sending the same draft while it's sending

Also fixes the same issue while attachments upload, too

closes #33

Signed-off-by: Amy <amy+git@amogus.cloud>
This commit is contained in:
Amy 2025-12-07 08:40:06 -04:00
parent 75bb23982b
commit 44b20d6a59
3 changed files with 11 additions and 3 deletions

View File

@ -159,6 +159,7 @@ fun MessageField(
channelId: String? = null,
valueIsBlank: Boolean = false,
editMode: Boolean = false,
sending: Boolean = false,
initialValueDirtyMarker: Any = Unit,
cancelEdit: () -> Unit = {},
onFocusChange: (Boolean) -> Unit = {},
@ -624,12 +625,12 @@ fun MessageField(
editMode -> painterResource(R.drawable.icn_edit_24dp)
else -> painterResource(R.drawable.icn_send_24dp)
},
tint = MaterialTheme.colorScheme.primary,
tint = if (!sending) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.onSurface.copy(alpha = 0.1f),
contentDescription = stringResource(id = R.string.send_alt),
modifier = Modifier
.padding(end = 8.dp)
.clip(CircleShape)
.clickable { onSendMessage() }
.clickable(enabled = !sending) { onSendMessage() }
.size(32.dp)
.padding(4.dp)
.testTag("send_message")
@ -656,6 +657,7 @@ fun NativeMessageFieldPreview() {
canAttach = true,
disabled = false,
editMode = false,
sending = false,
cancelEdit = {},
onFocusChange = {},
)

View File

@ -1092,7 +1092,8 @@ fun ChannelScreen(
cancelEdit = {
viewModel.editingMessage = null
viewModel.putDraftContent("", true)
}
},
sending = viewModel.sendingMessage
)
DropdownMenu(

View File

@ -91,6 +91,7 @@ class ChannelScreenViewModel @Inject constructor(
var draftAttachments = mutableStateListOf<FileArgs>()
var draftReplyTo = mutableStateListOf<SendMessageReply>()
var attachmentUploadProgress by mutableStateOf(0f)
var sendingMessage by mutableStateOf(false)
var endOfChannel by mutableStateOf(false)
var didInitialChannelFetch by mutableStateOf(false)
@ -338,6 +339,7 @@ class ChannelScreenViewModel @Inject constructor(
// the original content
val content = MessageProcessor.processOutgoing(draftContent, channel?.server)
val replyTo = draftReplyTo.toList()
sendingMessage = true
// First we upload (the next 5) attachments...
viewModelScope.launch {
@ -362,6 +364,7 @@ class ChannelScreenViewModel @Inject constructor(
} catch (e: Exception) {
Log.e("ChannelScreenViewModel", "Failed to upload attachment", e)
attachmentUploadProgress = 0f
sendingMessage = false
// TODO show error message
return@launch
}
@ -408,6 +411,8 @@ class ChannelScreenViewModel @Inject constructor(
} catch (e: Exception) {
Log.e("ChannelScreenViewModel", "Failed to send message", e)
updateItems(listOf(ChannelScreenItem.FailedMessage(prospectiveMessage)) + items.filter { it !is ChannelScreenItem.ProspectiveMessage })
} finally {
sendingMessage = false
}
}
}