Skip to content

Commit

Permalink
fix: this makes tests pass
Browse files Browse the repository at this point in the history
(how?)
  • Loading branch information
MKRhere authored and wojpawlik committed Nov 10, 2022
1 parent 9d85c07 commit 795d842
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,26 +430,26 @@ export class Composer<C extends Context> implements MiddlewareObj<C> {
): MiddlewareFn<Ctx> {
const filters = Array.isArray(updateType) ? updateType : [updateType]

return (ctx, next) => {
const { update } = ctx

const predicate = (update: tg.Update): update is tg.Update => {
for (const filter of filters) {
if (
typeof filter === 'function'
? // using filter function
? // filter is a type guard
filter(update)
: // check if filter is the update type
filter in update ||
// check if filter is the msg type
// TODO: remove in v5!
('message' in update && filter in update.message)
) {
return Composer.compose(fns)(ctx, next)
return true
}
}

return next()
return false
}

return Composer.optional((ctx) => predicate(ctx.update), ...fns)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export class Context<U extends Deunionize<tg.Update> = tg.Update> {
typeof filter === 'function'
? // filter is a type guard
filter(this.update)
: // filter is now type UpdateType
: // check if filter is the update type
filter in this.update
)
return true
Expand Down

0 comments on commit 795d842

Please sign in to comment.