From a16c42acacd317abe2bdca43cce829fb359f73fd Mon Sep 17 00:00:00 2001 From: NicolasCantu Date: Mon, 27 Jan 2025 16:42:25 +0100 Subject: [PATCH] Fix loadMemberChat --- src/pages/chat/chat.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/pages/chat/chat.ts b/src/pages/chat/chat.ts index 53d66b5..2d40ce2 100755 --- a/src/pages/chat/chat.ts +++ b/src/pages/chat/chat.ts @@ -397,6 +397,7 @@ class ChatElement extends HTMLElement { const service = await Services.getInstance(); const members = await service.getAllMembers(); + console.log("MEMBERS: ", members); const memberList = document.createElement('div'); memberList.className = 'member-list active'; @@ -434,8 +435,9 @@ class ChatElement extends HTMLElement { // Filter processes for the children of current process const service = await Services.getInstance(); const processes = await service.getProcesses(); + const memberAddresses = await service.getAddressesForMemberId(this.selectedMember); - const recipientAddresses = service.getAddressesForMemberId(this.selectedMember); + const recipientAddresses = memberAddresses.sp_addresses; for (const [processId, process] of Object.entries(processes)) { const description = await service.getDescription(processId, process); console.log('Process description:', description); @@ -468,6 +470,7 @@ class ChatElement extends HTMLElement { // Set the selected member this.selectedMember = pairingProcess; + console.log("SELECTED MEMBER: ", this.selectedMember); const chatHeader = this.shadowRoot?.querySelector('#chat-header'); const messagesContainer = this.shadowRoot?.querySelector('#messages'); @@ -485,8 +488,10 @@ class ChatElement extends HTMLElement { console.log('Create a new dm process'); // We need to create a new process try { + const memberAddresses = await service.getAddressesForMemberId(this.selectedMember); + console.log("MEMBER ADDRESSES: ", memberAddresses); // await service.checkConnections(otherMembers); - const res = await service.createDmProcess(this.selectedMember); + const res = await service.createDmProcess(memberAddresses.sp_addresses); // We catch the new process here const updatedProcess = res.updated_process?.current_process; const processId = updatedProcess?.states[0]?.commited_in; @@ -494,8 +499,8 @@ class ChatElement extends HTMLElement { await service.handleApiReturn(res); setTimeout(async () => { // Now create a first commitment - console.log('Created process', processId); - this.processId = ProcessId; + console.log('Created a dm process', processId); + this.processId = processId; const createPrdReturn = await service.createPrdUpdate(processId, stateId); console.log(createPrdReturn); await service.handleApiReturn(createPrdReturn); @@ -508,10 +513,10 @@ class ChatElement extends HTMLElement { return; } - while (dmProcessId === null) { - dmProcessId = await this.lookForDmProcess(); - await new Promise(r => setTimeout(r, 1000)); - } + // while (dmProcessId === null) { + // dmProcessId = await this.lookForDmProcess(); + // await new Promise(r => setTimeout(r, 1000)); + // } } else { console.log('Found DM process', dmProcessId); this.processId = dmProcessId; @@ -568,7 +573,8 @@ class ChatElement extends HTMLElement { messageContent.className = `message ${isCurrentUser ? 'user' : ''}`; console.log("SENDER: ", message.metadata.sender); - const pairingProcess = this.addressMap[message.metadata.sender]; + const pairingProcess = await this.getMyProcessId(); + const senderEmoji = await addressToEmoji(pairingProcess); const senderEmoji = await addressToEmoji(pairingProcess); if (message.type === 'file') {