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

Commit

Permalink
fix: user profile when re-initializing agent
Browse files Browse the repository at this point in the history
Signed-off-by: Ariel Gentile <[email protected]>
  • Loading branch information
genaris committed Sep 1, 2023
1 parent 4a39e74 commit 30921e9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export * from './UserProfileApi'
export * from './UserProfileModule'
export * from './UserProfileModuleConfig'
export * from './handlers'
export * from './messages'
export * from './repository'
export * from './services'
export * from './model'

2 changes: 0 additions & 2 deletions src/model/UserProfile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Exclude, Transform, TransformationType } from 'class-transformer'

export interface DisplayPictureData {
mimeType?: string
links?: string[]
Expand Down
26 changes: 10 additions & 16 deletions src/services/UserProfileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ export class UserProfileService {
private userProfileRepository: UserProfileRepository
private connectionService: ConnectionService
private eventEmitter: EventEmitter
private _userProfileRecord?: UserProfileRecord


public constructor(
userProfileRepository: UserProfileRepository,
connectionService: ConnectionService,
Expand All @@ -51,8 +50,6 @@ export class UserProfileService {

Object.assign(userProfile, props)
await this.userProfileRepository.update(agentContext, userProfile)
// Update internal state
this._userProfileRecord = userProfile

this.eventEmitter.emit<UserProfileUpdatedEvent>(agentContext, {
type: ProfileEventTypes.UserProfileUpdated,
Expand All @@ -72,23 +69,20 @@ export class UserProfileService {
* @returns User Profile Record
*/
public async getUserProfile(agentContext: AgentContext): Promise<UserProfileRecord> {
if (!this._userProfileRecord) {
let userProfileRecord = await this.userProfileRepository.findById(
let userProfileRecord = await this.userProfileRepository.findById(
agentContext,
this.userProfileRepository.DEFAULT_USER_PROFILE_RECORD
)

// If we don't have an user profile record yet, create it
if (!userProfileRecord) {
userProfileRecord = new UserProfileRecord({
id: this.userProfileRepository.DEFAULT_USER_PROFILE_RECORD,
})
await this.userProfileRepository.save(agentContext, userProfileRecord)
}

this._userProfileRecord = userProfileRecord
// If we don't have an user profile record yet, create it
if (!userProfileRecord) {
userProfileRecord = new UserProfileRecord({
id: this.userProfileRepository.DEFAULT_USER_PROFILE_RECORD,
})
await this.userProfileRepository.save(agentContext, userProfileRecord)
}
return this._userProfileRecord

return userProfileRecord
}

public async processProfile(messageContext: InboundMessageContext<ProfileMessage>) {
Expand Down

0 comments on commit 30921e9

Please sign in to comment.