I am still struggling to make the tracking plugin work perfectly with the collab module. I changed the trackingFunction (which is used both in the server and inside the plugin) to receive a list of steps, each one of the steps will also have the userId of the user who executed the step.
When the user types something I add the logged user id to the steps:
dispatchTransaction: transaction => {
this.addUserIdToLocalSteps(transaction)
this.dispatchTransaction(transaction);
},
....
private addUserIdToLocalSteps(transaction){
transaction.steps.forEach(step => step.userId = this.authService.getLoggedUser().id);
}
When I receive new steps from the server I parse them and add the userId:
private getNewVersionFromServer(){
...
this.canvasBackendConnector
.getStepsSince(getVersion(this.localCanvasState))
.then(canvasSteps => this.parseStepsAndAddUserId(canvasSteps))
.then(stepsAndClientIDs => this.receiveRemoteSteps(stepsAndClientIDs))
...
}
...
private parseStepsAndAddUserId(canvasSteps: CanvasStep[]){
const proseMirrorSteps = [];
const clientIDs = [];
canvasSteps.forEach(canvasStep => {
const parsedStep = Step.fromJSON(canvasSchema, canvasStep.proseMirrorStep);
parsedStep.userId = canvasStep.userId;
proseMirrorSteps.push(parsedStep);
clientIDs.push(canvasStep.clientID);
});
return {proseMirrorSteps, clientIDs};
}
...
private receiveRemoteSteps(stepsAndClientIDs){
const transaction = receiveTransaction(this.localCanvasState, stepsAndClientIDs.proseMirrorSteps, stepsAndClientIDs.clientIDs);
this.serverTransaction$.next(transaction);
}
Everything works perfectly until there is a conflict. When the conflict happens receiveTramsaction will rebase the steps and when that happens the ‘userId’ information will be lost and the tracking plugin will not work.
I was thinking that only local steps get rebased so only local steps can lose the ‘userId’. If that is the case I could loop through the steps of the transaction returned by receiveTransaction and add the loggedUserId to the ones which don’t have an ‘userId’.
Is that assumption correct ?