fix(dispatcher): implemented userId filter
it got commented out when migrating to 64-bit ids, then i moved to using native numbers for them and forgot to update the filter
This commit is contained in:
parent
a7e866f3eb
commit
252f94a594
1 changed files with 120 additions and 118 deletions
|
@ -31,7 +31,6 @@ import {
|
||||||
} from '@mtcute/client'
|
} from '@mtcute/client'
|
||||||
import { MaybeArray } from '@mtcute/core'
|
import { MaybeArray } from '@mtcute/core'
|
||||||
import { UpdateState } from './state'
|
import { UpdateState } from './state'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
|
|
||||||
function extractText(
|
function extractText(
|
||||||
obj: Message | InlineQuery | ChosenInlineResult | CallbackQuery
|
obj: Message | InlineQuery | ChosenInlineResult | CallbackQuery
|
||||||
|
@ -428,132 +427,135 @@ export namespace filters {
|
||||||
* For chat member updates, uses `user.id`
|
* For chat member updates, uses `user.id`
|
||||||
*/
|
*/
|
||||||
export const userId = (
|
export const userId = (
|
||||||
id: MaybeArray<number | string | tl.Long>
|
id: MaybeArray<number | string>
|
||||||
): UpdateFilter<
|
): UpdateFilter<
|
||||||
| Message
|
| Message
|
||||||
|
| UserStatusUpdate
|
||||||
|
| UserTypingUpdate
|
||||||
| InlineQuery
|
| InlineQuery
|
||||||
| ChatMemberUpdate
|
| ChatMemberUpdate
|
||||||
| ChosenInlineResult
|
| ChosenInlineResult
|
||||||
| CallbackQuery
|
| CallbackQuery
|
||||||
| PollVoteUpdate
|
| PollVoteUpdate
|
||||||
| UserStatusUpdate
|
|
||||||
| UserTypingUpdate
|
|
||||||
> => {
|
> => {
|
||||||
// TODO
|
if (Array.isArray(id)) {
|
||||||
return () => false
|
const index: Record<number | string, true> = {}
|
||||||
|
let matchSelf = false
|
||||||
|
id.forEach((id) => {
|
||||||
|
if (id === 'me' || id === 'self') {
|
||||||
|
matchSelf = true
|
||||||
|
} else {
|
||||||
|
index[id] = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// if (Array.isArray(id)) {
|
return (upd) => {
|
||||||
// const index: Record<number | string, true> = {}
|
const ctor = upd.constructor
|
||||||
// let matchSelf = false
|
|
||||||
// id.forEach((id) => {
|
if (ctor === Message) {
|
||||||
// if (id === 'me' || id === 'self') {
|
const sender = (upd as Message).sender
|
||||||
// matchSelf = true
|
return (
|
||||||
// } else {
|
(matchSelf && sender.isSelf) ||
|
||||||
// index[id] = true
|
sender.id in index ||
|
||||||
// }
|
sender.username! in index
|
||||||
// })
|
)
|
||||||
//
|
} else if (
|
||||||
// return (upd) => {
|
ctor === UserStatusUpdate ||
|
||||||
// const ctor = upd.constructor
|
ctor === UserTypingUpdate
|
||||||
//
|
) {
|
||||||
// if (ctor === Message) {
|
const id = (upd as UserStatusUpdate | UserTypingUpdate)
|
||||||
// const sender = (upd as Message).sender
|
.userId
|
||||||
// return (
|
return (
|
||||||
// (matchSelf && sender.isSelf) ||
|
(matchSelf && id === upd.client['_userId']) ||
|
||||||
// sender.id in index ||
|
id in index
|
||||||
// sender.username! in index
|
)
|
||||||
// )
|
} else {
|
||||||
// } else {
|
const user = (
|
||||||
// if (
|
upd as Exclude<
|
||||||
// ctor === UserStatusUpdate ||
|
typeof upd,
|
||||||
// ctor === UserTypingUpdate
|
Message | UserStatusUpdate | UserTypingUpdate
|
||||||
// ) {
|
>
|
||||||
// const id = (upd as UserStatusUpdate | UserTypingUpdate)
|
).user
|
||||||
// .userId
|
|
||||||
// return (
|
return (
|
||||||
// (matchSelf && id === upd.client['_userId']) ||
|
(matchSelf && user.isSelf) ||
|
||||||
// id in index
|
user.id in index ||
|
||||||
// )
|
user.username! in index
|
||||||
// } else {
|
)
|
||||||
// const user = (upd as Exclude<
|
}
|
||||||
// typeof upd,
|
}
|
||||||
// Message | UserStatusUpdate | UserTypingUpdate
|
}
|
||||||
// >).user
|
|
||||||
//
|
if (id === 'me' || id === 'self') {
|
||||||
// return (
|
return (upd) => {
|
||||||
// (matchSelf && user.isSelf) ||
|
const ctor = upd.constructor
|
||||||
// user.id in index ||
|
|
||||||
// user.username! in index
|
if (ctor === Message) {
|
||||||
// )
|
return (upd as Message).sender.isSelf
|
||||||
// }
|
} else if (
|
||||||
// }
|
ctor === UserStatusUpdate ||
|
||||||
// }
|
ctor === UserTypingUpdate
|
||||||
// }
|
) {
|
||||||
//
|
return (
|
||||||
// if (id === 'me' || id === 'self') {
|
(upd as UserStatusUpdate | UserTypingUpdate).userId ===
|
||||||
// return (upd) => {
|
upd.client['_userId']
|
||||||
// const ctor = upd.constructor
|
)
|
||||||
//
|
} else {
|
||||||
// if (ctor === Message) {
|
return (
|
||||||
// return (upd as Message).sender.isSelf
|
upd as Exclude<
|
||||||
// } else if (
|
typeof upd,
|
||||||
// ctor === UserStatusUpdate ||
|
Message | UserStatusUpdate | UserTypingUpdate
|
||||||
// ctor === UserTypingUpdate
|
>
|
||||||
// ) {
|
).user.isSelf
|
||||||
// return (
|
}
|
||||||
// (upd as UserStatusUpdate | UserTypingUpdate).userId ===
|
}
|
||||||
// upd.client['_userId']
|
}
|
||||||
// )
|
|
||||||
// } else {
|
if (typeof id === 'string') {
|
||||||
// return (upd as Exclude<
|
return (upd) => {
|
||||||
// typeof upd,
|
const ctor = upd.constructor
|
||||||
// Message | UserStatusUpdate | UserTypingUpdate
|
|
||||||
// >).user.isSelf
|
if (ctor === Message) {
|
||||||
// }
|
return (upd as Message).sender.username === id
|
||||||
// }
|
} else if (
|
||||||
// }
|
ctor === UserStatusUpdate ||
|
||||||
//
|
ctor === UserTypingUpdate
|
||||||
// if (typeof id === 'string') {
|
) {
|
||||||
// return (upd) => {
|
// username is not available
|
||||||
// const ctor = upd.constructor
|
return false
|
||||||
//
|
} else {
|
||||||
// if (ctor === Message) {
|
return (
|
||||||
// return (upd as Message).sender.username === id
|
(
|
||||||
// } else if (
|
upd as Exclude<
|
||||||
// ctor === UserStatusUpdate ||
|
typeof upd,
|
||||||
// ctor === UserTypingUpdate
|
Message | UserStatusUpdate | UserTypingUpdate
|
||||||
// ) {
|
>
|
||||||
// // username is not available
|
).user.username === id
|
||||||
// return false
|
)
|
||||||
// } else {
|
}
|
||||||
// return (
|
}
|
||||||
// (upd as Exclude<
|
}
|
||||||
// typeof upd,
|
|
||||||
// Message | UserStatusUpdate | UserTypingUpdate
|
return (upd) => {
|
||||||
// >).user.username === id
|
const ctor = upd.constructor
|
||||||
// )
|
|
||||||
// }
|
if (ctor === Message) {
|
||||||
// }
|
return (upd as Message).sender.id === id
|
||||||
// }
|
} else if (ctor === UserStatusUpdate || ctor === UserTypingUpdate) {
|
||||||
//
|
return (
|
||||||
// return (upd) => {
|
(upd as UserStatusUpdate | UserTypingUpdate).userId === id
|
||||||
// const ctor = upd.constructor
|
)
|
||||||
//
|
} else {
|
||||||
// if (ctor === Message) {
|
return (
|
||||||
// return (upd as Message).sender.id === id
|
(
|
||||||
// } else if (ctor === UserStatusUpdate || ctor === UserTypingUpdate) {
|
upd as Exclude<
|
||||||
// return (
|
typeof upd,
|
||||||
// (upd as UserStatusUpdate | UserTypingUpdate).userId === id
|
Message | UserStatusUpdate | UserTypingUpdate
|
||||||
// )
|
>
|
||||||
// } else {
|
).user.id === id
|
||||||
// return (
|
)
|
||||||
// (upd as Exclude<
|
}
|
||||||
// typeof upd,
|
}
|
||||||
// Message | UserStatusUpdate | UserTypingUpdate
|
|
||||||
// >).user.id === id
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue