Pad: Return new rev number from appendRevision()

This commit is contained in:
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); await Promise.all(p);
return newRev;
}; };
// save all attributes to the database // 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}`); `${Changeset.oldLen(rebasedChangeset)} to document of length ${prevText.length}`);
} }
await pad.appendRevision(rebasedChangeset, thisSession.author); const newRev = await pad.appendRevision(rebasedChangeset, thisSession.author);
assert.equal(pad.getHeadRevisionNumber(), r + 1); assert.equal(newRev, r + 1);
const correctionChangeset = _correctMarkersInPad(pad.atext, pad.pool); const correctionChangeset = _correctMarkersInPad(pad.atext, pad.pool);
if (correctionChangeset) { 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 // 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. // have already sent any previous ACCEPT_COMMIT and NEW_CHANGES messages.
assert.equal(thisSession.rev, r); assert.equal(thisSession.rev, r);
socket.json.send({ socket.json.send({type: 'COLLABROOM', data: {type: 'ACCEPT_COMMIT', newRev}});
type: 'COLLABROOM', thisSession.rev = newRev;
data: { thisSession.time = await pad.getRevisionDate(newRev);
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'});