Skip to content

Commit

Permalink
feat: upgrade to AFJ 0.4.0 alpha and add sent_time
Browse files Browse the repository at this point in the history
Signed-off-by: Ariel Gentile <gentilester@gmail.com>
  • Loading branch information
genaris committed Apr 15, 2023
1 parent bb59336 commit 808dd86
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 506 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"registry": "https://registry.npmjs.org/"
},
"devDependencies": {
"@aries-framework/node": "^0.3.0",
"@aries-framework/node": "^0.4.0-alpha.110",
"@types/jest": "^26.0.23",
"@types/uuid": "^9.0.0",
"@typescript-eslint/eslint-plugin": "^4.28.2",
Expand All @@ -46,12 +46,12 @@
"typescript": "~4.3.0"
},
"dependencies": {
"@aries-framework/core": "^0.3.0",
"class-transformer": "0.5.1",
"class-validator": "0.13.1",
"@aries-framework/core": "^0.4.0-alpha.110",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.2.0",
"tsyringe": "^4.6.0",
"tsyringe": "^4.7.0",
"uuid": "^9.0.0"
},
"release-it": {
Expand Down
9 changes: 3 additions & 6 deletions src/MediaSharingApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ConnectionService,
Dispatcher,
injectable,
MessageHandlerRegistry,
MessageSender,
OutboundMessageContext,
} from '@aries-framework/core'
Expand Down Expand Up @@ -33,7 +34,6 @@ export class MediaSharingApi {
private agentContext: AgentContext

public constructor(
dispatcher: Dispatcher,
messageSender: MessageSender,
mediaSharingService: MediaSharingService,
connectionService: ConnectionService,
Expand All @@ -43,7 +43,8 @@ export class MediaSharingApi {
this.mediaSharingService = mediaSharingService
this.connectionService = connectionService
this.agentContext = agentContext
this.registerHandlers(dispatcher)

this.agentContext.dependencyManager.registerMessageHandlers([new ShareMediaHandler(this.mediaSharingService)])
}

/**
Expand Down Expand Up @@ -112,8 +113,4 @@ export class MediaSharingApi {
public findById(recordId: string): Promise<MediaSharingRecord | null> {
return this.mediaSharingService.findById(this.agentContext, recordId)
}

private registerHandlers(dispatcher: Dispatcher) {
dispatcher.registerMessageHandler(new ShareMediaHandler(this.mediaSharingService))
}
}
2 changes: 1 addition & 1 deletion src/MediaSharingModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class MediaSharingModule implements Module {
public readonly api = MediaSharingApi

/**
* Registers the dependencies of the question answer module on the dependency manager.
* Registers the dependencies of media sharing module on the dependency manager.
*/
public register(dependencyManager: DependencyManager, featureRegistry: FeatureRegistry) {
// Api
Expand Down
12 changes: 10 additions & 2 deletions src/messages/ShareMediaMessage.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { AgentMessage, IsValidMessageType, parseMessageType } from '@aries-framework/core'
import { Type } from 'class-transformer'
import { IsOptional, IsString } from 'class-validator'
import { DateParser } from '@aries-framework/core/build/utils/transformers'
import { Expose, Transform, Type } from 'class-transformer'
import { IsDate, IsOptional, IsString } from 'class-validator'
import { SharedMediaItem } from '../repository'

export interface ShareMediaMessageOptions {
id?: string
threadId?: string
parentThreadId?: string
sentTime?: Date
description?: string
items: SharedMediaItem[]
}
Expand All @@ -29,6 +31,7 @@ export class ShareMediaMessage extends AgentMessage {
})
}

this.sentTime = options.sentTime || new Date()
this.description = options.description
this.items = options.items
}
Expand All @@ -38,6 +41,11 @@ export class ShareMediaMessage extends AgentMessage {
@IsString()
public description?: string

@Expose({ name: 'sent_time' })
@Transform(({ value }) => DateParser(value))
@IsDate()
public sentTime!: Date

@Type(() => SharedMediaItem)
public items!: SharedMediaItem[]

Expand Down
5 changes: 4 additions & 1 deletion src/repository/MediaSharingRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@ export interface MediaSharingStorageProps {
description?: string
items?: SharedMediaItem[]
metadata?: Record<string, unknown>
sentTime?: Date
}

export class MediaSharingRecord extends BaseRecord {
export class MediaSharingRecord extends BaseRecord<any, any, any> {
public connectionId!: string
public threadId?: string
public parentThreadId?: string
public role!: MediaSharingRole
public state!: MediaSharingState
public description?: string
public sentTime?: Date

@Type(() => SharedMediaItem)
public items?: SharedMediaItem[]
Expand All @@ -72,6 +74,7 @@ export class MediaSharingRecord extends BaseRecord {
this.parentThreadId = props.parentThreadId
this.description = props.description
this.items = props.items ?? []
this.sentTime = props.sentTime
if (props.metadata) {
Object.keys(props.metadata).forEach((key) => {
this.metadata.set(key, props.metadata?.[key])
Expand Down
3 changes: 3 additions & 0 deletions src/services/MediaSharingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export class MediaSharingService {
role: MediaSharingRole.Receiver,
items: message.items,
description: message.description,
sentTime: message.sentTime
})

await this.mediaSharingRepository.save(messageContext.agentContext, record)
Expand Down Expand Up @@ -217,4 +218,6 @@ export class MediaSharingService {
public async update(agentContext: AgentContext, record: MediaSharingRecord) {
return await this.mediaSharingRepository.update(agentContext, record)
}


}
Loading

0 comments on commit 808dd86

Please sign in to comment.