From 722e08ea8237b38f6855a769e30d797c07e3c2b7 Mon Sep 17 00:00:00 2001 From: NicolasCantu Date: Tue, 4 Mar 2025 14:55:35 +0100 Subject: [PATCH] Fix handleHandshakeMsg --- src/services/service.ts | 42 ++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/services/service.ts b/src/services/service.ts index fee6094..0972b3c 100755 --- a/src/services/service.ts +++ b/src/services/service.ts @@ -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