Skip to content

Commit

Permalink
feat(core): allow to set auto accept connetion exchange when acceptin…
Browse files Browse the repository at this point in the history
…g invitation (#589)


Signed-off-by: Jakub Koci <[email protected]>
  • Loading branch information
jakubkoci authored Jan 3, 2022
1 parent b491941 commit 2d95dce
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
16 changes: 12 additions & 4 deletions packages/core/src/modules/connections/ConnectionsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ export class ConnectionsModule {
mediatorId?: string
}
): Promise<ConnectionRecord> {
const myRouting = await this.mediationRecipientService.getRouting({ mediatorId: config?.mediatorId })
const routing = await this.mediationRecipientService.getRouting({ mediatorId: config?.mediatorId })

let connection = await this.connectionService.processInvitation(invitation, {
autoAcceptConnection: config?.autoAcceptConnection,
alias: config?.alias,
routing: myRouting,
routing,
})
// if auto accept is enabled (either on the record or the global agent config)
// we directly send a connection request
Expand Down Expand Up @@ -131,8 +131,16 @@ export class ConnectionsModule {
* @param connectionId the id of the connection for which to accept the invitation
* @returns connection record
*/
public async acceptInvitation(connectionId: string): Promise<ConnectionRecord> {
const { message, connectionRecord: connectionRecord } = await this.connectionService.createRequest(connectionId)
public async acceptInvitation(
connectionId: string,
config?: {
autoAcceptConnection?: boolean
}
): Promise<ConnectionRecord> {
const { message, connectionRecord: connectionRecord } = await this.connectionService.createRequest(
connectionId,
config
)
const outbound = createOutboundMessage(connectionRecord, message)
await this.messageSender.sendMessage(outbound)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,31 @@ export class ConnectionService {
*/
public async createRequest(
connectionId: string,
config?: {
config: {
myLabel?: string
myImageUrl?: string
}
autoAcceptConnection?: boolean
} = {}
): Promise<ConnectionProtocolMsgReturnType<ConnectionRequestMessage>> {
const connectionRecord = await this.connectionRepository.getById(connectionId)

connectionRecord.assertState(ConnectionState.Invited)
connectionRecord.assertRole(ConnectionRole.Invitee)

const { myLabel, myImageUrl, autoAcceptConnection } = config

const connectionRequest = new ConnectionRequestMessage({
label: config?.myLabel ?? this.config.label,
label: myLabel ?? this.config.label,
did: connectionRecord.did,
didDoc: connectionRecord.didDoc,
imageUrl: config?.myImageUrl ?? this.config.connectionImageUrl,
imageUrl: myImageUrl ?? this.config.connectionImageUrl,
})

if (autoAcceptConnection !== undefined || autoAcceptConnection !== null) {
connectionRecord.autoAcceptConnection = config?.autoAcceptConnection
}

connectionRecord.autoAcceptConnection = config?.autoAcceptConnection
await this.updateState(connectionRecord, ConnectionState.Requested)

return {
Expand Down

0 comments on commit 2d95dce

Please sign in to comment.