Skip to content

Commit

Permalink
fix: clientId assignment for sandbox test
Browse files Browse the repository at this point in the history
  • Loading branch information
ttypic committed Nov 18, 2024
1 parent 1eae2c0 commit c2563d4
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions chat-android/src/main/java/com/ably/chat/ChatClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ internal class DefaultChatClient(
realtimeClient = realtime,
chatApi = chatApi,
clientOptions = clientOptions,
clientId = clientId,
)

override val connection: Connection
Expand Down
2 changes: 1 addition & 1 deletion chat-android/src/main/java/com/ably/chat/Messages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions chat-android/src/main/java/com/ably/chat/Room.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions chat-android/src/main/java/com/ably/chat/Rooms.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, DefaultRoom> = mutableMapOf()

Expand All @@ -57,6 +58,7 @@ internal class DefaultRooms(
options = options,
realtimeClient = realtimeClient,
chatApi = chatApi,
clientId = clientId,
)
}

Expand Down
6 changes: 3 additions & 3 deletions chat-android/src/test/java/com/ably/chat/Sandbox.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion chat-android/src/test/java/com/ably/chat/SandboxTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c2563d4

Please sign in to comment.