collab_client: Factor out duplicate `ACCEPT_COMMIT` code

pull/4986/head
Richard Hansen 2021-03-26 19:33:14 -04:00
parent dd09a3f12b
commit 81b9a2544d
1 changed files with 15 additions and 27 deletions

View File

@ -119,15 +119,7 @@ const getCollabClient = (ace2editor, serverVars, initialUserInfo, options, _pad)
const newRev = msg.newRev;
rev = newRev;
if (msg.type === 'ACCEPT_COMMIT') {
editor.applyPreparedChangesetToBase();
setStateIdle();
callCatchingErrors('onInternalAction', () => {
callbacks.onInternalAction('commitAcceptedByServer');
});
callCatchingErrors('onConnectionTrouble', () => {
callbacks.onConnectionTrouble('OK');
});
handleUserChanges();
acceptCommit();
} else if (msg.type === 'NEW_CHANGES') {
const changeset = msg.changeset;
const author = (msg.author || '');
@ -170,6 +162,18 @@ const getCollabClient = (ace2editor, serverVars, initialUserInfo, options, _pad)
}
};
const acceptCommit = () => {
editor.applyPreparedChangesetToBase();
setStateIdle();
callCatchingErrors('onInternalAction', () => {
callbacks.onInternalAction('commitAcceptedByServer');
});
callCatchingErrors('onConnectionTrouble', () => {
callbacks.onConnectionTrouble('OK');
});
handleUserChanges();
};
const setUpSocket = () => {
setChannelState('CONNECTED');
doDeferredActions();
@ -257,15 +261,7 @@ const getCollabClient = (ace2editor, serverVars, initialUserInfo, options, _pad)
return;
}
rev = newRev;
editor.applyPreparedChangesetToBase();
setStateIdle();
callCatchingErrors('onInternalAction', () => {
callbacks.onInternalAction('commitAcceptedByServer');
});
callCatchingErrors('onConnectionTrouble', () => {
callbacks.onConnectionTrouble('OK');
});
handleUserChanges();
acceptCommit();
} else if (msg.type === 'CLIENT_RECONNECT') {
// Server sends a CLIENT_RECONNECT message when there is a client reconnect.
// Server also returns all pending revisions along with this CLIENT_RECONNECT message
@ -301,15 +297,7 @@ const getCollabClient = (ace2editor, serverVars, initialUserInfo, options, _pad)
rev = newRev;
if (author === pad.getUserId()) {
editor.applyPreparedChangesetToBase();
setStateIdle();
callCatchingErrors('onInternalAction', () => {
callbacks.onInternalAction('commitAcceptedByServer');
});
callCatchingErrors('onConnectionTrouble', () => {
callbacks.onConnectionTrouble('OK');
});
handleUserChanges();
acceptCommit();
} else {
editor.applyChangesToBase(changeset, author, apool);
}