fix(dispatcher): middleware and event emitter related fixes

This commit is contained in:
teidesu 2021-07-09 01:49:53 +03:00
parent 28c70a89ba
commit c33646943c

View file

@ -437,11 +437,16 @@ export class Dispatcher<
const isRawMessage = update && tl.isAnyMessage(update) const isRawMessage = update && tl.isAnyMessage(update)
if (parsed === undefined && this._handlersCount[update!._]) { if (parsed === undefined) {
const pair = PARSERS[update!._] const pair = PARSERS[update!._]
if (pair) { if (pair) {
if (
this._handlersCount[update!._] ||
this.listenerCount(pair[0])
) {
parsed = pair[1](this._client, update!, users!, chats!) parsed = pair[1](this._client, update!, users!, chats!)
parsedType = pair[0] parsedType = pair[0]
}
} else { } else {
parsed = parsedType = null parsed = parsedType = null
} }
@ -524,8 +529,10 @@ export class Dispatcher<
let shouldDispatch = true let shouldDispatch = true
let shouldDispatchChildren = true let shouldDispatchChildren = true
let wasHandled = false let wasHandled = false
let updateInfo: any = null
const updateInfo = { type: parsedType, data: parsed } if (parsed) {
updateInfo = { type: parsedType, data: parsed }
switch ( switch (
await this._preUpdateHandler?.( await this._preUpdateHandler?.(
updateInfo as any, updateInfo as any,
@ -538,6 +545,7 @@ export class Dispatcher<
case 'stop-children': case 'stop-children':
return false return false
} }
}
if (shouldDispatch) { if (shouldDispatch) {
if (update && !isRawMessage) { if (update && !isRawMessage) {
@ -678,11 +686,13 @@ export class Dispatcher<
} }
} }
if (updateInfo) {
this._postUpdateHandler?.( this._postUpdateHandler?.(
wasHandled, wasHandled,
updateInfo as any, updateInfo,
parsedState as any parsedState as any
) )
}
return wasHandled return wasHandled
} }