From 0143bf5a199aaedd783747e001732d013d32a0ee Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Thu, 26 Jun 2025 16:50:36 +0530 Subject: [PATCH] [ECO-5426] Implemented snippet to populate missing fields for objects --- .../io/ably/lib/objects/DefaultLiveObjects.kt | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/live-objects/src/main/kotlin/io/ably/lib/objects/DefaultLiveObjects.kt b/live-objects/src/main/kotlin/io/ably/lib/objects/DefaultLiveObjects.kt index ea88c5e99..b903b4dfc 100644 --- a/live-objects/src/main/kotlin/io/ably/lib/objects/DefaultLiveObjects.kt +++ b/live-objects/src/main/kotlin/io/ably/lib/objects/DefaultLiveObjects.kt @@ -3,6 +3,7 @@ package io.ably.lib.objects import io.ably.lib.types.Callback import io.ably.lib.types.ProtocolMessage import io.ably.lib.util.Log +import java.util.* internal class DefaultLiveObjects(private val channelName: String, private val adapter: LiveObjectsAdapter): LiveObjects { private val tag = DefaultLiveObjects::class.simpleName @@ -47,14 +48,22 @@ internal class DefaultLiveObjects(private val channelName: String, private val a TODO("Not yet implemented") } - fun handle(msg: ProtocolMessage) { + fun handle(protocolMessage: ProtocolMessage) { // RTL15b - msg.channelSerial?.let { - if (msg.action === ProtocolMessage.Action.`object`) { - Log.v(tag, "Setting channel serial for channelName: $channelName, value: ${msg.channelSerial}") - adapter.setChannelSerial(channelName, msg.channelSerial) + protocolMessage.channelSerial?.let { + if (protocolMessage.action === ProtocolMessage.Action.`object`) { + Log.v(tag, "Setting channel serial for channelName: $channelName, value: ${protocolMessage.channelSerial}") + adapter.setChannelSerial(channelName, protocolMessage.channelSerial) } } + // Populate missing fields from parent + val objects = protocolMessage.state.filterIsInstance().mapIndexed { index, stateItem -> + stateItem.copy( + connectionId = stateItem.connectionId ?: protocolMessage.connectionId, + timestamp = stateItem.timestamp ?: protocolMessage.timestamp, + id = stateItem.id ?: (protocolMessage.id + ':' + index) + ) + } } fun dispose() {