mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-02-01 03:12:42 +01:00
collab_client: Factor out duplicate ACCEPT_COMMIT
code
This commit is contained in:
parent
dd09a3f12b
commit
81b9a2544d
1 changed files with 15 additions and 27 deletions
|
@ -119,15 +119,7 @@ const getCollabClient = (ace2editor, serverVars, initialUserInfo, options, _pad)
|
||||||
const newRev = msg.newRev;
|
const newRev = msg.newRev;
|
||||||
rev = newRev;
|
rev = newRev;
|
||||||
if (msg.type === 'ACCEPT_COMMIT') {
|
if (msg.type === 'ACCEPT_COMMIT') {
|
||||||
editor.applyPreparedChangesetToBase();
|
acceptCommit();
|
||||||
setStateIdle();
|
|
||||||
callCatchingErrors('onInternalAction', () => {
|
|
||||||
callbacks.onInternalAction('commitAcceptedByServer');
|
|
||||||
});
|
|
||||||
callCatchingErrors('onConnectionTrouble', () => {
|
|
||||||
callbacks.onConnectionTrouble('OK');
|
|
||||||
});
|
|
||||||
handleUserChanges();
|
|
||||||
} else if (msg.type === 'NEW_CHANGES') {
|
} else if (msg.type === 'NEW_CHANGES') {
|
||||||
const changeset = msg.changeset;
|
const changeset = msg.changeset;
|
||||||
const author = (msg.author || '');
|
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 = () => {
|
const setUpSocket = () => {
|
||||||
setChannelState('CONNECTED');
|
setChannelState('CONNECTED');
|
||||||
doDeferredActions();
|
doDeferredActions();
|
||||||
|
@ -257,15 +261,7 @@ const getCollabClient = (ace2editor, serverVars, initialUserInfo, options, _pad)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
rev = newRev;
|
rev = newRev;
|
||||||
editor.applyPreparedChangesetToBase();
|
acceptCommit();
|
||||||
setStateIdle();
|
|
||||||
callCatchingErrors('onInternalAction', () => {
|
|
||||||
callbacks.onInternalAction('commitAcceptedByServer');
|
|
||||||
});
|
|
||||||
callCatchingErrors('onConnectionTrouble', () => {
|
|
||||||
callbacks.onConnectionTrouble('OK');
|
|
||||||
});
|
|
||||||
handleUserChanges();
|
|
||||||
} else if (msg.type === 'CLIENT_RECONNECT') {
|
} else if (msg.type === 'CLIENT_RECONNECT') {
|
||||||
// Server sends a CLIENT_RECONNECT message when there is a 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
|
// 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;
|
rev = newRev;
|
||||||
if (author === pad.getUserId()) {
|
if (author === pad.getUserId()) {
|
||||||
editor.applyPreparedChangesetToBase();
|
acceptCommit();
|
||||||
setStateIdle();
|
|
||||||
callCatchingErrors('onInternalAction', () => {
|
|
||||||
callbacks.onInternalAction('commitAcceptedByServer');
|
|
||||||
});
|
|
||||||
callCatchingErrors('onConnectionTrouble', () => {
|
|
||||||
callbacks.onConnectionTrouble('OK');
|
|
||||||
});
|
|
||||||
handleUserChanges();
|
|
||||||
} else {
|
} else {
|
||||||
editor.applyChangesToBase(changeset, author, apool);
|
editor.applyChangesToBase(changeset, author, apool);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue