diff --git a/app/src/main/java/chat/revolt/components/chat/NativeMessageField.kt b/app/src/main/java/chat/revolt/components/chat/NativeMessageField.kt index 89188657..d2f1ea11 100644 --- a/app/src/main/java/chat/revolt/components/chat/NativeMessageField.kt +++ b/app/src/main/java/chat/revolt/components/chat/NativeMessageField.kt @@ -158,6 +158,7 @@ fun NativeMessageField( forceSendButton: Boolean = false, canAttach: Boolean = true, disabled: Boolean = false, + failedValidation: Boolean = false, serverId: String? = null, channelId: String? = null, editMode: Boolean = false, @@ -176,7 +177,8 @@ fun NativeMessageField( var requestFocus by remember { mutableStateOf({}) } var clearFocus by remember { mutableStateOf({}) } - val sendButtonVisible = (value.isNotBlank() || forceSendButton) && !disabled + val sendButtonVisible = + (value.isNotBlank() || forceSendButton) && !disabled && !failedValidation val density = LocalDensity.current @@ -184,6 +186,7 @@ fun NativeMessageField( val selectionColour = MaterialTheme.colorScheme.primary.copy(alpha = 0.2f).toArgb() val cursorColour = MaterialTheme.colorScheme.primary.toArgb() + val failedValidationColour = MaterialTheme.colorScheme.error.toArgb() val contentColour = LocalContentColor.current.toArgb() val placeholderColour = LocalContentColor.current.copy(alpha = 0.5f).toArgb() @@ -524,6 +527,11 @@ fun NativeMessageField( } it.hint = it.context.getString(placeholderResource, channelName) it.serverId = serverId + if (failedValidation) { + it.setTextColor(failedValidationColour) + } else { + it.setTextColor(contentColour) + } }, modifier = Modifier .weight(1f) diff --git a/app/src/main/java/chat/revolt/screens/chat/views/channel/ChannelScreen.kt b/app/src/main/java/chat/revolt/screens/chat/views/channel/ChannelScreen.kt index 3f60030b..0d10dc81 100644 --- a/app/src/main/java/chat/revolt/screens/chat/views/channel/ChannelScreen.kt +++ b/app/src/main/java/chat/revolt/screens/chat/views/channel/ChannelScreen.kt @@ -5,7 +5,6 @@ import android.net.Uri import android.os.Build import android.os.Environment import android.provider.MediaStore -import android.util.Log import android.widget.Toast import androidx.activity.compose.BackHandler import androidx.activity.compose.rememberLauncherForActivityResult @@ -73,8 +72,6 @@ import chat.revolt.api.routes.channel.react import chat.revolt.api.routes.microservices.autumn.FileArgs import chat.revolt.api.schemas.Channel import chat.revolt.api.schemas.ChannelType -import chat.revolt.callbacks.Action -import chat.revolt.callbacks.ActionChannel import chat.revolt.components.chat.Message import chat.revolt.components.chat.NativeMessageField import chat.revolt.components.chat.SystemMessage @@ -288,6 +285,12 @@ fun ChannelScreen( } } + val isMessageTooLong by remember(viewModel.pendingMessageContent) { + derivedStateOf { + viewModel.pendingMessageContent.length > MAX_MESSAGE_LENGTH + } + } + LaunchedEffect(isScrolledToTop) { snapshotFlow { isScrolledToTop.value } .distinctUntilChanged() @@ -530,6 +533,7 @@ fun ChannelScreen( serverId = channel?.server, editMode = viewModel.editingMessage != null, cancelEdit = viewModel::cancelEditingMessage, + failedValidation = isMessageTooLong, onFocusChange = { nowFocused -> if (nowFocused && viewModel.currentBottomPane != BottomPane.None) { viewModel.currentBottomPane = BottomPane.None diff --git a/app/src/main/java/chat/revolt/screens/chat/views/channel/ChannelScreenViewModel.kt b/app/src/main/java/chat/revolt/screens/chat/views/channel/ChannelScreenViewModel.kt index 917cda9f..30b2a0d6 100644 --- a/app/src/main/java/chat/revolt/screens/chat/views/channel/ChannelScreenViewModel.kt +++ b/app/src/main/java/chat/revolt/screens/chat/views/channel/ChannelScreenViewModel.kt @@ -59,6 +59,8 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import kotlinx.datetime.Instant +const val MAX_MESSAGE_LENGTH = 2000 + sealed class BottomPane { data object None : BottomPane() data object InbuiltMediaPicker : BottomPane()