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)) {
|
for (const [processId, process] of Object.entries(newProcesses)) {
|
||||||
const existing = await this.getProcess(processId);
|
const existing = await this.getProcess(processId);
|
||||||
if (existing) {
|
if (existing) {
|
||||||
// We check if we have public_data on the first state
|
// Look for state id we don't know yet
|
||||||
if (Object.keys(process.states[0].public_data).length != 0) {
|
let new_states = [];
|
||||||
await this.saveProcessToDb(processId, process as Process);
|
let roles = [];
|
||||||
const event = new CustomEvent('process-updated', {
|
for (const state of process.states) {
|
||||||
detail: { processId }
|
if (!this.lookForStateId(existing, state.state_id)) {
|
||||||
});
|
|
||||||
window.dispatchEvent(event);
|
new_states.push(state.state_id);
|
||||||
continue;
|
roles.push(state.roles);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const lastKnownCommitment = this.getLastCommitedState(existing);
|
|
||||||
const newLastCommitment = this.getLastCommitedState(process);
|
if (new_states.length != 0) {
|
||||||
if (!lastKnownCommitment || !newLastCommitment) { continue }
|
// We request the new states
|
||||||
if (lastKnownCommitment.commited_in !== newLastCommitment.commited_in) {
|
await this.requestDataFromPeers(processId, new_states, roles);
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise we're probably just in the initial loading at page initialization
|
// 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
|
* Retourne la liste de tous les membres ordonnés par leur process id
|
||||||
* @returns Un tableau contenant tous les membres
|
* @returns Un tableau contenant tous les membres
|
||||||
|
Loading…
x
Reference in New Issue
Block a user