From 6f0791312cd3292229a4a83b0657cb48bd677a05 Mon Sep 17 00:00:00 2001 From: evgeny Date: Mon, 18 Nov 2024 12:12:08 +0000 Subject: [PATCH] fix: `clientId` assignment for sandbox test --- chat-android/src/main/java/com/ably/chat/ChatClient.kt | 1 + chat-android/src/main/java/com/ably/chat/Messages.kt | 2 +- chat-android/src/main/java/com/ably/chat/Room.kt | 3 +-- chat-android/src/main/java/com/ably/chat/Rooms.kt | 2 ++ chat-android/src/test/java/com/ably/chat/Sandbox.kt | 6 +++--- chat-android/src/test/java/com/ably/chat/SandboxTest.kt | 2 +- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/chat-android/src/main/java/com/ably/chat/ChatClient.kt b/chat-android/src/main/java/com/ably/chat/ChatClient.kt index ba3e0ef..686c6f1 100644 --- a/chat-android/src/main/java/com/ably/chat/ChatClient.kt +++ b/chat-android/src/main/java/com/ably/chat/ChatClient.kt @@ -61,6 +61,7 @@ internal class DefaultChatClient( realtimeClient = realtime, chatApi = chatApi, clientOptions = clientOptions, + clientId = clientId, ) override val connection: Connection diff --git a/chat-android/src/main/java/com/ably/chat/Messages.kt b/chat-android/src/main/java/com/ably/chat/Messages.kt index e0c8ca8..cf9c411 100644 --- a/chat-android/src/main/java/com/ably/chat/Messages.kt +++ b/chat-android/src/main/java/com/ably/chat/Messages.kt @@ -243,7 +243,7 @@ internal class DefaultMessages( init { channelStateListener = ChannelStateListener { - if (!it.resumed) updateChannelSerialsAfterDiscontinuity() + if (it.current == ChannelState.attached && !it.resumed) updateChannelSerialsAfterDiscontinuity() } channel.on(channelStateListener) } diff --git a/chat-android/src/main/java/com/ably/chat/Room.kt b/chat-android/src/main/java/com/ably/chat/Room.kt index e95097e..70356b4 100644 --- a/chat-android/src/main/java/com/ably/chat/Room.kt +++ b/chat-android/src/main/java/com/ably/chat/Room.kt @@ -89,10 +89,9 @@ internal class DefaultRoom( override val options: RoomOptions, val realtimeClient: RealtimeClient, chatApi: ChatApi, + clientId: String, ) : Room { - private val clientId get() = realtimeClient.auth.clientId - private val _messages = DefaultMessages( roomId = roomId, realtimeChannels = realtimeClient.channels, diff --git a/chat-android/src/main/java/com/ably/chat/Rooms.kt b/chat-android/src/main/java/com/ably/chat/Rooms.kt index 31c0c49..46d4662 100644 --- a/chat-android/src/main/java/com/ably/chat/Rooms.kt +++ b/chat-android/src/main/java/com/ably/chat/Rooms.kt @@ -46,6 +46,7 @@ internal class DefaultRooms( private val realtimeClient: RealtimeClient, private val chatApi: ChatApi, override val clientOptions: ClientOptions, + private val clientId: String, ) : Rooms { private val roomIdToRoom: MutableMap = mutableMapOf() @@ -57,6 +58,7 @@ internal class DefaultRooms( options = options, realtimeClient = realtimeClient, chatApi = chatApi, + clientId = clientId, ) } diff --git a/chat-android/src/test/java/com/ably/chat/Sandbox.kt b/chat-android/src/test/java/com/ably/chat/Sandbox.kt index 0bae074..1b1b043 100644 --- a/chat-android/src/test/java/com/ably/chat/Sandbox.kt +++ b/chat-android/src/test/java/com/ably/chat/Sandbox.kt @@ -39,12 +39,12 @@ class Sandbox private constructor(val appId: String, val apiKey: String) { } } -internal fun Sandbox.createSandboxChatClient(): DefaultChatClient { - val realtime = createSandboxRealtime(apiKey) +internal fun Sandbox.createSandboxChatClient(chatClientId: String = "sandbox-client"): DefaultChatClient { + val realtime = createSandboxRealtime(chatClientId) return DefaultChatClient(realtime, ClientOptions()) } -internal fun Sandbox.createSandboxRealtime(chatClientId: String = "sandbox-client"): AblyRealtime = +internal fun Sandbox.createSandboxRealtime(chatClientId: String): AblyRealtime = AblyRealtime( io.ably.lib.types.ClientOptions().apply { key = apiKey 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 9c459af..6da469b 100644 --- a/chat-android/src/test/java/com/ably/chat/SandboxTest.kt +++ b/chat-android/src/test/java/com/ably/chat/SandboxTest.kt @@ -26,7 +26,7 @@ class SandboxTest { @Test fun `should return yourself as presence member after you entered`() = runTest { - val chatClient = sandbox.createSandboxChatClient() + val chatClient = sandbox.createSandboxChatClient("sandbox-client") val room = chatClient.rooms.get(UUID.randomUUID().toString()) room.attach() room.presence.enter()