Skip to content

Commit 94d676b

Browse files
authored
Merge pull request #1945 from ably/fix-not-populating-serial
Message: fix parent-populated version not being propagated to serial
2 parents 3bf3d7a + 4997199 commit 94d676b

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/common/lib/client/realtimechannel.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,7 @@ class RealtimeChannel extends EventEmitter {
596596

597597
const encoded = message.messages!,
598598
firstMessage = encoded[0],
599-
lastMessage = encoded[encoded.length - 1],
600-
channelSerial = message.channelSerial;
599+
lastMessage = encoded[encoded.length - 1];
601600

602601
if (
603602
firstMessage.extras &&
@@ -639,13 +638,6 @@ class RealtimeChannel extends EventEmitter {
639638
}
640639
}
641640

642-
for (let i = 0; i < messages.length; i++) {
643-
const msg = messages[i];
644-
if (channelSerial && !msg.version) {
645-
msg.version = channelSerial + ':' + i.toString().padStart(3, '0');
646-
}
647-
}
648-
649641
this._lastPayload.messageId = lastMessage.id;
650642
this._lastPayload.protocolMessageChannelSerial = message.channelSerial;
651643
this.onEvent(messages);

src/common/lib/types/basemessage.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,20 @@ export function wireToJSON(this: BaseMessage, ...args: any[]): any {
218218

219219
// in-place, generally called on the protocol message before decoding
220220
export function populateFieldsFromParent(parent: ProtocolMessage) {
221+
const { id, connectionId, timestamp, channelSerial } = parent;
222+
221223
let msgs: BaseMessage[];
222224
switch (parent.action) {
223-
case actions.MESSAGE:
225+
case actions.MESSAGE: {
224226
msgs = parent.messages!;
227+
for (let i = 0; i < msgs.length; i++) {
228+
const msg = parent.messages![i];
229+
if (channelSerial && !msg.version) {
230+
msg.version = channelSerial + ':' + i.toString().padStart(3, '0');
231+
}
232+
}
225233
break;
234+
}
226235
case actions.PRESENCE:
227236
case actions.SYNC:
228237
msgs = parent.presence!;
@@ -231,12 +240,17 @@ export function populateFieldsFromParent(parent: ProtocolMessage) {
231240
throw new ErrorInfo('Unexpected action ' + parent.action, 40000, 400);
232241
}
233242

234-
const { id, connectionId, timestamp } = parent;
235243
for (let i = 0; i < msgs.length; i++) {
236244
const msg = msgs[i];
237-
if (!msg.connectionId) msg.connectionId = connectionId;
238-
if (!msg.timestamp) msg.timestamp = timestamp;
239-
if (id && !msg.id) msg.id = id + ':' + i;
245+
if (!msg.connectionId) {
246+
msg.connectionId = connectionId;
247+
}
248+
if (!msg.timestamp) {
249+
msg.timestamp = timestamp;
250+
}
251+
if (id && !msg.id) {
252+
msg.id = id + ':' + i;
253+
}
240254
}
241255
}
242256

0 commit comments

Comments
 (0)