Skip to content

Commit

Permalink
fix: request media handler
Browse files Browse the repository at this point in the history
Signed-off-by: Ariel Gentile <[email protected]>
  • Loading branch information
genaris committed Jun 22, 2023
1 parent d232731 commit bf8b9a3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 32 deletions.
7 changes: 5 additions & 2 deletions src/MediaSharingApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
MessageSender,
OutboundMessageContext,
} from '@aries-framework/core'
import { ShareMediaHandler } from './handlers'
import { RequestMediaHandler, ShareMediaHandler } from './handlers'
import { MediaSharingRecord, SharedMediaItem, SharedMediaItemOptions } from './repository'
import { MediaSharingService } from './services'

Expand Down Expand Up @@ -49,7 +49,10 @@ export class MediaSharingApi {
this.connectionService = connectionService
this.agentContext = agentContext

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

/**
Expand Down
18 changes: 18 additions & 0 deletions src/handlers/RequestMediaHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { MessageHandler, MessageHandlerInboundMessage } from '@aries-framework/core'
import { MediaSharingService } from '../services'
import { RequestMediaMessage } from '../messages'

export class RequestMediaHandler implements MessageHandler {
public supportedMessages = [RequestMediaMessage]
private mediaSharingService: MediaSharingService

public constructor(mediaSharingService: MediaSharingService) {
this.mediaSharingService = mediaSharingService
}

public async handle(inboundMessage: MessageHandlerInboundMessage<RequestMediaHandler>) {
inboundMessage.assertReadyConnection()

// Nothing to do internally. Will be handled by the controller
}
}
1 change: 1 addition & 0 deletions src/handlers/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './RequestMediaHandler'
export * from './ShareMediaHandler'
30 changes: 0 additions & 30 deletions src/messages/RequestMediaMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,6 @@ import { AgentMessage, IsValidMessageType, parseMessageType } from '@aries-frame
import { DateParser } from '@aries-framework/core/build/utils/transformers'
import { Expose, Transform } from 'class-transformer'
import { IsDate, IsOptional, IsString } from 'class-validator'
import { CipheringInfo } from '../repository'

interface SharedMediaItemDescriptorOptions {
id: string
attachmentId: string
description?: string
ciphering?: CipheringInfo
metadata?: Record<string, unknown>
}

class SharedMediaItemDescriptor {
@Expose({ name: '@id' })
public id!: string

@Expose({ name: 'attachment_id' })
public attachmentId!: string

public ciphering?: CipheringInfo

public metadata?: Record<string, unknown>

public constructor(options: SharedMediaItemDescriptorOptions) {
if (options) {
this.id = options.id
this.attachmentId = options.attachmentId
this.ciphering = options.ciphering
this.metadata = options.metadata
}
}
}

export interface RequestMediaMessageOptions {
id?: string
Expand Down

0 comments on commit bf8b9a3

Please sign in to comment.