Skip to content

Commit

Permalink
feat: add initiatorAid, groupInitiator, groupReplied to NotificationR…
Browse files Browse the repository at this point in the history
…ecord
  • Loading branch information
Sotatek-TungNguyen2a committed Dec 19, 2024
1 parent 40bae29 commit 9583fb2
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 21 deletions.
12 changes: 12 additions & 0 deletions src/core/agent/records/notificationRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ interface NotificationRecordStorageProps {
connectionId: string;
credentialId?: string;
linkedGroupRequest?: LinkedGroupRequest;
groupReplied?: boolean,
initiatorAid?: string,
groupInitiator?: boolean,
}

class NotificationRecord extends BaseRecord {
Expand All @@ -24,6 +27,9 @@ class NotificationRecord extends BaseRecord {
connectionId!: string;
linkedGroupRequest!: LinkedGroupRequest;
credentialId?: string;
groupReplied?: boolean;
initiatorAid?: string;
groupInitiator?: boolean;

static readonly type = "NotificationRecord";
readonly type = NotificationRecord.type;
Expand All @@ -41,6 +47,9 @@ class NotificationRecord extends BaseRecord {
this._tags = props.tags ?? {};
this.linkedGroupRequest = props.linkedGroupRequest ?? { accepted: false };
this.credentialId = props.credentialId;
this.groupReplied = props.groupReplied;
this.initiatorAid = props.initiatorAid;
this.groupInitiator = props.groupInitiator;
}
}

Expand All @@ -51,6 +60,9 @@ class NotificationRecord extends BaseRecord {
multisigId: this.multisigId,
exnSaid: this.a.d,
credentialId: this.credentialId,
groupReplied: this.groupReplied,
initiatorAid: this.initiatorAid,
groupInitiator: this.groupInitiator,
...this._tags,
};
}
Expand Down
27 changes: 27 additions & 0 deletions src/core/agent/services/keriaNotificationService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2561,9 +2561,36 @@ describe("Long running operation tracker", () => {
linkedGroupRequest: { accepted: false },
connectionId: "EEFjBBDcUM2IWpNF7OclCme_bE76yKE3hzULLzTOFE8E",
updatedAt: new Date(),
groupReplied: true,
initiatorAid: "EAL7pX9Hklc_iq7pkVYSjAilCfQX3sr5RbX76AxYs2UH",
groupInitiator: true,
},
]);

multiSigs.getMultisigParticipants.mockResolvedValue({
ourIdentifier: {
id: "EC1cyV3zLnGs4B9AYgoGNjXESyQZrBWygz3jLlRD30bR",
displayName:"holder",
createdAt: "2024-09-23T08:53:11.981Z",
theme: 0,
groupMetadata: {
groupId: "group-id",
groupInitiator: true,
groupCreated: true,
},
},
multisigMembers: [
{
aid: "EC1cyV3zLnGs4B9AYgoGNjXESyQZrBWygz3jLlRD30bR",
ends: [],
},
{
aid: "EGaEIhOGSTPccSMvnXvfvOVyC1C5AFq62GLTrRKVZBS5",
ends: [],
},
],
});

await keriaNotificationService.processOperation(operationRecord);

expect(notificationStorage.delete).not.toBeCalled();
Expand Down
70 changes: 49 additions & 21 deletions src/core/agent/services/keriaNotificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,10 +675,10 @@ class KeriaNotificationService extends AgentService {
a: notificationRecord.a,
multisigId: notificationRecord.multisigId,
connectionId: notificationRecord.connectionId,
read: notificationRecord.read,
read: notificationRecord.read,
groupReplied: true,
}
}
},
},
});

return false;
Expand Down Expand Up @@ -707,6 +707,18 @@ class KeriaNotificationService extends AgentService {
};
notificationRecord.createdAt = new Date();
notificationRecord.read = false;
const { multisigMembers, ourIdentifier } =
await this.multiSigs.getMultisigParticipants(exchange.exn.a.gid);

const initiatorAid = multisigMembers.map(
(member: any) => member.aid
)[0];

