diff --git a/src/common/lib/client/realtimechannel.ts b/src/common/lib/client/realtimechannel.ts index 5e67ab11e..f915d3d76 100644 --- a/src/common/lib/client/realtimechannel.ts +++ b/src/common/lib/client/realtimechannel.ts @@ -596,8 +596,7 @@ class RealtimeChannel extends EventEmitter { const encoded = message.messages!, firstMessage = encoded[0], - lastMessage = encoded[encoded.length - 1], - channelSerial = message.channelSerial; + lastMessage = encoded[encoded.length - 1]; if ( firstMessage.extras && @@ -639,13 +638,6 @@ class RealtimeChannel extends EventEmitter { } } - for (let i = 0; i < messages.length; i++) { - const msg = messages[i]; - if (channelSerial && !msg.version) { - msg.version = channelSerial + ':' + i.toString().padStart(3, '0'); - } - } - this._lastPayload.messageId = lastMessage.id; this._lastPayload.protocolMessageChannelSerial = message.channelSerial; this.onEvent(messages); diff --git a/src/common/lib/types/basemessage.ts b/src/common/lib/types/basemessage.ts index 749ca5b03..7665b5ffe 100644 --- a/src/common/lib/types/basemessage.ts +++ b/src/common/lib/types/basemessage.ts @@ -218,11 +218,20 @@ export function wireToJSON(this: BaseMessage, ...args: any[]): any { // in-place, generally called on the protocol message before decoding export function populateFieldsFromParent(parent: ProtocolMessage) { + const { id, connectionId, timestamp, channelSerial } = parent; + let msgs: BaseMessage[]; switch (parent.action) { - case actions.MESSAGE: + case actions.MESSAGE: { msgs = parent.messages!; + for (let i = 0; i < msgs.length; i++) { + const msg = parent.messages![i]; + if (channelSerial && !msg.version) { + msg.version = channelSerial + ':' + i.toString().padStart(3, '0'); + } + } break; + } case actions.PRESENCE: case actions.SYNC: msgs = parent.presence!; @@ -231,12 +240,17 @@ export function populateFieldsFromParent(parent: ProtocolMessage) { throw new ErrorInfo('Unexpected action ' + parent.action, 40000, 400); } - const { id, connectionId, timestamp } = parent; for (let i = 0; i < msgs.length; i++) { const msg = msgs[i]; - if (!msg.connectionId) msg.connectionId = connectionId; - if (!msg.timestamp) msg.timestamp = timestamp; - if (id && !msg.id) msg.id = id + ':' + i; + if (!msg.connectionId) { + msg.connectionId = connectionId; + } + if (!msg.timestamp) { + msg.timestamp = timestamp; + } + if (id && !msg.id) { + msg.id = id + ':' + i; + } } }