Skip to content

Commit 0143bf5

Browse files
committed
[ECO-5426] Implemented snippet to populate missing fields for objects
1 parent 6fa439d commit 0143bf5

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

live-objects/src/main/kotlin/io/ably/lib/objects/DefaultLiveObjects.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package io.ably.lib.objects
33
import io.ably.lib.types.Callback
44
import io.ably.lib.types.ProtocolMessage
55
import io.ably.lib.util.Log
6+
import java.util.*
67

78
internal class DefaultLiveObjects(private val channelName: String, private val adapter: LiveObjectsAdapter): LiveObjects {
89
private val tag = DefaultLiveObjects::class.simpleName
@@ -47,14 +48,22 @@ internal class DefaultLiveObjects(private val channelName: String, private val a
4748
TODO("Not yet implemented")
4849
}
4950

50-
fun handle(msg: ProtocolMessage) {
51+
fun handle(protocolMessage: ProtocolMessage) {
5152
// RTL15b
52-
msg.channelSerial?.let {
53-
if (msg.action === ProtocolMessage.Action.`object`) {
54-
Log.v(tag, "Setting channel serial for channelName: $channelName, value: ${msg.channelSerial}")
55-
adapter.setChannelSerial(channelName, msg.channelSerial)
53+
protocolMessage.channelSerial?.let {
54+
if (protocolMessage.action === ProtocolMessage.Action.`object`) {
55+
Log.v(tag, "Setting channel serial for channelName: $channelName, value: ${protocolMessage.channelSerial}")
56+
adapter.setChannelSerial(channelName, protocolMessage.channelSerial)
5657
}
5758
}
59+
// Populate missing fields from parent
60+
val objects = protocolMessage.state.filterIsInstance<ObjectMessage>().mapIndexed { index, stateItem ->
61+
stateItem.copy(
62+
connectionId = stateItem.connectionId ?: protocolMessage.connectionId,
63+
timestamp = stateItem.timestamp ?: protocolMessage.timestamp,
64+
id = stateItem.id ?: (protocolMessage.id + ':' + index)
65+
)
66+
}
5867
}
5968

6069
fun dispose() {

0 commit comments

Comments
 (0)