Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,14 @@ import io.getstream.chat.android.client.extensions.internal.hasPendingAttachment
import io.getstream.chat.android.core.internal.InternalStreamChatApi
import io.getstream.chat.android.models.Message
import io.getstream.chat.android.models.MessageType
import java.util.regex.Pattern

private val COMMAND_PATTERN = Pattern.compile("^/[a-z]*$")

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

return if (COMMAND_PATTERN.matcher(message.text).find() || (hasAttachments && hasAttachmentsToUpload)) {
return if (hasAttachments && hasAttachmentsToUpload) {
MessageType.EPHEMERAL
} else if (message.type == MessageType.SYSTEM) {
MessageType.SYSTEM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ import org.junit.jupiter.api.Test

internal class MessageUtilsTest {

@Test
fun testCommandMessage() {
val message = Message(text = "/command")
val updatedMessageType = getMessageType(message)
updatedMessageType `should be equal to` MessageType.EPHEMERAL
}

@Test
fun testMessageWithAttachmentsInUploadStateIdle() {
val message = Message(
Expand Down
Loading