From 34ce754be4330f5797abd64281abe8190e794738 Mon Sep 17 00:00:00 2001 From: Pascal Date: Fri, 17 Jan 2025 15:15:15 +0100 Subject: [PATCH] chat_bug --- src/pages/chat/chat-component.ts | 10 ----- src/pages/chat/chat.ts | 69 ++++++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 18 deletions(-) diff --git a/src/pages/chat/chat-component.ts b/src/pages/chat/chat-component.ts index ff409c6..a74abf8 100644 --- a/src/pages/chat/chat-component.ts +++ b/src/pages/chat/chat-component.ts @@ -17,22 +17,12 @@ class ChatComponent extends HTMLElement { connectedCallback() { console.log('CALLBACKs'); this.render(); - this.fetchData(); if (!customElements.get('chat-element')) { customElements.define('chat-element', ChatElement); } } - async fetchData() { - if ((import.meta as any).env.VITE_IS_INDEPENDANT_LIB === false) { - const data = await (window as any).myService?.getProcesses(); - } else { - const service = await Services.getInstance(); - const data = await service.getProcesses(); - } - } - set callback(fn) { if (typeof fn === 'function') { this._callback = fn; diff --git a/src/pages/chat/chat.ts b/src/pages/chat/chat.ts index 1d2e639..19fb879 100755 --- a/src/pages/chat/chat.ts +++ b/src/pages/chat/chat.ts @@ -30,6 +30,7 @@ export function initChat() { } } + class ChatElement extends HTMLElement { static get observedAttributes() { return ['process-id']; @@ -130,7 +131,7 @@ class ChatElement extends HTMLElement { console.log(`🔄 Attribute ${name} changed from ${oldValue} to ${newValue}`); if (name === 'process-id' && newValue) { console.log('🔍 Loading chat with new process ID:', newValue); - this.loadGroupList(newValue); + this.loadGroupListFromAProcess(newValue); } } @@ -413,6 +414,8 @@ class ChatElement extends HTMLElement { console.log('Found child process', messagesProcess); } + /* TODO + console.log("Je suis messagesProcess", messagesProcess); // --- GET THE STATE ID --- const messagesProcessStateId = messagesProcess?.states?.[0]?.state_id; console.log("Je suis messagesProcessStateId", messagesProcessStateId); @@ -421,7 +424,7 @@ class ChatElement extends HTMLElement { if (messagesProcessStateId) { const diffFromStateId = await this.getDiffByStateId(messagesProcessStateId); console.log("Je suis diffFromStateId", diffFromStateId); - } + }*/ // Récupérer les messages depuis les états du processus const allMessages: any[] = []; @@ -617,7 +620,43 @@ class ChatElement extends HTMLElement { return null; } - private async loadGroupList(processId: string): Promise { + public async loadAllGroupList(): Promise { + console.log('🎯 Loading all group list'); + const groupList = this.shadowRoot?.querySelector('#group-list'); + if (!groupList) { + console.error('❌ Group list element not found'); + return; + } + + groupList.innerHTML = ''; + const service = await Services.getInstance(); + + // Récupérer tous les processus + const processes = await service.getProcesses(); + console.log('All processes here:', processes); + + if (!processes || Object.keys(processes).length === 0) { + console.log('⚠️ No processes found'); + return; + } + + // Pour chaque processus, récupérer et afficher les rôles + /*for (const [processId, process] of Object.entries(processes)) { + console.log(`🔄 Processing: ${processId}`, process); + const roles = await this.getRoles(process); + console.log(`👥 Roles for ${processId}:`, roles); + + if (roles === null) { + console.error(`❌ No roles in process ${processId}`); + continue; + } + + console.log(`📝 Loading group list for process ${processId}`); + await this.loadGroupListFromAProcess(processId); + }*/ + } + + private async loadGroupListFromAProcess(processId: string): Promise { console.log('Loading group list with processId:', processId); const groupList = this.shadowRoot?.querySelector('#group-list'); if (!groupList) return; @@ -767,7 +806,7 @@ class ChatElement extends HTMLElement { text: `Fichier envoyé: ${file.name}`, timestamp: timestamp, sender: myAddresses[0], - recipient: this.selectedMemberId, + recipient: this.selectedMember, messageState: this.messageState, roleName: this.selectedRole, type: 'file', @@ -794,7 +833,7 @@ class ChatElement extends HTMLElement { metadata: { text: "J'ai bien reçu votre fichier 📎", timestamp: timestamp + 1000, - sender: this.selectedMemberId, + sender: this.selectedMember, recipient: myAddresses[0], messageState: this.messageState, roleName: this.selectedRole @@ -827,8 +866,8 @@ class ChatElement extends HTMLElement { if (fileInput) fileInput.value = ''; // Recharger les messages - if (this.selectedMemberId) { - await this.loadMemberChat(this.selectedMemberId); + if (this.selectedMember) { + await this.loadMemberChat(this.selectedMember); } } catch (error) { @@ -887,13 +926,27 @@ class ChatElement extends HTMLElement { } async connectedCallback() { + console.log('🔍 Connected Callback started'); + // Log du contenu d'IndexedDB + const dbRequest = indexedDB.open('4nk'); + dbRequest.onsuccess = (event: any) => { + const db = event.target.result; + const transaction = db.transaction('processes', 'readonly'); + // Log des processes + const processesStore = transaction.objectStore('processes'); + processesStore.getAll().onsuccess = (event: any) => { + console.log('🔄 Processes in IndexedDB:', event.target.result); + }; + }; + if (this.processId) { console.log('🔍 Loading chat with process ID:', this.processId); - this.loadGroupList(this.processId); + this.loadGroupListFromAProcess(this.processId); } else { console.error('❌ No process ID found in element attributes'); } + // Si un membre est sélectionné par défaut, charger ses messages if (this.selectedMember) { await this.loadMemberChat(this.selectedMember);