-
Notifications
You must be signed in to change notification settings - Fork 198
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: support handling messages with different minor version #714
Changes from all commits
4b6951a
5a9452b
869c784
90d5e08
c32859c
c559ad3
ee2601a
53312ba
451cf62
24f2d8c
8552cfa
aa1484d
1ea48d1
aa07fa1
fe4f843
d46b570
b8186d7
42f45a1
4392906
2f1f0e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import { Lifecycle, scoped } from 'tsyringe' | |
|
||
import { AgentConfig } from '../agent/AgentConfig' | ||
import { AriesFrameworkError } from '../error/AriesFrameworkError' | ||
import { canHandleMessageType, parseMessageType } from '../utils/messageType' | ||
|
||
import { ProblemReportMessage } from './../modules/problem-reports/messages/ProblemReportMessage' | ||
import { EventEmitter } from './EventEmitter' | ||
|
@@ -92,17 +93,21 @@ class Dispatcher { | |
} | ||
|
||
private getHandlerForType(messageType: string): Handler | undefined { | ||
const incomingMessageType = parseMessageType(messageType) | ||
|
||
for (const handler of this.handlers) { | ||
for (const MessageClass of handler.supportedMessages) { | ||
if (MessageClass.type === messageType) return handler | ||
if (canHandleMessageType(MessageClass, incomingMessageType)) return handler | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this might be a big cleaner return this.handlers.forEach((handler) => handler.supportedMessages.find((message) => message.type === messageType)) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This won't work because the forEach doesn't return anything. I could change it to find, but then it would return the handler and not the message class. Any other suggestions on how to approach? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe that swapping the |
||
|
||
public getMessageClassForType(messageType: string): typeof AgentMessage | undefined { | ||
const incomingMessageType = parseMessageType(messageType) | ||
|
||
for (const handler of this.handlers) { | ||
for (const MessageClass of handler.supportedMessages) { | ||
if (MessageClass.type === messageType) return MessageClass | ||
if (canHandleMessageType(MessageClass, incomingMessageType)) return MessageClass | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, could be a bit cleaner. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If return Array.prototype.concat(...this.handlers.map((handler) => handler.supportedMessages).find((MessageClass) => canHandleMessageType(MessageClass, incomingMessageType)) |
||
|
@@ -122,7 +127,7 @@ class Dispatcher { | |
* Protocol ID format is PIURI specified at https://github.com/hyperledger/aries-rfcs/blob/main/concepts/0003-protocols/README.md#piuri. | ||
*/ | ||
public get supportedProtocols() { | ||
return Array.from(new Set(this.supportedMessageTypes.map((m) => m.substring(0, m.lastIndexOf('/'))))) | ||
return Array.from(new Set(this.supportedMessageTypes.map((m) => m.protocolUri))) | ||
} | ||
|
||
public filterSupportedProtocolsByMessageFamilies(messageFamilies: string[]) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It almost looks like LISP here :)