Skip to content

Commit

Permalink
fix: add missing channel modes for message channel
Browse files Browse the repository at this point in the history
  • Loading branch information
ttypic committed Dec 10, 2024
1 parent 4d32877 commit 2c12aa3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
20 changes: 13 additions & 7 deletions chat-android/src/main/java/com/ably/chat/RoomOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,20 @@ internal fun RoomOptions.validateRoomOptions() {
internal fun RoomOptions.messagesChannelOptions(): ChannelOptions {
return ChatChannelOptions {
presence?.let {
val presenceModes = mutableListOf<ChannelMode>()
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(
Expand Down
22 changes: 21 additions & 1 deletion chat-android/src/test/java/com/ably/chat/SandboxTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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<MessageEvent>()

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()
Expand Down

0 comments on commit 2c12aa3

Please sign in to comment.