Fix handleHandshakeMsg
This commit is contained in:
parent
3785285e4d
commit
722e08ea82
@ -1065,26 +1065,20 @@ export default class Services {
|
||||
for (const [processId, process] of Object.entries(newProcesses)) {
|
||||
const existing = await this.getProcess(processId);
|
||||
if (existing) {
|
||||
// We check if we have public_data on the first state
|
||||
if (Object.keys(process.states[0].public_data).length != 0) {
|
||||
await this.saveProcessToDb(processId, process as Process);
|
||||
const event = new CustomEvent('process-updated', {
|
||||
detail: { processId }
|
||||
});
|
||||
window.dispatchEvent(event);
|
||||
continue;
|
||||
// Look for state id we don't know yet
|
||||
let new_states = [];
|
||||
let roles = [];
|
||||
for (const state of process.states) {
|
||||
if (!this.lookForStateId(existing, state.state_id)) {
|
||||
|
||||
new_states.push(state.state_id);
|
||||
roles.push(state.roles);
|
||||
}
|
||||
}
|
||||
const lastKnownCommitment = this.getLastCommitedState(existing);
|
||||
const newLastCommitment = this.getLastCommitedState(process);
|
||||
if (!lastKnownCommitment || !newLastCommitment) { continue }
|
||||
if (lastKnownCommitment.commited_in !== newLastCommitment.commited_in) {
|
||||
// Update the process in db with the new one
|
||||
await this.saveProcessToDb(processId, process as Process);
|
||||
console.log('Dispatching process-updated event');
|
||||
const event = new CustomEvent('process-updated', {
|
||||
detail: { processId }
|
||||
});
|
||||
window.dispatchEvent(event);
|
||||
|
||||
if (new_states.length != 0) {
|
||||
// We request the new states
|
||||
await this.requestDataFromPeers(processId, new_states, roles);
|
||||
}
|
||||
|
||||
// Otherwise we're probably just in the initial loading at page initialization
|
||||
@ -1106,6 +1100,16 @@ export default class Services {
|
||||
}
|
||||
}
|
||||
|
||||
private lookForStateId(process: Process, stateId: string): boolean {
|
||||
for (const state of process.states) {
|
||||
if (state.state_id === stateId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retourne la liste de tous les membres ordonnés par leur process id
|
||||
* @returns Un tableau contenant tous les membres
|
||||
|
Loading…
x
Reference in New Issue
Block a user