Skip to content
This repository has been archived by the owner on Sep 25, 2024. It is now read-only.

Commit

Permalink
fix: remove references to CommunicationPolicy
Browse files Browse the repository at this point in the history
Signed-off-by: Ariel Gentile <[email protected]>
  • Loading branch information
genaris committed Aug 24, 2023
1 parent 9477ba1 commit 4a39e74
Show file tree
Hide file tree
Showing 17 changed files with 59 additions and 352 deletions.
55 changes: 2 additions & 53 deletions src/UserProfileApi.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,24 @@
import {
ConnectionService,
injectable,
Dispatcher,
MessageSender,
AgentContext,
ConnectionRecord,
OutboundMessageContext,
} from '@aries-framework/core'
import { ProfileHandler, RequestProfileHandler } from './handlers'
import { CommunicationPolicyBaseProps, CommunicationPolicyRecord, UserProfileData } from './repository'
import { UserProfileData } from './repository'
import { UserProfileService } from './services'
import { CommunicationPolicyService } from './services/CommunicationPolicyService'

@injectable()
export class UserProfileApi {
private messageSender: MessageSender
private userProfileService: UserProfileService
private communicationPolicyService: CommunicationPolicyService
private agentContext: AgentContext

public constructor(
agentContext: AgentContext,
dispatcher: Dispatcher,
messageSender: MessageSender,
userProfileService: UserProfileService,
connectionService: ConnectionService,
communicationPolicyService: CommunicationPolicyService
) {
public constructor(agentContext: AgentContext, messageSender: MessageSender, userProfileService: UserProfileService) {
this.agentContext = agentContext
this.messageSender = messageSender
this.userProfileService = userProfileService
this.communicationPolicyService = communicationPolicyService

this.agentContext.dependencyManager.registerMessageHandlers([
new ProfileHandler(this.userProfileService),
Expand Down Expand Up @@ -62,25 +50,6 @@ export class UserProfileApi {
)
}

public async getCommunicationPolicies(): Promise<CommunicationPolicyRecord[]> {
return await this.communicationPolicyService.getAll(this.agentContext)
}

public async createCommunicationPolicy(props: CommunicationPolicyBaseProps) {
return await this.communicationPolicyService.create(this.agentContext, props)
}

public async updateCommunicationPolicy(
communicationPolicyRecord: CommunicationPolicyRecord,
props: CommunicationPolicyBaseProps
) {
await this.communicationPolicyService.update(this.agentContext, communicationPolicyRecord, props)
}

public async deleteCommunicationPolicy(communicationPolicyRecord: CommunicationPolicyRecord) {
await this.communicationPolicyService.delete(this.agentContext, communicationPolicyRecord)
}

/**
* Update editable properties of user profile record and persist in repository
*
Expand All @@ -96,29 +65,9 @@ export class UserProfileApi {
public async getUserProfileData(): Promise<UserProfileData> {
const userProfile = await this.userProfileService.getUserProfile(this.agentContext)
return {
defaultCommunicationPolicyId: userProfile.defaultCommunicationPolicyId,
displayName: userProfile.displayName,
displayPicture: userProfile.displayPicture,
description: userProfile.description,
}
}

/**
* Update default communication policy record for new connections, persisting it in repository
*
* @param communicationPolicyRecord new default communication policy record
*
* @returns updated User Profile Record
*/
public async setDefaultCommunicationPolicy(communicationPolicyRecord: CommunicationPolicyRecord) {
await this.userProfileService.updateUserProfile(this.agentContext, {
defaultCommunicationPolicyId: communicationPolicyRecord.id,
})

return await this.userProfileService.getUserProfile(this.agentContext)
}

public async getDefaultCommunicationPolicy() {
return await this.userProfileService.getDefaultCommunicationPolicy(this.agentContext)
}
}
9 changes: 9 additions & 0 deletions src/UserProfileModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@ import { Protocol } from '@aries-framework/core'

import { UserProfileApi } from './UserProfileApi'
import { UserProfileService } from './services'
import { UserProfileModuleConfig } from './UserProfileModuleConfig'

export class UserProfileModule implements Module {
public readonly config: UserProfileModuleConfig
public readonly api = UserProfileApi

public constructor(config?: UserProfileModuleConfig) {
this.config = new UserProfileModuleConfig(config)
}

/**
* Registers the dependencies of the question answer module on the dependency manager.
*/
public register(dependencyManager: DependencyManager, featureRegistry: FeatureRegistry) {
// Api
dependencyManager.registerContextScoped(UserProfileApi)

// Config
dependencyManager.registerInstance(UserProfileModuleConfig, this.config)

// Services
dependencyManager.registerSingleton(UserProfileService)

Expand Down
28 changes: 28 additions & 0 deletions src/UserProfileModuleConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* UserProfileModuleConfigOptions defines the interface for the options of the UserProfileModuleConfig class.
* This can contain optional parameters that have default values in the config class itself.
*/
export interface UserProfileModuleConfigOptions {
/**
* Whether to automatically send our profile when asked to do so.
*
* @default true
*/
autoSendProfile?: boolean
}

export class UserProfileModuleConfig {
#autoSendProfile?: boolean

private options: UserProfileModuleConfigOptions

public constructor(options?: UserProfileModuleConfigOptions) {
this.options = options ?? {}
this.#autoSendProfile = this.options.autoSendProfile
}

/** See {@link UserProfileModuleConfigOptions.autoSendProfile} */
public get autoSendProfile() {
return this.#autoSendProfile ?? true
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './UserProfileApi'
export * from './UserProfileModule'
export * from './UserProfileModuleConfig'
export * from './handlers'
export * from './messages'
export * from './repository'
Expand Down
2 changes: 1 addition & 1 deletion src/model/ConnectionMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConnectionRecord, JsonTransformer } from '@aries-framework/core'
import { ConnectionRecord } from '@aries-framework/core'
import { UserProfileData } from '../repository'

export const getConnectionProfile = (record: ConnectionRecord) => record.metadata.get('UserProfile') as UserProfileData
Expand Down
57 changes: 0 additions & 57 deletions src/repository/CommunicationPolicyRecord.ts

This file was deleted.

14 changes: 0 additions & 14 deletions src/repository/CommunicationPolicyRepository.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/repository/CommunicationPolicyState.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/repository/ConnectionAcceptancePolicy.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/repository/UserProfileRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export interface UserProfileData {
displayName?: string
displayPicture?: DisplayPictureData
description?: string
defaultCommunicationPolicyId?: string
}

export interface UserProfileStorageProps extends UserProfileData {
Expand All @@ -18,7 +17,6 @@ export class UserProfileRecord extends BaseRecord implements UserProfileStorageP
public displayName?: string
public displayPicture?: DisplayPictureData
public description?: string
public defaultCommunicationPolicyId?: string

public static readonly type = 'UserProfileRecord'
public readonly type = UserProfileRecord.type
Expand Down
4 changes: 0 additions & 4 deletions src/repository/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
export * from './CommunicationPolicyRecord'
export * from './CommunicationPolicyRepository'
export * from './CommunicationPolicyState'
export * from './ConnectionAcceptancePolicy'
export * from './UserProfileRecord'
export * from './UserProfileRepository'
15 changes: 0 additions & 15 deletions src/services/CommunicationPolicyEvents.ts

This file was deleted.

Loading

0 comments on commit 4a39e74

Please sign in to comment.