process_no_loop_ok
This commit is contained in:
parent
30fadfb3d6
commit
a14b54a7e7
@ -289,12 +289,26 @@ class ChatElement extends HTMLElement {
|
||||
}
|
||||
|
||||
const currentProcessId = this.getAttribute('process-id');
|
||||
console.log('🔍 Current Process ID from attribute:', currentProcessId);
|
||||
console.log('<EFBFBD><EFBFBD> Current Process ID:', currentProcessId);
|
||||
|
||||
if (!currentProcessId) {
|
||||
throw new Error('No process ID found in element attributes');
|
||||
throw new Error('No process ID found');
|
||||
}
|
||||
|
||||
// Vérifier si le processus existe déjà
|
||||
const existingProcess = await this.getExistingMessageProcess(
|
||||
currentProcessId,
|
||||
otherMembers[0].sp_addresses
|
||||
);
|
||||
|
||||
if (existingProcess) {
|
||||
console.log('✅ Process message déjà existant, réutilisation:', existingProcess);
|
||||
return existingProcess;
|
||||
}
|
||||
|
||||
// Si non existant, créer un nouveau processus
|
||||
console.log('🆕 Création d\'un nouveau processus message');
|
||||
|
||||
const messagingTemplate = {
|
||||
parent_id: currentProcessId,
|
||||
description: 'messaging',
|
||||
@ -327,10 +341,30 @@ class ChatElement extends HTMLElement {
|
||||
feeRate
|
||||
);
|
||||
console.log('✅ Process message créé:', result);
|
||||
|
||||
// Vérification dans IndexedDB
|
||||
const db = await Database.getInstance();
|
||||
const processStore = 'processes';
|
||||
const storedProcess = await db.getObject(processStore, (result as any).process_id);
|
||||
console.log('💾 Process message stocké dans IndexedDB:', {
|
||||
store: processStore,
|
||||
processId: (result as any).process_id,
|
||||
data: storedProcess
|
||||
});
|
||||
|
||||
if (!storedProcess) {
|
||||
console.log('⚠️ Process non trouvé dans IndexedDB, ajout manuel...');
|
||||
await db.addObject({
|
||||
storeName: processStore,
|
||||
key: (result as any).process_id,
|
||||
object: result
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (e) {
|
||||
console.error('❌ Erreur création process:', e);
|
||||
throw new Error(`Creating process failed: ${e}`);
|
||||
console.error('❌ Erreur:', e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@ -496,9 +530,20 @@ class ChatElement extends HTMLElement {
|
||||
memberItem.onclick = async (event) => {
|
||||
event.stopPropagation();
|
||||
try {
|
||||
const existingProcess = await this.getExistingConversationProcess(member.sp_addresses[0]);
|
||||
// Récupérer le processId du chat parent
|
||||
const parentProcessId = this.getAttribute('process-id');
|
||||
console.log('🔍 Parent Process ID:', parentProcessId);
|
||||
|
||||
if (existingProcess) {
|
||||
if (!parentProcessId) {
|
||||
throw new Error('No parent process ID found');
|
||||
}
|
||||
|
||||
// Vérifier si un processus de message existe déjà pour cet utilisateur
|
||||
const db = await Database.getInstance();
|
||||
const processes = await db.getObject('processes', parentProcessId);
|
||||
console.log('💾 Processus trouvé:', processes);
|
||||
|
||||
if (processes) {
|
||||
console.log('✅ Processus existant trouvé, chargement de la conversation');
|
||||
this.loadMemberChat(member.sp_addresses[0]);
|
||||
} else {
|
||||
@ -508,14 +553,13 @@ class ChatElement extends HTMLElement {
|
||||
[member],
|
||||
'relay_address',
|
||||
1,
|
||||
this.processId || '',
|
||||
parentProcessId,
|
||||
roleName
|
||||
);
|
||||
await this.saveConversationProcessRef(member.sp_addresses[0], (result as any).process_id);
|
||||
this.loadMemberChat(member.sp_addresses[0]);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('❌ Erreur:', error);
|
||||
console.error('❌ Erreur lors du clic:', error);
|
||||
}
|
||||
};
|
||||
|
||||
@ -1077,6 +1121,48 @@ class ChatElement extends HTMLElement {
|
||||
console.error('Error saving conversation reference:', error);
|
||||
}
|
||||
}
|
||||
|
||||
async getProcessFromDB(processId: string) {
|
||||
const db = await Database.getInstance();
|
||||
const processStore = 'processes';
|
||||
const process = await db.getObject(processStore, processId);
|
||||
console.log('📦 Process trouvé dans IndexedDB:', {
|
||||
store: processStore,
|
||||
processId: processId,
|
||||
data: process
|
||||
});
|
||||
return process;
|
||||
}
|
||||
|
||||
private async getExistingMessageProcess(parentId: string, spAddresses: string[]): Promise<any> {
|
||||
try {
|
||||
const db = await Database.getInstance();
|
||||
const processStore = 'processes';
|
||||
|
||||
// Utiliser une clé valide pour la recherche
|
||||
const process = await db.getObject(processStore, parentId);
|
||||
console.log('🔍 Processus trouvé:', process);
|
||||
|
||||
if (!process) {
|
||||
console.log('❌ Aucun processus trouvé avec l\'ID:', parentId);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Vérifier si c'est le bon processus
|
||||
if (process.parent_id === parentId &&
|
||||
process.roles?.owner?.members?.some((member: any) =>
|
||||
spAddresses.includes(member.sp_addresses[0])
|
||||
)) {
|
||||
console.log('✅ Processus correspondant trouvé');
|
||||
return process;
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (error) {
|
||||
console.error('❌ Erreur lors de la recherche du processus:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define('chat-element', ChatElement);
|
||||
|
Loading…
x
Reference in New Issue
Block a user