Clean up and fixes
This commit is contained in:
@@ -44,15 +44,24 @@ export class Invitation extends EventEmitter<InvitationEventMap> {
|
||||
throw new Error(`Invitation not found in local or remote storage: ${invitation}`);
|
||||
}
|
||||
|
||||
// Make sure the engine has the template imported
|
||||
await dependencies.engine.importTemplate(invitation.templateIdentifier);
|
||||
const template = await dependencies.engine.getTemplate(invitation.templateIdentifier);
|
||||
|
||||
if (!template) {
|
||||
throw new Error(`Template not found: ${invitation.templateIdentifier}`);
|
||||
}
|
||||
|
||||
console.log('Invitation:', invitation);
|
||||
|
||||
// Create the invitation
|
||||
const invitationInstance = new Invitation(invitation, dependencies);
|
||||
|
||||
console.log('Invitation instance:', invitationInstance);
|
||||
|
||||
// Start the invitation and its tracking
|
||||
await invitationInstance.start();
|
||||
|
||||
console.log('Invitation started:', invitationInstance);
|
||||
|
||||
return invitationInstance;
|
||||
}
|
||||
|
||||
@@ -114,7 +123,9 @@ export class Invitation extends EventEmitter<InvitationEventMap> {
|
||||
const sseCommits = this.data.commits;
|
||||
|
||||
// Set the invitation data with the combined commits
|
||||
this.data = { ...invitation, commits: [...sseCommits, ...invitation.commits] };
|
||||
this.data = { ...this.data, ...invitation, commits: [...sseCommits, ...(invitation?.commits ?? [])] };
|
||||
|
||||
console.log('Invitation data:', this.data);
|
||||
|
||||
// Store the invitation in the storage
|
||||
await this.storage.set(this.data.invitationIdentifier, this.data);
|
||||
@@ -132,10 +143,14 @@ export class Invitation extends EventEmitter<InvitationEventMap> {
|
||||
const data = JSON.parse(event.data) as { topic?: string; data?: unknown };
|
||||
if (data.topic === 'invitation-updated') {
|
||||
const invitation = decodeExtendedJsonObject(data.data) as XOInvitation;
|
||||
console.log('Invitation updated:', invitation);
|
||||
|
||||
if (invitation.invitationIdentifier !== this.data.invitationIdentifier) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('New commits:', invitation.commits);
|
||||
|
||||
// Filter out commits that already exist (probably a faster way to do this. This is n^2)
|
||||
const newCommits = invitation.commits.filter(commit => !this.data.commits.some(c => c.commitIdentifier === commit.commitIdentifier));
|
||||
this.data.commits.push(...newCommits);
|
||||
@@ -271,28 +286,28 @@ export class Invitation extends EventEmitter<InvitationEventMap> {
|
||||
/**
|
||||
* Get the missing requirements for the invitation
|
||||
*/
|
||||
get missingRequirements() {
|
||||
async getMissingRequirements() {
|
||||
return this.engine.listMissingRequirements(this.data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the requirements for the invitation
|
||||
*/
|
||||
get requirements() {
|
||||
async getRequirements() {
|
||||
return this.engine.listRequirements(this.data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the available roles for the invitation
|
||||
*/
|
||||
get availableRoles() {
|
||||
async getAvailableRoles() {
|
||||
return this.engine.listAvailableRoles(this.data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the starting actions for the invitation
|
||||
*/
|
||||
get startingActions() {
|
||||
async getStartingActions() {
|
||||
return this.engine.listStartingActions(this.data.templateIdentifier);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user