Skip to content

Commit 02e4407

Browse files
VelikovPetarclaude
andauthored
Fix sending wrong type for incomplete command messages (#6236)
* Fix wrong message type for commands in getMessageType() Co-Authored-By: Claude <noreply@anthropic.com> * Fix KDoc --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 73f14e6 commit 02e4407

2 files changed

Lines changed: 4 additions & 14 deletions

File tree

  • stream-chat-android-client/src/main/java/io/getstream/chat/android/client/utils/internal
  • stream-chat-android-state/src/test/java/io/getstream/chat/android/client/utils/internal

stream-chat-android-client/src/main/java/io/getstream/chat/android/client/utils/internal/MessageUtils.kt

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,14 @@ import io.getstream.chat.android.client.extensions.internal.hasPendingAttachment
2020
import io.getstream.chat.android.core.internal.InternalStreamChatApi
2121
import io.getstream.chat.android.models.Message
2222
import io.getstream.chat.android.models.MessageType
23-
import java.util.regex.Pattern
24-
25-
private val COMMAND_PATTERN = Pattern.compile("^/[a-z]*$")
2623

2724
/**
2825
* Updates the type of the [Message] based on its content.
2926
*
30-
* If the message contains a command or has attachments to upload, the type will be [MessageType.EPHEMERAL].
27+
* If the message has attachments to upload, the type will be [MessageType.EPHEMERAL] (local-only - after the
28+
* attachments are uploaded, the type is changed to [MessageType.REGULAR]).
3129
* If the message is a system message, the type will be [MessageType.SYSTEM].
32-
* Otherwise, the type will be [MessageType.REGULAR], as we cannot send messages which are not regular, ephemeral, or
33-
* system.
30+
* Otherwise, the type will be [MessageType.REGULAR], as we cannot send messages which are not regular or system.
3431
*
3532
* @param message The message to update.
3633
*/
@@ -39,7 +36,7 @@ public fun getMessageType(message: Message): String {
3936
val hasAttachments = message.attachments.isNotEmpty()
4037
val hasAttachmentsToUpload = message.hasPendingAttachments()
4138

42-
return if (COMMAND_PATTERN.matcher(message.text).find() || (hasAttachments && hasAttachmentsToUpload)) {
39+
return if (hasAttachments && hasAttachmentsToUpload) {
4340
MessageType.EPHEMERAL
4441
} else if (message.type == MessageType.SYSTEM) {
4542
MessageType.SYSTEM

stream-chat-android-state/src/test/java/io/getstream/chat/android/client/utils/internal/MessageUtilsTest.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ import org.junit.jupiter.api.Test
2424

2525
internal class MessageUtilsTest {
2626

27-
@Test
28-
fun testCommandMessage() {
29-
val message = Message(text = "/command")
30-
val updatedMessageType = getMessageType(message)
31-
updatedMessageType `should be equal to` MessageType.EPHEMERAL
32-
}
33-
3427
@Test
3528
fun testMessageWithAttachmentsInUploadStateIdle() {
3629
val message = Message(

0 commit comments

Comments
 (0)