Pad: Return new rev number from `appendRevision()`

pull/5328/head
Richard Hansen 2021-12-12 18:10:33 -05:00
parent c05ee7ce72
commit 56b7671422
2 changed files with 6 additions and 10 deletions

View File

@ -119,6 +119,7 @@ Pad.prototype.appendRevision = async function (aChangeset, author) {
}
await Promise.all(p);
return newRev;
};
// save all attributes to the database

View File

@ -639,8 +639,8 @@ const handleUserChanges = async (socket, message) => {
`${Changeset.oldLen(rebasedChangeset)} to document of length ${prevText.length}`);
}
await pad.appendRevision(rebasedChangeset, thisSession.author);
assert.equal(pad.getHeadRevisionNumber(), r + 1);
const newRev = await pad.appendRevision(rebasedChangeset, thisSession.author);
assert.equal(newRev, r + 1);
const correctionChangeset = _correctMarkersInPad(pad.atext, pad.pool);
if (correctionChangeset) {
@ -656,14 +656,9 @@ const handleUserChanges = async (socket, message) => {
// 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);
socket.json.send({type: 'COLLABROOM', data: {type: 'ACCEPT_COMMIT', newRev}});
thisSession.rev = newRev;
thisSession.time = await pad.getRevisionDate(newRev);
await exports.updatePadClients(pad);
} catch (err) {
socket.json.send({disconnect: 'badChangeset'});