Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(routing): support promise in message repo #959

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/core/src/agent/MessageSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class MessageSender {
// If the other party shared a queue service endpoint in their did doc we queue the message
if (queueService) {
this.logger.debug(`Queue packed message for connection ${connection.id} (${connection.theirLabel})`)
this.messageRepository.add(connection.id, encryptedMessage)
await this.messageRepository.add(connection.id, encryptedMessage)
return
}

Expand Down Expand Up @@ -267,7 +267,7 @@ export class MessageSender {
}

const encryptedMessage = await this.envelopeService.packMessage(payload, keys)
this.messageRepository.add(connection.id, encryptedMessage)
await this.messageRepository.add(connection.id, encryptedMessage)
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class MessagePickupService {
const connection = messageContext.assertReadyConnection()

const { message } = messageContext
const messages = this.messageRepository.takeFromQueue(connection.id, message.batchSize)
const messages = await this.messageRepository.takeFromQueue(connection.id, message.batchSize)

// TODO: each message should be stored with an id. to be able to conform to the id property
// of batch message
Expand All @@ -39,7 +39,7 @@ export class MessagePickupService {
return createOutboundMessage(connection, batchMessage)
}

public queueMessage(connectionId: string, message: EncryptedMessage) {
this.messageRepository.add(connectionId, message)
public async queueMessage(connectionId: string, message: EncryptedMessage) {
await this.messageRepository.add(connectionId, message)
}
}
4 changes: 2 additions & 2 deletions packages/core/src/storage/MessageRepository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { EncryptedMessage } from '../types'

export interface MessageRepository {
takeFromQueue(connectionId: string, limit?: number): EncryptedMessage[]
add(connectionId: string, payload: EncryptedMessage): void
takeFromQueue(connectionId: string, limit?: number): EncryptedMessage[] | Promise<EncryptedMessage[]>
add(connectionId: string, payload: EncryptedMessage): void | Promise<void>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this still be sync? I thought all repository operations are async.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message repository is a special type of repository. We should probably rework this in the near future if we want to start using AFJ as a mediator. For now this makes it possible to make a custom repo implementation based on the indy wallet storage (which is indeed async).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should probably be called something like queue (as that's what is is based on the methods e.g. takeFromQueue)

}