refactor: use UsersIndex and ChatsIndex types instead of bare record types

This commit is contained in:
teidesu 2021-05-11 21:46:59 +03:00
parent 0525800133
commit 0f1edcfcf7
20 changed files with 116 additions and 70 deletions

View file

@ -143,6 +143,7 @@ import {
ChatInviteLink, ChatInviteLink,
ChatMember, ChatMember,
ChatPreview, ChatPreview,
ChatsIndex,
Dialog, Dialog,
FileDownloadParameters, FileDownloadParameters,
InputChatPermissions, InputChatPermissions,
@ -166,6 +167,7 @@ import {
UploadFileLike, UploadFileLike,
UploadedFile, UploadedFile,
User, User,
UsersIndex,
} from './types' } from './types'
import { MaybeArray, MaybeAsync, TelegramConnection } from '@mtcute/core' import { MaybeArray, MaybeAsync, TelegramConnection } from '@mtcute/core'
import { Lock } from './utils/lock' import { Lock } from './utils/lock'
@ -490,6 +492,7 @@ export interface TelegramClient extends BaseTelegramClient {
* @param queryId Inline query ID * @param queryId Inline query ID
* @param results Results of the query * @param results Results of the query
* @param params Additional parameters * @param params Additional parameters
*/ */
answerInlineQuery( answerInlineQuery(
queryId: tl.Long, queryId: tl.Long,
@ -691,6 +694,7 @@ export interface TelegramClient extends BaseTelegramClient {
* *
* @param chatId Chat ID * @param chatId Chat ID
* @param params * @param params
*/ */
getChatEventLog( getChatEventLog(
chatId: InputPeerLike, chatId: InputPeerLike,
@ -843,6 +847,7 @@ export interface TelegramClient extends BaseTelegramClient {
* *
* @param latitude Latitude of the location * @param latitude Latitude of the location
* @param longitude Longitude of the location * @param longitude Longitude of the location
*/ */
getNearbyChats(latitude: number, longitude: number): Promise<Chat[]> getNearbyChats(latitude: number, longitude: number): Promise<Chat[]>
/** /**
@ -1054,6 +1059,7 @@ export interface TelegramClient extends BaseTelegramClient {
* *
* @param folder Parameters for the folder * @param folder Parameters for the folder
* @returns Newly created folder * @returns Newly created folder
*/ */
createFolder( createFolder(
folder: PartialExcept<tl.RawDialogFilter, 'title'> folder: PartialExcept<tl.RawDialogFilter, 'title'>
@ -1102,6 +1108,7 @@ export interface TelegramClient extends BaseTelegramClient {
* is not considered when sorting. * is not considered when sorting.
* *
* @param params Fetch parameters * @param params Fetch parameters
*/ */
getDialogs(params?: { getDialogs(params?: {
/** /**
@ -1740,6 +1747,7 @@ export interface TelegramClient extends BaseTelegramClient {
* *
* @param chatId Chat ID * @param chatId Chat ID
* @param message ID of one of the messages in the group * @param message ID of one of the messages in the group
*/ */
getMessageGroup(chatId: InputPeerLike, message: number): Promise<Message[]> getMessageGroup(chatId: InputPeerLike, message: number): Promise<Message[]>
/** /**
@ -1956,6 +1964,7 @@ export interface TelegramClient extends BaseTelegramClient {
* @param fromChatId Target chat ID * @param fromChatId Target chat ID
* @param message Message ID to forward * @param message Message ID to forward
* @param params * @param params
*/ */
sendCopy( sendCopy(
toChatId: InputPeerLike, toChatId: InputPeerLike,
@ -2147,6 +2156,7 @@ export interface TelegramClient extends BaseTelegramClient {
* @param chatId ID of the chat, its username, phone or `"me"` or `"self"` * @param chatId ID of the chat, its username, phone or `"me"` or `"self"`
* @param text Text of the message * @param text Text of the message
* @param params Additional sending parameters * @param params Additional sending parameters
*/ */
sendText( sendText(
chatId: InputPeerLike, chatId: InputPeerLike,
@ -2528,8 +2538,8 @@ export interface TelegramClient extends BaseTelegramClient {
*/ */
dispatchUpdate( dispatchUpdate(
update: tl.TypeUpdate | tl.TypeMessage, update: tl.TypeUpdate | tl.TypeMessage,
users: Record<number, tl.TypeUser>, users: UsersIndex,
chats: Record<number, tl.TypeChat> chats: ChatsIndex
): void ): void
/** /**
* Catch up with the server by loading missed updates. * Catch up with the server by loading missed updates.

View file

@ -35,7 +35,9 @@ import {
TypingStatus, TypingStatus,
Photo, Photo,
ChatEvent, ChatEvent,
ChatInviteLink ChatInviteLink,
UsersIndex,
ChatsIndex
} from '../types' } from '../types'
// @copy // @copy

View file

@ -11,6 +11,7 @@ import { Lock } from '../utils/lock'
import bigInt from 'big-integer' import bigInt from 'big-integer'
import { MAX_CHANNEL_ID } from '@mtcute/core' import { MAX_CHANNEL_ID } from '@mtcute/core'
import { isDummyUpdate, isDummyUpdates } from '../utils/updates-utils' import { isDummyUpdate, isDummyUpdates } from '../utils/updates-utils'
import { ChatsIndex, UsersIndex } from '../types'
const debug = require('debug')('mtcute:upds') const debug = require('debug')('mtcute:upds')
@ -135,8 +136,8 @@ export async function _saveStorage(this: TelegramClient): Promise<void> {
export function dispatchUpdate( export function dispatchUpdate(
this: TelegramClient, this: TelegramClient,
update: tl.TypeUpdate | tl.TypeMessage, update: tl.TypeUpdate | tl.TypeMessage,
users: Record<number, tl.TypeUser>, users: UsersIndex,
chats: Record<number, tl.TypeChat> chats: ChatsIndex
): void { ): void {
// no-op // // no-op //
} }

View file

@ -5,7 +5,7 @@ import { Message } from '../messages'
import { MtCuteArgumentError } from '../errors' import { MtCuteArgumentError } from '../errors'
import { getMarkedPeerId } from '@mtcute/core' import { getMarkedPeerId } from '@mtcute/core'
import { encodeInlineMessageId } from '../../utils/inline-utils' import { encodeInlineMessageId } from '../../utils/inline-utils'
import { User } from '../peers' import { User, UsersIndex } from '../peers'
/** /**
* An incoming callback query, originated from a callback button * An incoming callback query, originated from a callback button
@ -17,12 +17,12 @@ export class CallbackQuery {
| tl.RawUpdateBotCallbackQuery | tl.RawUpdateBotCallbackQuery
| tl.RawUpdateInlineBotCallbackQuery | tl.RawUpdateInlineBotCallbackQuery
readonly _users: Record<number, tl.TypeUser> readonly _users: UsersIndex
constructor( constructor(
client: TelegramClient, client: TelegramClient,
raw: tl.RawUpdateBotCallbackQuery | tl.RawUpdateInlineBotCallbackQuery, raw: tl.RawUpdateBotCallbackQuery | tl.RawUpdateInlineBotCallbackQuery,
users: Record<number, tl.TypeUser> users: UsersIndex
) { ) {
this.client = client this.client = client
this.raw = raw this.raw = raw

View file

@ -1,6 +1,6 @@
import { makeInspectable } from '@mtcute/client/src/types/utils' import { makeInspectable } from '@mtcute/client/src/types/utils'
import { tl } from '@mtcute/tl' import { tl } from '@mtcute/tl'
import { PeerType, User } from '../peers' import { PeerType, User, UsersIndex } from '../peers'
import { TelegramClient } from '../../client' import { TelegramClient } from '../../client'
import { Location } from '../media' import { Location } from '../media'
import { InputInlineResult } from './input' import { InputInlineResult } from './input'
@ -18,12 +18,12 @@ export class InlineQuery {
readonly raw: tl.RawUpdateBotInlineQuery readonly raw: tl.RawUpdateBotInlineQuery
/** Map of users in this message. Mainly for internal use */ /** Map of users in this message. Mainly for internal use */
readonly _users: Record<number, tl.TypeUser> readonly _users: UsersIndex
constructor( constructor(
client: TelegramClient, client: TelegramClient,
raw: tl.RawUpdateBotInlineQuery, raw: tl.RawUpdateBotInlineQuery,
users: Record<number, tl.TypeUser> users: UsersIndex
) { ) {
this.client = client this.client = client
this.raw = raw this.raw = raw

View file

@ -3,6 +3,7 @@ import { tl } from '@mtcute/tl'
import { TelegramClient } from '../../client' import { TelegramClient } from '../../client'
import { MessageEntity } from '../messages' import { MessageEntity } from '../messages'
import bigInt from 'big-integer' import bigInt from 'big-integer'
import { UsersIndex } from '../peers'
export namespace Poll { export namespace Poll {
export interface PollAnswer { export interface PollAnswer {
@ -41,12 +42,12 @@ export class Poll {
readonly raw: tl.TypePoll readonly raw: tl.TypePoll
readonly results?: tl.TypePollResults readonly results?: tl.TypePollResults
readonly _users: Record<number, tl.TypeUser> readonly _users: UsersIndex
constructor( constructor(
client: TelegramClient, client: TelegramClient,
raw: tl.TypePoll, raw: tl.TypePoll,
users: Record<number, tl.TypeUser>, users: UsersIndex,
results?: tl.TypePollResults results?: tl.TypePollResults
) { ) {
this.client = client this.client = client

View file

@ -1,6 +1,6 @@
import { TelegramClient } from '../../client' import { TelegramClient } from '../../client'
import { tl } from '@mtcute/tl' import { tl } from '@mtcute/tl'
import { Chat } from '../peers' import { Chat, ChatsIndex, UsersIndex } from '../peers'
import { Message } from './message' import { Message } from './message'
import { DraftMessage } from './draft-message' import { DraftMessage } from './draft-message'
import { makeInspectable } from '../utils' import { makeInspectable } from '../utils'
@ -18,10 +18,10 @@ export class Dialog {
readonly raw: tl.RawDialog readonly raw: tl.RawDialog
/** Map of users in this object. Mainly for internal use */ /** Map of users in this object. Mainly for internal use */
readonly _users: Record<number, tl.TypeUser> readonly _users: UsersIndex
/** Map of chats in this object. Mainly for internal use */ /** Map of chats in this object. Mainly for internal use */
readonly _chats: Record<number, tl.TypeChat> readonly _chats: ChatsIndex
/** Map of messages in this object. Mainly for internal use */ /** Map of messages in this object. Mainly for internal use */
readonly _messages: Record<number, tl.TypeMessage> readonly _messages: Record<number, tl.TypeMessage>
@ -29,8 +29,8 @@ export class Dialog {
constructor( constructor(
client: TelegramClient, client: TelegramClient,
raw: tl.RawDialog, raw: tl.RawDialog,
users: Record<number, tl.TypeUser>, users: UsersIndex,
chats: Record<number, tl.TypeChat>, chats: ChatsIndex,
messages: Record<number, tl.TypeMessage> messages: Record<number, tl.TypeMessage>
) { ) {
this.client = client this.client = client

View file

@ -1,4 +1,4 @@
import { User, Chat, InputPeerLike } from '../peers' import { User, Chat, InputPeerLike, UsersIndex, ChatsIndex } from '../peers'
import { tl } from '@mtcute/tl' import { tl } from '@mtcute/tl'
import { BotKeyboard, ReplyMarkup } from '../bots' import { BotKeyboard, ReplyMarkup } from '../bots'
import { MAX_CHANNEL_ID } from '@mtcute/core' import { MAX_CHANNEL_ID } from '@mtcute/core'
@ -90,17 +90,17 @@ export class Message {
readonly raw: tl.RawMessage | tl.RawMessageService readonly raw: tl.RawMessage | tl.RawMessageService
/** Map of users in this message. Mainly for internal use */ /** Map of users in this message. Mainly for internal use */
readonly _users: Record<number, tl.TypeUser> readonly _users: UsersIndex
/** Map of chats in this message. Mainly for internal use */ /** Map of chats in this message. Mainly for internal use */
readonly _chats: Record<number, tl.TypeChat> readonly _chats: ChatsIndex
private _emptyError?: MtCuteEmptyError private _emptyError?: MtCuteEmptyError
constructor( constructor(
client: TelegramClient, client: TelegramClient,
raw: tl.TypeMessage, raw: tl.TypeMessage,
users: Record<number, tl.TypeUser>, users: UsersIndex,
chats: Record<number, tl.TypeChat>, chats: ChatsIndex,
isScheduled = false isScheduled = false
) { ) {
this.client = client this.client = client

View file

@ -8,6 +8,7 @@ import { Message } from '../messages'
import { ChatPermissions } from './chat-permissions' import { ChatPermissions } from './chat-permissions'
import { ChatLocation } from './chat-location' import { ChatLocation } from './chat-location'
import { ChatInviteLink } from './chat-invite-link' import { ChatInviteLink } from './chat-invite-link'
import { ChatsIndex, UsersIndex } from './index'
export namespace ChatEvent { export namespace ChatEvent {
/** A user has joined the group (in the case of big groups, info of the user that has joined isn't shown) */ /** A user has joined the group (in the case of big groups, info of the user that has joined isn't shown) */
@ -496,14 +497,14 @@ export class ChatEvent {
readonly client: TelegramClient readonly client: TelegramClient
readonly raw: tl.TypeChannelAdminLogEvent readonly raw: tl.TypeChannelAdminLogEvent
readonly _users: Record<number, tl.TypeUser> readonly _users: UsersIndex
readonly _chats: Record<number, tl.TypeChat> readonly _chats: ChatsIndex
constructor( constructor(
client: TelegramClient, client: TelegramClient,
raw: tl.TypeChannelAdminLogEvent, raw: tl.TypeChannelAdminLogEvent,
users: Record<number, tl.TypeUser>, users: UsersIndex,
chats: Record<number, tl.TypeChat> chats: ChatsIndex
) { ) {
this.client = client this.client = client
this.raw = raw this.raw = raw

View file

@ -2,6 +2,7 @@ import { makeInspectable } from '../utils'
import { TelegramClient } from '../../client' import { TelegramClient } from '../../client'
import { tl } from '@mtcute/tl' import { tl } from '@mtcute/tl'
import { User } from './user' import { User } from './user'
import { UsersIndex } from './index'
export namespace ChatInviteLink { export namespace ChatInviteLink {
export interface JoinedMember { export interface JoinedMember {
@ -17,9 +18,9 @@ export class ChatInviteLink {
readonly client: TelegramClient readonly client: TelegramClient
readonly raw: tl.RawChatInviteExported readonly raw: tl.RawChatInviteExported
readonly _users?: Record<number, tl.TypeUser> readonly _users?: UsersIndex
constructor (client: TelegramClient, raw: tl.RawChatInviteExported, users?: Record<number, tl.TypeUser>) { constructor (client: TelegramClient, raw: tl.RawChatInviteExported, users?: UsersIndex) {
this.client = client this.client = client
this.raw = raw this.raw = raw
this._users = users this._users = users

View file

@ -4,6 +4,7 @@ import { tl } from '@mtcute/tl'
import { User } from './user' import { User } from './user'
import { assertTypeIs } from '../../utils/type-assertion' import { assertTypeIs } from '../../utils/type-assertion'
import { ChatPermissions } from './chat-permissions' import { ChatPermissions } from './chat-permissions'
import { UsersIndex } from './index'
export namespace ChatMember { export namespace ChatMember {
/** /**
@ -32,12 +33,12 @@ export class ChatMember {
readonly raw: tl.TypeChatParticipant | tl.TypeChannelParticipant readonly raw: tl.TypeChatParticipant | tl.TypeChannelParticipant
/** Map of users in this object. Mainly for internal use */ /** Map of users in this object. Mainly for internal use */
readonly _users: Record<number, tl.TypeUser> readonly _users: UsersIndex
constructor( constructor(
client: TelegramClient, client: TelegramClient,
raw: tl.TypeChatParticipant | tl.TypeChannelParticipant, raw: tl.TypeChatParticipant | tl.TypeChannelParticipant,
users: Record<number, tl.TypeUser>, users: UsersIndex,
) { ) {
this.client = client this.client = client
this.raw = raw this.raw = raw

View file

@ -5,7 +5,7 @@ import { TelegramClient } from '../../client'
import { getMarkedPeerId, MaybeArray } from '@mtcute/core' import { getMarkedPeerId, MaybeArray } from '@mtcute/core'
import { MtCuteArgumentError, MtCuteTypeAssertionError } from '../errors' import { MtCuteArgumentError, MtCuteTypeAssertionError } from '../errors'
import { makeInspectable } from '../utils' import { makeInspectable } from '../utils'
import { InputPeerLike, User } from './index' import { ChatsIndex, InputPeerLike, User, UsersIndex } from './index'
import { ChatLocation } from './chat-location' import { ChatLocation } from './chat-location'
export namespace Chat { export namespace Chat {
@ -454,8 +454,8 @@ export class Chat {
static _parseFromMessage( static _parseFromMessage(
client: TelegramClient, client: TelegramClient,
message: tl.RawMessage | tl.RawMessageService, message: tl.RawMessage | tl.RawMessageService,
users: Record<number, tl.TypeUser>, users: UsersIndex,
chats: Record<number, tl.TypeChat> chats: ChatsIndex
): Chat { ): Chat {
return Chat._parseFromPeer(client, message.peerId, users, chats) return Chat._parseFromPeer(client, message.peerId, users, chats)
} }
@ -464,8 +464,8 @@ export class Chat {
static _parseFromPeer( static _parseFromPeer(
client: TelegramClient, client: TelegramClient,
peer: tl.TypePeer, peer: tl.TypePeer,
users: Record<number, tl.TypeUser>, users: UsersIndex,
chats: Record<number, tl.TypeChat> chats: ChatsIndex
): Chat { ): Chat {
if (peer._ === 'peerUser') { if (peer._ === 'peerUser') {
return new Chat(client, users[peer.userId]) return new Chat(client, users[peer.userId])

View file

@ -35,3 +35,6 @@ export type InputPeerLike =
| tl.TypeInputPeer | tl.TypeInputPeer
| tl.TypeInputUser | tl.TypeInputUser
| tl.TypeInputChannel | tl.TypeInputChannel
export type UsersIndex = Record<number, tl.TypeUser>
export type ChatsIndex = Record<number, tl.TypeChat>

View file

@ -1,5 +1,6 @@
import { tl } from '@mtcute/tl' import { tl } from '@mtcute/tl'
import bigInt from 'big-integer' import bigInt from 'big-integer'
import { ChatsIndex, UsersIndex } from '../types'
export const INVITE_LINK_REGEX = /^(?:https?:\/\/)?(?:www\.)?(?:t(?:elegram)?\.(?:org|me|dog)\/joinchat\/)([\w-]+)$/i export const INVITE_LINK_REGEX = /^(?:https?:\/\/)?(?:www\.)?(?:t(?:elegram)?\.(?:org|me|dog)\/joinchat\/)([\w-]+)$/i
@ -103,11 +104,11 @@ export function createUsersChatsIndex(
chats?: tl.TypeChat[] chats?: tl.TypeChat[]
} }
): { ): {
users: Record<number, tl.TypeUser> users: UsersIndex
chats: Record<number, tl.TypeChat> chats: ChatsIndex
} { } {
const users: Record<number, tl.TypeUser> = {} const users: UsersIndex = {}
const chats: Record<number, tl.TypeChat> = {} const chats: ChatsIndex = {}
obj.users?.forEach((e) => (users[e.id] = e)) obj.users?.forEach((e) => (users[e.id] = e))
obj.chats?.forEach((e) => (chats[e.id] = e)) obj.chats?.forEach((e) => (chats[e.id] = e))

View file

@ -1,9 +1,11 @@
import { import {
CallbackQuery, CallbackQuery,
ChatsIndex,
InlineQuery, InlineQuery,
Message, Message,
MtCuteArgumentError, MtCuteArgumentError,
TelegramClient, TelegramClient,
UsersIndex,
} from '@mtcute/client' } from '@mtcute/client'
import { tl } from '@mtcute/tl' import { tl } from '@mtcute/tl'
import { import {
@ -42,8 +44,8 @@ const noop = () => {}
type ParserFunction = ( type ParserFunction = (
client: TelegramClient, client: TelegramClient,
upd: tl.TypeUpdate | tl.TypeMessage, upd: tl.TypeUpdate | tl.TypeMessage,
users: Record<number, tl.TypeUser>, users: UsersIndex,
chats: Record<number, tl.TypeChat> chats: ChatsIndex
) => any ) => any
type UpdateParser = [Exclude<UpdateHandler['type'], 'raw'>, ParserFunction] type UpdateParser = [Exclude<UpdateHandler['type'], 'raw'>, ParserFunction]
@ -73,7 +75,7 @@ const callbackQueryParser: UpdateParser = [
] ]
const userTypingParser: UpdateParser = [ const userTypingParser: UpdateParser = [
'user_typing', 'user_typing',
(client, upd) => new UserTypingUpdate(client, upd as any) (client, upd) => new UserTypingUpdate(client, upd as any),
] ]
const PARSERS: Partial< const PARSERS: Partial<
@ -182,8 +184,8 @@ export class Dispatcher {
*/ */
dispatchUpdate( dispatchUpdate(
update: tl.TypeUpdate | tl.TypeMessage, update: tl.TypeUpdate | tl.TypeMessage,
users: Record<number, tl.TypeUser>, users: UsersIndex,
chats: Record<number, tl.TypeChat> chats: ChatsIndex
): void { ): void {
if (!this._client) return if (!this._client) return
@ -208,8 +210,8 @@ export class Dispatcher {
*/ */
async dispatchUpdateNow( async dispatchUpdateNow(
update: tl.TypeUpdate | tl.TypeMessage, update: tl.TypeUpdate | tl.TypeMessage,
users: Record<number, tl.TypeUser>, users: UsersIndex,
chats: Record<number, tl.TypeChat> chats: ChatsIndex
): Promise<void> { ): Promise<void> {
if (!this._client) return if (!this._client) return

View file

@ -4,6 +4,8 @@ import {
TelegramClient, TelegramClient,
InlineQuery, InlineQuery,
CallbackQuery, CallbackQuery,
UsersIndex,
ChatsIndex,
} from '@mtcute/client' } from '@mtcute/client'
import { tl } from '@mtcute/tl' import { tl } from '@mtcute/tl'
import { PropagationSymbol } from './propagation' import { PropagationSymbol } from './propagation'
@ -35,14 +37,14 @@ export type RawUpdateHandler = BaseUpdateHandler<
( (
client: TelegramClient, client: TelegramClient,
update: tl.TypeUpdate, update: tl.TypeUpdate,
users: Record<number, tl.TypeUser>, users: UsersIndex,
chats: Record<number, tl.TypeChat> chats: ChatsIndex
) => MaybeAsync<void | PropagationSymbol>, ) => MaybeAsync<void | PropagationSymbol>,
( (
client: TelegramClient, client: TelegramClient,
update: tl.TypeUpdate, update: tl.TypeUpdate,
users: Record<number, tl.TypeUser>, users: UsersIndex,
chats: Record<number, tl.TypeChat> chats: ChatsIndex
) => MaybeAsync<boolean> ) => MaybeAsync<boolean>
> >

View file

@ -3,8 +3,10 @@ import {
Chat, Chat,
ChatInviteLink, ChatInviteLink,
ChatMember, ChatMember,
ChatsIndex,
TelegramClient, TelegramClient,
User, User,
UsersIndex,
} from '@mtcute/client' } from '@mtcute/client'
import { makeInspectable } from '@mtcute/client/src/types/utils' import { makeInspectable } from '@mtcute/client/src/types/utils'
@ -49,15 +51,15 @@ export class ChatMemberUpdate {
readonly raw: tl.RawUpdateChatParticipant | tl.RawUpdateChannelParticipant readonly raw: tl.RawUpdateChatParticipant | tl.RawUpdateChannelParticipant
/** Map of users in this message. Mainly for internal use */ /** Map of users in this message. Mainly for internal use */
readonly _users: Record<number, tl.TypeUser> readonly _users: UsersIndex
/** Map of chats in this message. Mainly for internal use */ /** Map of chats in this message. Mainly for internal use */
readonly _chats: Record<number, tl.TypeChat> readonly _chats: ChatsIndex
constructor( constructor(
client: TelegramClient, client: TelegramClient,
raw: tl.RawUpdateChatParticipant | tl.RawUpdateChannelParticipant, raw: tl.RawUpdateChatParticipant | tl.RawUpdateChannelParticipant,
users: Record<number, tl.TypeUser>, users: UsersIndex,
chats: Record<number, tl.TypeChat> chats: ChatsIndex
) { ) {
this.client = client this.client = client
this.raw = raw this.raw = raw

View file

@ -4,7 +4,7 @@ import {
TelegramClient, TelegramClient,
User, User,
Location, Location,
MtCuteArgumentError, MtCuteArgumentError, UsersIndex,
} from '@mtcute/client' } from '@mtcute/client'
import { encodeInlineMessageId } from '@mtcute/client/src/utils/inline-utils' import { encodeInlineMessageId } from '@mtcute/client/src/utils/inline-utils'
@ -18,12 +18,12 @@ export class ChosenInlineResult {
readonly client: TelegramClient readonly client: TelegramClient
readonly raw: tl.RawUpdateBotInlineSend readonly raw: tl.RawUpdateBotInlineSend
readonly _users: Record<number, tl.TypeUser> readonly _users: UsersIndex
constructor( constructor(
client: TelegramClient, client: TelegramClient,
raw: tl.RawUpdateBotInlineSend, raw: tl.RawUpdateBotInlineSend,
users: Record<number, tl.TypeUser> users: UsersIndex
) { ) {
this.client = client this.client = client
this.raw = raw this.raw = raw

View file

@ -1,5 +1,5 @@
import { makeInspectable } from '@mtcute/client/src/types/utils' import { makeInspectable } from '@mtcute/client/src/types/utils'
import { TelegramClient, Poll } from '@mtcute/client' import { TelegramClient, Poll, UsersIndex } from '@mtcute/client'
import { tl } from '@mtcute/tl' import { tl } from '@mtcute/tl'
/** /**
@ -13,9 +13,13 @@ export class PollUpdate {
readonly client: TelegramClient readonly client: TelegramClient
readonly raw: tl.RawUpdateMessagePoll readonly raw: tl.RawUpdateMessagePoll
readonly _users: Record<number, tl.TypeUser> readonly _users: UsersIndex
constructor (client: TelegramClient, raw: tl.RawUpdateMessagePoll, users: Record<number, tl.TypeUser>) { constructor(
client: TelegramClient,
raw: tl.RawUpdateMessagePoll,
users: UsersIndex
) {
this.client = client this.client = client
this.raw = raw this.raw = raw
this._users = users this._users = users
@ -55,15 +59,21 @@ export class PollUpdate {
_: 'poll', _: 'poll',
id: this.raw.pollId, id: this.raw.pollId,
question: '', question: '',
answers: this.raw.results.results?.map((res) => ({ answers:
_: 'pollAnswer', this.raw.results.results?.map((res) => ({
text: '', _: 'pollAnswer',
option: res.option text: '',
})) ?? [] option: res.option,
})) ?? [],
} }
} }
this._poll = new Poll(this.client, poll, this._users, this.raw.results) this._poll = new Poll(
this.client,
poll,
this._users,
this.raw.results
)
} }
return this._poll return this._poll

View file

@ -1,4 +1,9 @@
import { MtCuteUnsupportedError, TelegramClient, User } from '@mtcute/client' import {
MtCuteUnsupportedError,
TelegramClient,
User,
UsersIndex,
} from '@mtcute/client'
import { tl } from '@mtcute/tl' import { tl } from '@mtcute/tl'
import { makeInspectable } from '@mtcute/client/src/types/utils' import { makeInspectable } from '@mtcute/client/src/types/utils'
@ -12,9 +17,13 @@ export class PollVoteUpdate {
readonly client: TelegramClient readonly client: TelegramClient
readonly raw: tl.RawUpdateMessagePollVote readonly raw: tl.RawUpdateMessagePollVote
readonly _users: Record<number, tl.TypeUser> readonly _users: UsersIndex
constructor(client: TelegramClient, raw: tl.RawUpdateMessagePollVote, users: Record<number, tl.TypeUser>) { constructor(
client: TelegramClient,
raw: tl.RawUpdateMessagePollVote,
users: UsersIndex
) {
this.client = client this.client = client
this.raw = raw this.raw = raw
this._users = users this._users = users