Browse Source

Prevent sending empty messages (#2527)

* Prevent sending empty messages

* Fix screenshot issue

* Use `aRichTextEditorState` helper function
pull/2533/head
Jorge Martin Espinosa 6 months ago committed by GitHub
parent
commit
3453738344
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      changelog.d/995.bugfix
  2. 4
      features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesStateProvider.kt
  3. 44
      libraries/textcomposer/impl/src/main/kotlin/io/element/android/libraries/textcomposer/TextComposer.kt

1
changelog.d/995.bugfix

@ -0,0 +1 @@ @@ -0,0 +1 @@
Prevent sending empty messages.

4
features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/MessagesStateProvider.kt

@ -43,8 +43,8 @@ import io.element.android.libraries.architecture.AsyncData @@ -43,8 +43,8 @@ import io.element.android.libraries.architecture.AsyncData
import io.element.android.libraries.designsystem.components.avatar.AvatarData
import io.element.android.libraries.designsystem.components.avatar.AvatarSize
import io.element.android.libraries.matrix.api.core.RoomId
import io.element.android.libraries.textcomposer.aRichTextEditorState
import io.element.android.libraries.textcomposer.model.MessageComposerMode
import io.element.android.wysiwyg.compose.RichTextEditorState
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.persistentSetOf
@ -99,7 +99,7 @@ fun aMessagesState( @@ -99,7 +99,7 @@ fun aMessagesState(
userHasPermissionToRedactOther: Boolean = false,
userHasPermissionToSendReaction: Boolean = true,
composerState: MessageComposerState = aMessageComposerState(
richTextEditorState = RichTextEditorState("Hello", initialFocus = true),
richTextEditorState = aRichTextEditorState(initialText = "Hello", initialFocus = true),
isFullScreen = false,
mode = MessageComposerMode.Normal,
),

44
libraries/textcomposer/impl/src/main/kotlin/io/element/android/libraries/textcomposer/TextComposer.kt

@ -172,7 +172,7 @@ fun TextComposer( @@ -172,7 +172,7 @@ fun TextComposer(
}
}
val canSendMessage by remember { derivedStateOf { state.messageHtml.isNotEmpty() } }
val canSendMessage by remember { derivedStateOf { state.messageMarkdown.isNotBlank() } }
val sendButton = @Composable {
SendButton(
canSendMessage = canSendMessage,
@ -598,7 +598,7 @@ internal fun TextComposerSimplePreview() = ElementPreview { @@ -598,7 +598,7 @@ internal fun TextComposerSimplePreview() = ElementPreview {
items = persistentListOf(
{
ATextComposer(
RichTextEditorState("", initialFocus = true),
aRichTextEditorState(initialText = "", initialFocus = true),
voiceMessageState = VoiceMessageState.Idle,
composerMode = MessageComposerMode.Normal,
enableTextFormatting = true,
@ -608,7 +608,7 @@ internal fun TextComposerSimplePreview() = ElementPreview { @@ -608,7 +608,7 @@ internal fun TextComposerSimplePreview() = ElementPreview {
},
{
ATextComposer(
RichTextEditorState("A message", initialFocus = true),
aRichTextEditorState(initialText = "A message", initialFocus = true),
voiceMessageState = VoiceMessageState.Idle,
composerMode = MessageComposerMode.Normal,
enableTextFormatting = true,
@ -618,8 +618,8 @@ internal fun TextComposerSimplePreview() = ElementPreview { @@ -618,8 +618,8 @@ internal fun TextComposerSimplePreview() = ElementPreview {
},
{
ATextComposer(
RichTextEditorState(
"A message\nWith several lines\nTo preview larger textfields and long lines with overflow",
aRichTextEditorState(
initialText = "A message\nWith several lines\nTo preview larger textfields and long lines with overflow",
initialFocus = true
),
voiceMessageState = VoiceMessageState.Idle,
@ -631,7 +631,7 @@ internal fun TextComposerSimplePreview() = ElementPreview { @@ -631,7 +631,7 @@ internal fun TextComposerSimplePreview() = ElementPreview {
},
{
ATextComposer(
RichTextEditorState("A message without focus", initialFocus = false),
aRichTextEditorState(initialText = "A message without focus", initialFocus = false),
voiceMessageState = VoiceMessageState.Idle,
composerMode = MessageComposerMode.Normal,
enableTextFormatting = true,
@ -648,7 +648,7 @@ internal fun TextComposerSimplePreview() = ElementPreview { @@ -648,7 +648,7 @@ internal fun TextComposerSimplePreview() = ElementPreview {
internal fun TextComposerFormattingPreview() = ElementPreview {
PreviewColumn(items = persistentListOf({
ATextComposer(
RichTextEditorState("", initialFocus = false),
aRichTextEditorState(initialText = "", initialFocus = false),
voiceMessageState = VoiceMessageState.Idle,
showTextFormatting = true,
composerMode = MessageComposerMode.Normal,
@ -658,7 +658,7 @@ internal fun TextComposerFormattingPreview() = ElementPreview { @@ -658,7 +658,7 @@ internal fun TextComposerFormattingPreview() = ElementPreview {
)
}, {
ATextComposer(
RichTextEditorState("A message", initialFocus = false),
aRichTextEditorState(initialText = "A message", initialFocus = false),
voiceMessageState = VoiceMessageState.Idle,
showTextFormatting = true,
composerMode = MessageComposerMode.Normal,
@ -668,7 +668,10 @@ internal fun TextComposerFormattingPreview() = ElementPreview { @@ -668,7 +668,10 @@ internal fun TextComposerFormattingPreview() = ElementPreview {
)
}, {
ATextComposer(
RichTextEditorState("A message\nWith several lines\nTo preview larger textfields and long lines with overflow", initialFocus = false),
aRichTextEditorState(
initialText = "A message\nWith several lines\nTo preview larger textfields and long lines with overflow",
initialFocus = false
),
voiceMessageState = VoiceMessageState.Idle,
showTextFormatting = true,
composerMode = MessageComposerMode.Normal,
@ -684,7 +687,7 @@ internal fun TextComposerFormattingPreview() = ElementPreview { @@ -684,7 +687,7 @@ internal fun TextComposerFormattingPreview() = ElementPreview {
internal fun TextComposerEditPreview() = ElementPreview {
PreviewColumn(items = persistentListOf({
ATextComposer(
RichTextEditorState("A message", initialFocus = true),
aRichTextEditorState(initialText = "A message", initialFocus = true),
voiceMessageState = VoiceMessageState.Idle,
composerMode = MessageComposerMode.Edit(EventId("$1234"), "Some text", TransactionId("1234")),
enableTextFormatting = true,
@ -701,7 +704,7 @@ internal fun TextComposerReplyPreview() = ElementPreview { @@ -701,7 +704,7 @@ internal fun TextComposerReplyPreview() = ElementPreview {
items = persistentListOf(
{
ATextComposer(
RichTextEditorState(""),
aRichTextEditorState(""),
voiceMessageState = VoiceMessageState.Idle,
composerMode = MessageComposerMode.Reply(
isThreaded = false,
@ -737,7 +740,7 @@ internal fun TextComposerReplyPreview() = ElementPreview { @@ -737,7 +740,7 @@ internal fun TextComposerReplyPreview() = ElementPreview {
},
{
ATextComposer(
RichTextEditorState("A message"),
aRichTextEditorState(initialText = "A message"),
voiceMessageState = VoiceMessageState.Idle,
composerMode = MessageComposerMode.Reply(
isThreaded = true,
@ -758,7 +761,7 @@ internal fun TextComposerReplyPreview() = ElementPreview { @@ -758,7 +761,7 @@ internal fun TextComposerReplyPreview() = ElementPreview {
},
{
ATextComposer(
RichTextEditorState("A message"),
aRichTextEditorState(initialText = "A message"),
voiceMessageState = VoiceMessageState.Idle,
composerMode = MessageComposerMode.Reply(
isThreaded = false,
@ -779,7 +782,7 @@ internal fun TextComposerReplyPreview() = ElementPreview { @@ -779,7 +782,7 @@ internal fun TextComposerReplyPreview() = ElementPreview {
},
{
ATextComposer(
RichTextEditorState("A message"),
aRichTextEditorState(initialText = "A message"),
voiceMessageState = VoiceMessageState.Idle,
composerMode = MessageComposerMode.Reply(
isThreaded = false,
@ -800,7 +803,7 @@ internal fun TextComposerReplyPreview() = ElementPreview { @@ -800,7 +803,7 @@ internal fun TextComposerReplyPreview() = ElementPreview {
},
{
ATextComposer(
RichTextEditorState("A message", initialFocus = true),
aRichTextEditorState(initialText = "A message", initialFocus = true),
voiceMessageState = VoiceMessageState.Idle,
composerMode = MessageComposerMode.Reply(
isThreaded = false,
@ -923,3 +926,14 @@ private fun ATextComposer( @@ -923,3 +926,14 @@ private fun ATextComposer(
onRichContentSelected = null,
)
}
fun aRichTextEditorState(
initialText: String = "",
initialHtml: String = initialText,
initialMarkdown: String = initialText,
initialFocus: Boolean = false,
) = RichTextEditorState(
initialHtml = initialHtml,
initialMarkdown = initialMarkdown,
initialFocus = initialFocus,
)

Loading…
Cancel
Save