From ba632d0abeecd80bc5148ddc5dff43905a372276 Mon Sep 17 00:00:00 2001 From: Pascal Date: Wed, 22 Jan 2025 02:25:23 +0100 Subject: [PATCH] simplified_loop --- src/pages/chat/chat.ts | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/pages/chat/chat.ts b/src/pages/chat/chat.ts index f000765..30a44ad 100755 --- a/src/pages/chat/chat.ts +++ b/src/pages/chat/chat.ts @@ -50,7 +50,7 @@ class ChatElement extends HTMLElement { })); private messageState: number = 0; private selectedRole: string | null = null; - + private userProcessesSet: Set | null = null; constructor() { super(); @@ -715,8 +715,9 @@ class ChatElement extends HTMLElement { //Load all processes private async loadAllProcesses() { console.log('🎯 Loading all processes'); - // TODO : uncomment this when we have a way to get the processSet - //const processSet = await this.getProcessesWhereTheCurrentMemberIs(); + + const processSet = this.userProcessesSet; + console.log("Je suis le processSet :" ,processSet); const dbRequest = indexedDB.open('4nk'); @@ -770,12 +771,10 @@ class ChatElement extends HTMLElement { const li = document.createElement('li'); li.className = 'group-list-item'; const oneProcess = process.states[0].commited_in; - console.log("Je suis l'id du processus :" ,oneProcess); - // Ajouter une classe spéciale si le processus est dans notre Set - //if (processSet?.has(oneProcess)) { - // li.classList.add('user-process'); - //} + if (processSet?.has(oneProcess)) { + console.log("Je suis le processus dans le set :" ,oneProcess); + } li.setAttribute('data-process-id', oneProcess); groupList.appendChild(li); @@ -906,16 +905,14 @@ class ChatElement extends HTMLElement { for (const {key, value} of processes) { const processName = await key; const roles = await value.states[0].encrypted_pcd.roles; - for (const [roleName, roleData] of Object.entries(roles)) { - const allMembers = (roleData as { members: { sp_addresses: string[] }[] }).members; - for (const member of allMembers) { - for (const address of member.sp_addresses) { - if (address === this.processId) { - console.log("Je suis le processName :" ,processName); - processSet.add(processName); - } - } - } + + const hasCurrentUser = this.processId && Object.values(roles).some(role => + (role as { members: { sp_addresses: string[] }[] }).members + .some(member => member.sp_addresses.includes(this.processId!)) + ); + + if (hasCurrentUser) { + processSet.add(processName); } } @@ -1259,7 +1256,8 @@ class ChatElement extends HTMLElement { } else { console.warn('⚠️ No process ID found. Loading default processes...'); await this.loadAllProcesses(); - await this.getProcessesWhereTheCurrentMemberIs(); + const processSet = await this.getProcessesWhereTheCurrentMemberIs(); + this.userProcessesSet = processSet || null; }