fix(dispatcher): middleware and event emitter related fixes
This commit is contained in:
parent
28c70a89ba
commit
c33646943c
1 changed files with 30 additions and 20 deletions
|
@ -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) {
|
||||||
parsed = pair[1](this._client, update!, users!, chats!)
|
if (
|
||||||
parsedType = pair[0]
|
this._handlersCount[update!._] ||
|
||||||
|
this.listenerCount(pair[0])
|
||||||
|
) {
|
||||||
|
parsed = pair[1](this._client, update!, users!, chats!)
|
||||||
|
parsedType = pair[0]
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
parsed = parsedType = null
|
parsed = parsedType = null
|
||||||
}
|
}
|
||||||
|
@ -524,19 +529,22 @@ 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) {
|
||||||
switch (
|
updateInfo = { type: parsedType, data: parsed }
|
||||||
await this._preUpdateHandler?.(
|
switch (
|
||||||
updateInfo as any,
|
await this._preUpdateHandler?.(
|
||||||
parsedState as any
|
updateInfo as any,
|
||||||
)
|
parsedState as any
|
||||||
) {
|
)
|
||||||
case 'stop':
|
) {
|
||||||
shouldDispatch = false
|
case 'stop':
|
||||||
break
|
shouldDispatch = false
|
||||||
case 'stop-children':
|
break
|
||||||
return false
|
case 'stop-children':
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldDispatch) {
|
if (shouldDispatch) {
|
||||||
|
@ -678,11 +686,13 @@ export class Dispatcher<
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this._postUpdateHandler?.(
|
if (updateInfo) {
|
||||||
wasHandled,
|
this._postUpdateHandler?.(
|
||||||
updateInfo as any,
|
wasHandled,
|
||||||
parsedState as any
|
updateInfo,
|
||||||
)
|
parsedState as any
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return wasHandled
|
return wasHandled
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue