diff --git a/chat-android/src/main/java/com/ably/chat/RoomOptions.kt b/chat-android/src/main/java/com/ably/chat/RoomOptions.kt index 03f20304..efb65e2b 100644 --- a/chat-android/src/main/java/com/ably/chat/RoomOptions.kt +++ b/chat-android/src/main/java/com/ably/chat/RoomOptions.kt @@ -121,14 +121,20 @@ internal fun RoomOptions.validateRoomOptions() { internal fun RoomOptions.messagesChannelOptions(): ChannelOptions { return ChatChannelOptions { presence?.let { - val presenceModes = mutableListOf() - if (presence.enter) { - presenceModes.add(ChannelMode.presence) - } - if (presence.subscribe) { - presenceModes.add(ChannelMode.presence_subscribe) + val channelModes = buildList { + // We should have this modes for regular messages + add(ChannelMode.publish) + add(ChannelMode.subscribe) + + if (presence.enter) { + add(ChannelMode.presence) + } + if (presence.subscribe) { + add(ChannelMode.presence_subscribe) + } } - modes = presenceModes.toTypedArray() + + modes = channelModes.toTypedArray() } occupancy?.let { params = mapOf( diff --git a/chat-android/src/test/java/com/ably/chat/SandboxTest.kt b/chat-android/src/test/java/com/ably/chat/SandboxTest.kt index 76e96488..8a19df34 100644 --- a/chat-android/src/test/java/com/ably/chat/SandboxTest.kt +++ b/chat-android/src/test/java/com/ably/chat/SandboxTest.kt @@ -109,7 +109,7 @@ class SandboxTest { } @Test - fun `should be able to send and retrieve messages`() = runTest { + fun `should be able to send and retrieve messages without room features`() = runTest { val chatClient = sandbox.createSandboxChatClient() val roomId = UUID.randomUUID().toString() @@ -128,6 +128,26 @@ class SandboxTest { ) } + @Test + fun `should be able to send and retrieve messages with all room features enabled`() = runTest { + val chatClient = sandbox.createSandboxChatClient() + val roomId = UUID.randomUUID().toString() + + val room = chatClient.rooms.get(roomId, RoomOptions.default) + + room.attach() + + val messageEvent = CompletableDeferred() + + room.messages.subscribe { messageEvent.complete(it) } + room.messages.send("hello") + + assertEquals( + "hello", + messageEvent.await().message.text, + ) + } + @Test fun `should be able to send and retrieve messages from history`() = runTest { val chatClient = sandbox.createSandboxChatClient()