kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
fix: limit quick chat append, prevent duplicates (#1522)
Limits quick chat append to 200 characters and prevents duplicate appends. Also sets a constant for the max message size. fixes #1511pull/1520/head^2
rodzic
b067a0c0b3
commit
584fe8d6f8
app/src/main/java/com/geeksville/mesh/ui/message
|
@ -101,6 +101,8 @@ import com.geeksville.mesh.ui.theme.AppTheme
|
|||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
private const val MESSAGE_CHARACTER_LIMIT = 200
|
||||
|
||||
internal fun FragmentManager.navigateToMessages(contactKey: String, message: String = "") {
|
||||
val messagesFragment = MessagesFragment().apply {
|
||||
arguments = bundleOf("contactKey" to contactKey, "message" to message)
|
||||
|
@ -253,13 +255,16 @@ internal fun MessageScreen(
|
|||
QuickChatRow(isConnected, quickChat) { action ->
|
||||
if (action.mode == QuickChatAction.Mode.Append) {
|
||||
val originalText = messageInput.value.text
|
||||
val needsSpace = !originalText.endsWith(' ') && originalText.isNotEmpty()
|
||||
val newText = buildString {
|
||||
append(originalText)
|
||||
if (needsSpace) append(' ')
|
||||
append(action.message)
|
||||
if (!originalText.contains(action.message)) {
|
||||
val needsSpace =
|
||||
!originalText.endsWith(' ') && originalText.isNotEmpty()
|
||||
val newText = buildString {
|
||||
append(originalText)
|
||||
if (needsSpace) append(' ')
|
||||
append(action.message)
|
||||
}.take(MESSAGE_CHARACTER_LIMIT)
|
||||
messageInput.value = TextFieldValue(newText, TextRange(newText.length))
|
||||
}
|
||||
messageInput.value = TextFieldValue(newText, TextRange(newText.length))
|
||||
} else {
|
||||
viewModel.sendMessage(action.message, contactKey)
|
||||
}
|
||||
|
@ -419,7 +424,7 @@ private fun TextInput(
|
|||
enabled: Boolean,
|
||||
message: MutableState<TextFieldValue>,
|
||||
modifier: Modifier = Modifier,
|
||||
maxSize: Int = 200,
|
||||
maxSize: Int = MESSAGE_CHARACTER_LIMIT,
|
||||
onClick: (String) -> Unit = {}
|
||||
) = Column(modifier) {
|
||||
val focusManager = LocalFocusManager.current
|
||||
|
|
Ładowanie…
Reference in New Issue