diff --git a/src/pages/chat/chat.ts b/src/pages/chat/chat.ts index 2aae947..ff44eb9 100755 --- a/src/pages/chat/chat.ts +++ b/src/pages/chat/chat.ts @@ -402,9 +402,9 @@ class ChatElement extends HTMLElement { } const res = await service.createDmProcess(member, this.processId); // We catch the new process here - const updatedProcess = res.updated_process.current_process; - const processId = updatedProcess.states[0].commited_in; - const stateId = updatedProcess.states[0].state_id; + const updatedProcess = res.updated_process?.current_process; + const processId = updatedProcess?.states[0]?.commited_in; + const stateId = updatedProcess?.states[0]?.state_id; await service.handleApiReturn(res); setTimeout(async () => { // Now create a first commitment @@ -444,8 +444,8 @@ class ChatElement extends HTMLElement { console.log(messagesProcess); const childProcess = JSON.parse(messagesProcess); - if (messagesProcess?.states) { - for (const state of messagesProcess.states) { + if (childProcess?.states) { + for (const state of childProcess.states) { const pcd_commitment = state.pcd_commitment; if (pcd_commitment) { const message_hash = pcd_commitment.message; @@ -635,7 +635,17 @@ class ChatElement extends HTMLElement { return null; } - public async loadAllGroupList(): Promise { + //Load all processes + private async loadAllProcesses() { + console.log('🎯 Loading all processes'); + const service = await Services.getInstance(); + const processes = await service.getProcesses(); + return processes; + } + + + // Load the group list from all processes + public async loadAllGroupListFromMyProcess(): Promise { console.log('🎯 Loading all group list'); const groupList = this.shadowRoot?.querySelector('#group-list'); if (!groupList) { @@ -657,6 +667,7 @@ class ChatElement extends HTMLElement { } } + // Load the group list from a process private async loadGroupListFromAProcess(processId: string): Promise { console.log('Loading group list with processId:', processId); const groupList = this.shadowRoot?.querySelector('#group-list'); @@ -966,7 +977,8 @@ class ChatElement extends HTMLElement { this.loadGroupListFromAProcess(this.processId); } else if(this.processId == null){ console.error('❌ No process ID found in element attributes'); - this.loadAllGroupList(); + //this.loadAllGroupListFromMyProcess(); + this.loadAllProcesses(); } // Si un membre est sélectionné par défaut, charger ses messages