Skip to content

Message: fix parent-populated version not being propagated to serial #1945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions src/common/lib/client/realtimechannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down Expand Up @@ -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);
Expand Down
24 changes: 19 additions & 5 deletions src/common/lib/types/basemessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!;
Expand All @@ -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;
}
}
}

Expand Down
Loading