notificationRecord.multisigId = exchange.exn.a.gid;
notificationRecord.groupReplied = true;
notificationRecord.initiatorAid = initiatorAid;
notificationRecord.groupInitiator =
ourIdentifier.groupMetadata?.groupInitiator;

await this.notificationStorage.update(notificationRecord);

Expand All @@ -716,12 +728,6 @@ class KeriaNotificationService extends AgentService {
id: notificationRecord.id,
},
});
const { multisigMembers, ourIdentifier } =
await this.multiSigs.getMultisigParticipants(exchange.exn.a.gid);

const initiatorAid = multisigMembers.map(
(member: any) => member.aid
)[0];

this.props.eventEmitter.emit<NotificationAddedEvent>({
type: EventTypes.NotificationAdded,
Expand All @@ -730,12 +736,12 @@ class KeriaNotificationService extends AgentService {
id: notificationRecord.id,
createdAt: notificationRecord.createdAt.toISOString(),
a: notificationRecord.a,
multisigId: exchange.exn.a.gid,
multisigId: notificationRecord.multisigId,
connectionId: notificationRecord.connectionId,
read: notificationRecord.read,
groupReplied: true,
initiatorAid,
groupInitiator: ourIdentifier.groupMetadata?.groupInitiator,
groupReplied: notificationRecord.groupReplied,
initiatorAid: notificationRecord.initiatorAid,
groupInitiator: notificationRecord.groupInitiator,
},
},
});
Expand Down Expand Up @@ -766,7 +772,10 @@ class KeriaNotificationService extends AgentService {
};

await this.notificationStorage.update(notificationRecord);
await this.ipexCommunications.joinMultisigGrant(exchange, notificationRecord);
await this.ipexCommunications.joinMultisigGrant(
exchange,
notificationRecord
);
return false;
}
default:
Expand Down Expand Up @@ -859,7 +868,9 @@ class KeriaNotificationService extends AgentService {
multisigId: notification.multisigId,
connectionId: notification.connectionId,
read: notification.read,
groupReplied: notification.linkedGroupRequest.current !== undefined
groupReplied: notification.linkedGroupRequest.current !== undefined,
groupInitiator: notification.groupInitiator,
initiatorAid: notification.initiatorAid,
};
});
}
Expand Down Expand Up @@ -1031,7 +1042,7 @@ class KeriaNotificationService extends AgentService {
.exchanges()
.get(admitExchange.exn.p);
const credentialId = grantExchange.exn.e.acdc.d;

const holder = await this.identifierStorage.getIdentifierMetadata(
admitExchange.exn.i
);
Expand Down Expand Up @@ -1085,6 +1096,21 @@ class KeriaNotificationService extends AgentService {
// "Refresh" the notification so user is aware offer is successfully sent
notification.createdAt = new Date();
notification.read = false;

const { multisigMembers, ourIdentifier } =
await this.multiSigs.getMultisigParticipants(
applyExchange.exn.rp
);

const initiatorAid = multisigMembers.map(
(member: any) => member.aid
)[0];

notification.groupReplied = true;
notification.initiatorAid = initiatorAid;
notification.groupInitiator =
ourIdentifier.groupMetadata?.groupInitiator;

await this.notificationStorage.update(notification);

this.props.eventEmitter.emit<NotificationRemovedEvent>({
Expand All @@ -1103,10 +1129,12 @@ class KeriaNotificationService extends AgentService {
a: notification.a,
multisigId: notification.multisigId,
connectionId: notification.connectionId,
read: notification.read,
groupReplied: true,
}
}
read: notification.read,
groupReplied: notification.groupReplied,
initiatorAid,
groupInitiator: notification.groupInitiator,
},
},
});
}
}
Expand All @@ -1121,7 +1149,7 @@ class KeriaNotificationService extends AgentService {
const agreeExchange = await this.props.signifyClient
.exchanges()
.get(grantExchange.exn.p);

const holder = await this.identifierStorage.getIdentifierMetadata(
grantExchange.exn.i
);
Expand Down

0 comments on commit 9583fb2

Please sign in to comment.