PadMessageHandler: Move `ACCEPT_COMMIT` after changeset save

pull/5328/head
Richard Hansen 2021-12-12 18:03:16 -05:00
parent dbacc73c36
commit c05ee7ce72
1 changed files with 25 additions and 18 deletions

View File

@ -640,6 +640,7 @@ const handleUserChanges = async (socket, message) => {
} }
await pad.appendRevision(rebasedChangeset, thisSession.author); await pad.appendRevision(rebasedChangeset, thisSession.author);
assert.equal(pad.getHeadRevisionNumber(), r + 1);
const correctionChangeset = _correctMarkersInPad(pad.atext, pad.pool); const correctionChangeset = _correctMarkersInPad(pad.atext, pad.pool);
if (correctionChangeset) { if (correctionChangeset) {
@ -652,6 +653,17 @@ const handleUserChanges = async (socket, message) => {
await pad.appendRevision(nlChangeset); await pad.appendRevision(nlChangeset);
} }
// The client assumes that ACCEPT_COMMIT and NEW_CHANGES messages arrive in order. Make sure we
// have already sent any previous ACCEPT_COMMIT and NEW_CHANGES messages.
assert.equal(thisSession.rev, r);
socket.json.send({
type: 'COLLABROOM',
data: {
type: 'ACCEPT_COMMIT',
newRev: ++thisSession.rev,
},
});
thisSession.time = await pad.getRevisionDate(thisSession.rev);
await exports.updatePadClients(pad); await exports.updatePadClients(pad);
} catch (err) { } catch (err) {
socket.json.send({disconnect: 'badChangeset'}); socket.json.send({disconnect: 'badChangeset'});
@ -697,24 +709,19 @@ exports.updatePadClients = async (pad) => {
const revChangeset = revision.changeset; const revChangeset = revision.changeset;
const currentTime = revision.meta.timestamp; const currentTime = revision.meta.timestamp;
let msg; const forWire = Changeset.prepareForWire(revChangeset, pad.pool);
if (author === sessioninfo.author) { const msg = {
msg = {type: 'COLLABROOM', data: {type: 'ACCEPT_COMMIT', newRev: r}}; type: 'COLLABROOM',
} else { data: {
const forWire = Changeset.prepareForWire(revChangeset, pad.pool); type: 'NEW_CHANGES',
msg = { newRev: r,
type: 'COLLABROOM', changeset: forWire.translated,
data: { apool: forWire.pool,
type: 'NEW_CHANGES', author,
newRev: r, currentTime,
changeset: forWire.translated, timeDelta: currentTime - sessioninfo.time,
apool: forWire.pool, },
author, };
currentTime,
timeDelta: currentTime - sessioninfo.time,
},
};
}
try { try {
socket.json.send(msg); socket.json.send(msg);
} catch (err) { } catch (err) {