Fix loadMemberChat
This commit is contained in:
parent
326e9607c9
commit
da64e76779
@ -336,6 +336,34 @@ class ChatElement extends HTMLElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async lookForChildren(): Promise<string | null> {
|
||||||
|
// Filter processes for the children of current process
|
||||||
|
const service = await Services.getInstance();
|
||||||
|
const children: string[] = await service.getChildrenOfProcess(this.processId);
|
||||||
|
|
||||||
|
const processRoles = this.processRoles;
|
||||||
|
const selectedMember = this.selectedMember;
|
||||||
|
for (const child of children) {
|
||||||
|
const roles = await this.getRoles(JSON.parse(child));
|
||||||
|
// Check that we and the other members are in the role
|
||||||
|
if (!service.isChildRole(processRoles, roles)) {
|
||||||
|
console.error('Child process roles are not a subset of parent')
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!service.rolesContainsMember(roles, selectedMember)) {
|
||||||
|
console.error('Member is not part of the process');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!service.rolesContainsUs(roles)) {
|
||||||
|
console.error('We\'re not part of child process');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return child;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private async loadMemberChat(member: string[]) {
|
private async loadMemberChat(member: string[]) {
|
||||||
if (member.length === 0) {
|
if (member.length === 0) {
|
||||||
console.error('Empty member');
|
console.error('Empty member');
|
||||||
@ -362,50 +390,39 @@ class ChatElement extends HTMLElement {
|
|||||||
chatHeader.textContent = `Chat with ${emojis}`;
|
chatHeader.textContent = `Chat with ${emojis}`;
|
||||||
messagesContainer.innerHTML = '';
|
messagesContainer.innerHTML = '';
|
||||||
|
|
||||||
// Filter processes for the children of current process
|
let messagesProcess = await this.lookForChildren();
|
||||||
if (!this.processId) {
|
|
||||||
console.error('No process id');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const children: string[] = await service.getChildrenOfProcess(this.processId);
|
|
||||||
|
|
||||||
let messagesProcess: Process | null = null;
|
|
||||||
const processRoles = this.processRoles;
|
|
||||||
for (const child of children) {
|
|
||||||
const roles = await this.getRoles(JSON.parse(child));
|
|
||||||
// Check that we and the other members are in the role
|
|
||||||
if (!service.isChildRole(processRoles, roles)) {
|
|
||||||
console.error('Child process roles are not a subset of parent')
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!service.rolesContainsMember(roles, this.selectedMember)) {
|
|
||||||
console.error('Member is not part of the process');
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!service.rolesContainsUs(roles)) {
|
|
||||||
console.error('We\'re not part of child process');
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
messagesProcess = JSON.parse(child);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (messagesProcess === null) {
|
if (messagesProcess === null) {
|
||||||
console.log('Create a new child process');
|
console.log('Create a new child process');
|
||||||
// We need to create a new process
|
// We need to create a new process
|
||||||
let newProcess;
|
|
||||||
try {
|
try {
|
||||||
if (this.processId) {
|
if (!this.processId) {
|
||||||
|
console.error('No process id');
|
||||||
|
return;
|
||||||
|
}
|
||||||
const res = await service.createDmProcess(member, this.processId);
|
const res = await service.createDmProcess(member, this.processId);
|
||||||
// We catch the new process here
|
// We catch the new process here
|
||||||
messagesProcess = res.updated_process?.current_process ?? null;
|
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);
|
await service.handleApiReturn(res);
|
||||||
} else {
|
setTimeout(async () => {
|
||||||
console.error('No process id');
|
// Now create a first commitment
|
||||||
}
|
console.log('Created child process', processId);
|
||||||
|
const createPrdReturn = await service.createPrdUpdate(processId, stateId);
|
||||||
|
await service.handleApiReturn(createPrdReturn);
|
||||||
|
const approveChangeReturn = service.approveChange(processId, stateId);
|
||||||
|
await service.handleApiReturn(approveChangeReturn);
|
||||||
|
}, 500);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (messagesProcess === null) {
|
||||||
|
messagesProcess = await this.lookForChildren();
|
||||||
|
await new Promise(r => setTimeout(r, 500));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log('Found child process', messagesProcess);
|
console.log('Found child process', messagesProcess);
|
||||||
}
|
}
|
||||||
@ -425,6 +442,8 @@ class ChatElement extends HTMLElement {
|
|||||||
// Récupérer les messages depuis les états du processus
|
// Récupérer les messages depuis les états du processus
|
||||||
const allMessages: any[] = [];
|
const allMessages: any[] = [];
|
||||||
|
|
||||||
|
console.log(messagesProcess);
|
||||||
|
const childProcess = JSON.parse(messagesProcess);
|
||||||
if (messagesProcess?.states) {
|
if (messagesProcess?.states) {
|
||||||
for (const state of messagesProcess.states) {
|
for (const state of messagesProcess.states) {
|
||||||
const pcd_commitment = state.pcd_commitment;
|
const pcd_commitment = state.pcd_commitment;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user