diff --git a/src/pages/chat/chat.ts b/src/pages/chat/chat.ts index 87102c3..65b9166 100755 --- a/src/pages/chat/chat.ts +++ b/src/pages/chat/chat.ts @@ -560,6 +560,40 @@ class ChatElement extends HTMLElement { roleElement.appendChild(memberList); } + async getRoles(process: Process): Promise { + const service = await Services.getInstance(); + // Get the `commited_in` value of the last state and remove it from the array + const currentCommitedIn = process.states.pop()?.commited_in; + + if (currentCommitedIn === undefined) { + return null; // No states available + } + + // Find the last state where `commited_in` is different + let lastDifferentState = process.states.findLast( + state => state.commited_in !== currentCommitedIn + ); + + if (!lastDifferentState) { + // It means that we only have one state that is not commited yet, that can happen with process we just created + // let's assume that the right description is in the last concurrent state and not handle the (arguably rare) case where we have multiple concurrent states on a creation + lastDifferentState = process.states.pop(); + } + + // Take the roles out of the state + const roles = lastDifferentState!.pcd_commitment['roles']; + if (roles) { + const userDiff = await service.getDiffByValue(roles); + if (userDiff) { + console.log("Successfully retrieved userDiff:", userDiff); + return userDiff.new_value; + } else { + console.log("Failed to retrieve a non-null userDiff."); + } + } + + return null; + } private async loadGroupList(processId: string): Promise { console.log('Loading group list with processId:', processId);