Fix checkConnections, also check more aggressively
This commit is contained in:
parent
0d934e7b6e
commit
5fc485e233
@ -376,6 +376,8 @@ export async function registerAllListeners() {
|
||||
}
|
||||
const state = services.getStateFromId(process, stateId);
|
||||
|
||||
await services.checkConnections(process, stateId);
|
||||
|
||||
let res: Record<string, any> = {};
|
||||
if (state) {
|
||||
// Decrypt all the data we have the key for
|
||||
|
@ -210,15 +210,18 @@ export default class Services {
|
||||
|
||||
// If we're updating a process, we must call that after update especially if roles are part of it
|
||||
// We will take the roles from the last state, wheter it's commited or not
|
||||
public async checkConnections(process: Process): Promise<void> {
|
||||
public async checkConnections(process: Process, stateId: string | null = null): Promise<void> {
|
||||
if (process.states.length < 2) {
|
||||
throw new Error('Process doesn\'t have any state yet');
|
||||
}
|
||||
let roles = process.states[process.states.length - 2].roles;
|
||||
let roles: Record<string, RoleDefinition> | null = null;
|
||||
if (!stateId) {
|
||||
roles = process.states[process.states.length - 2].roles;
|
||||
} else {
|
||||
roles = process.states.find(state => state.state_id === stateId)?.roles || null;
|
||||
}
|
||||
if (!roles) {
|
||||
throw new Error('No roles found');
|
||||
} else {
|
||||
console.log('roles found', roles);
|
||||
}
|
||||
let members: Set<Member> = new Set();
|
||||
for (const role of Object.values(roles!)) {
|
||||
@ -255,8 +258,7 @@ export default class Services {
|
||||
for (const address of sp_addresses) {
|
||||
// For now, we ignore our own device address, although there might be use cases for having a secret with ourselves
|
||||
if (address === myAddress) continue;
|
||||
const sharedSecret = await this.getSecretForAddress(address);
|
||||
if (!sharedSecret) {
|
||||
if (await this.getSecretForAddress(address) === null) {
|
||||
unconnectedAddresses.add(address);
|
||||
}
|
||||
}
|
||||
@ -420,7 +422,8 @@ export default class Services {
|
||||
);
|
||||
|
||||
if (result.updated_process) {
|
||||
await this.checkConnections(result.updated_process);
|
||||
console.log('created process:', result.updated_process);
|
||||
await this.checkConnections(result.updated_process.current_process);
|
||||
return(result);
|
||||
} else {
|
||||
throw new Error('Empty updated_process in createProcessReturn');
|
||||
@ -448,7 +451,7 @@ export default class Services {
|
||||
try {
|
||||
const result = this.sdkClient.update_process(process, encodedPrivateData, roles, encodedPublicData, this.getAllMembers());
|
||||
if (result.updated_process) {
|
||||
await this.checkConnections(result.updated_process);
|
||||
await this.checkConnections(result.updated_process.current_process);
|
||||
return(result);
|
||||
} else {
|
||||
throw new Error('Empty updated_process in updateProcessReturn');
|
||||
@ -462,15 +465,11 @@ export default class Services {
|
||||
const process = await this.getProcess(processId);
|
||||
if (!process) {
|
||||
throw new Error('Unknown process');
|
||||
} else {
|
||||
await this.checkConnections(process);
|
||||
}
|
||||
try {
|
||||
const result = this.sdkClient.create_update_message(process, stateId, this.getAllMembers());
|
||||
if (result.updated_process) {
|
||||
await this.checkConnections(result.updated_process);
|
||||
return(result);
|
||||
} else {
|
||||
throw new Error('Empty updated_process in createPrdUpdateReturn');
|
||||
}
|
||||
return this.sdkClient.create_update_message(process, stateId, this.getAllMembers());
|
||||
} catch (e) {
|
||||
throw new Error(`Failed to create prd update: ${e}`);
|
||||
}
|
||||
@ -496,7 +495,7 @@ export default class Services {
|
||||
try {
|
||||
const result = this.sdkClient.validate_state(process, stateId, this.getAllMembers());
|
||||
if (result.updated_process) {
|
||||
await this.checkConnections(result.updated_process);
|
||||
await this.checkConnections(result.updated_process.current_process);
|
||||
return(result);
|
||||
} else {
|
||||
throw new Error('Empty updated_process in approveChangeReturn');
|
||||
@ -1462,6 +1461,7 @@ export default class Services {
|
||||
}
|
||||
|
||||
if (newStates.length != 0) {
|
||||
await this.checkConnections(existing);
|
||||
await this.requestDataFromPeers(processId, newStates, newRoles);
|
||||
}
|
||||
// Otherwise we're probably just in the initial loading at page initialization
|
||||
|
Loading…
x
Reference in New Issue
Block a user