Skip to content

Commit

Permalink
Decompose relationships at connector startup in AutoDecomposeDeletion…
Browse files Browse the repository at this point in the history
…ProposedRelationshipsModule (#276)
  • Loading branch information
jkoenig134 authored Oct 2, 2024
1 parent 1e475dd commit 10e3a3f
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,32 @@ export default class AutoDecomposeDeletionProposedRelationshipsModule extends Co
const currentIdentityResult = await this.runtime.getServices().transportServices.account.getIdentityInfo();
this.currentIdentity = currentIdentityResult.value.address;

await this.decomposeDeletionProposedRelationshipsAtStartup();

this.subscribeToEvent(RelationshipChangedEvent, this.handleRelationshipChanged.bind(this));
}

private async decomposeDeletionProposedRelationshipsAtStartup() {
const services = this.runtime.getServices();

const deletionProposedRelationships = await services.transportServices.relationships.getRelationships({ query: { status: "DeletionProposed" } });
this.logger.info(`Found ${deletionProposedRelationships.value.length} 'DeletionProposed' Relationships.`);

for (const relationship of deletionProposedRelationships.value) {
await this.decomposeRelationship(relationship.id);
}
}

private async handleRelationshipChanged(event: RelationshipChangedEvent) {
if (event.data.status !== RelationshipStatus.DeletionProposed) return;

this.logger.info("'DeletionProposed' Relationship detected.");

const result = await this.runtime.getServices().transportServices.relationships.decomposeRelationship({ relationshipId: event.data.id });
await this.decomposeRelationship(event.data.id);
}

private async decomposeRelationship(relationshipId: string) {
const result = await this.runtime.getServices().transportServices.relationships.decomposeRelationship({ relationshipId });

if (result.isSuccess) {
this.logger.info("'DeletionProposed' Relationship was decomposed successfully.");
Expand Down

0 comments on commit 10e3a3f

Please sign in to comment.