refactor: use UsersIndex and ChatsIndex types instead of bare record types
This commit is contained in:
parent
0525800133
commit
0f1edcfcf7
20 changed files with 116 additions and 70 deletions
|
@ -143,6 +143,7 @@ import {
|
|||
ChatInviteLink,
|
||||
ChatMember,
|
||||
ChatPreview,
|
||||
ChatsIndex,
|
||||
Dialog,
|
||||
FileDownloadParameters,
|
||||
InputChatPermissions,
|
||||
|
@ -166,6 +167,7 @@ import {
|
|||
UploadFileLike,
|
||||
UploadedFile,
|
||||
User,
|
||||
UsersIndex,
|
||||
} from './types'
|
||||
import { MaybeArray, MaybeAsync, TelegramConnection } from '@mtcute/core'
|
||||
import { Lock } from './utils/lock'
|
||||
|
@ -490,6 +492,7 @@ export interface TelegramClient extends BaseTelegramClient {
|
|||
* @param queryId Inline query ID
|
||||
* @param results Results of the query
|
||||
* @param params Additional parameters
|
||||
|
||||
*/
|
||||
answerInlineQuery(
|
||||
queryId: tl.Long,
|
||||
|
@ -691,6 +694,7 @@ export interface TelegramClient extends BaseTelegramClient {
|
|||
*
|
||||
* @param chatId Chat ID
|
||||
* @param params
|
||||
|
||||
*/
|
||||
getChatEventLog(
|
||||
chatId: InputPeerLike,
|
||||
|
@ -843,6 +847,7 @@ export interface TelegramClient extends BaseTelegramClient {
|
|||
*
|
||||
* @param latitude Latitude of the location
|
||||
* @param longitude Longitude of the location
|
||||
|
||||
*/
|
||||
getNearbyChats(latitude: number, longitude: number): Promise<Chat[]>
|
||||
/**
|
||||
|
@ -1054,6 +1059,7 @@ export interface TelegramClient extends BaseTelegramClient {
|
|||
*
|
||||
* @param folder Parameters for the folder
|
||||
* @returns Newly created folder
|
||||
|
||||
*/
|
||||
createFolder(
|
||||
folder: PartialExcept<tl.RawDialogFilter, 'title'>
|
||||
|
@ -1102,6 +1108,7 @@ export interface TelegramClient extends BaseTelegramClient {
|
|||
* is not considered when sorting.
|
||||
*
|
||||
* @param params Fetch parameters
|
||||
|
||||
*/
|
||||
getDialogs(params?: {
|
||||
/**
|
||||
|
@ -1740,6 +1747,7 @@ export interface TelegramClient extends BaseTelegramClient {
|
|||
*
|
||||
* @param chatId Chat ID
|
||||
* @param message ID of one of the messages in the group
|
||||
|
||||
*/
|
||||
getMessageGroup(chatId: InputPeerLike, message: number): Promise<Message[]>
|
||||
/**
|
||||
|
@ -1956,6 +1964,7 @@ export interface TelegramClient extends BaseTelegramClient {
|
|||
* @param fromChatId Target chat ID
|
||||
* @param message Message ID to forward
|
||||
* @param params
|
||||
|
||||
*/
|
||||
sendCopy(
|
||||
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 text Text of the message
|
||||
* @param params Additional sending parameters
|
||||
|
||||
*/
|
||||
sendText(
|
||||
chatId: InputPeerLike,
|
||||
|
@ -2528,8 +2538,8 @@ export interface TelegramClient extends BaseTelegramClient {
|
|||
*/
|
||||
dispatchUpdate(
|
||||
update: tl.TypeUpdate | tl.TypeMessage,
|
||||
users: Record<number, tl.TypeUser>,
|
||||
chats: Record<number, tl.TypeChat>
|
||||
users: UsersIndex,
|
||||
chats: ChatsIndex
|
||||
): void
|
||||
/**
|
||||
* Catch up with the server by loading missed updates.
|
||||
|
|
|
@ -35,7 +35,9 @@ import {
|
|||
TypingStatus,
|
||||
Photo,
|
||||
ChatEvent,
|
||||
ChatInviteLink
|
||||
ChatInviteLink,
|
||||
UsersIndex,
|
||||
ChatsIndex
|
||||
} from '../types'
|
||||
|
||||
// @copy
|
||||
|
|
|
@ -11,6 +11,7 @@ import { Lock } from '../utils/lock'
|
|||
import bigInt from 'big-integer'
|
||||
import { MAX_CHANNEL_ID } from '@mtcute/core'
|
||||
import { isDummyUpdate, isDummyUpdates } from '../utils/updates-utils'
|
||||
import { ChatsIndex, UsersIndex } from '../types'
|
||||
|
||||
const debug = require('debug')('mtcute:upds')
|
||||
|
||||
|
@ -135,8 +136,8 @@ export async function _saveStorage(this: TelegramClient): Promise<void> {
|
|||
export function dispatchUpdate(
|
||||
this: TelegramClient,
|
||||
update: tl.TypeUpdate | tl.TypeMessage,
|
||||
users: Record<number, tl.TypeUser>,
|
||||
chats: Record<number, tl.TypeChat>
|
||||
users: UsersIndex,
|
||||
chats: ChatsIndex
|
||||
): void {
|
||||
// no-op //
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import { Message } from '../messages'
|
|||
import { MtCuteArgumentError } from '../errors'
|
||||
import { getMarkedPeerId } from '@mtcute/core'
|
||||
import { encodeInlineMessageId } from '../../utils/inline-utils'
|
||||
import { User } from '../peers'
|
||||
import { User, UsersIndex } from '../peers'
|
||||
|
||||
/**
|
||||
* An incoming callback query, originated from a callback button
|
||||
|
@ -17,12 +17,12 @@ export class CallbackQuery {
|
|||
| tl.RawUpdateBotCallbackQuery
|
||||
| tl.RawUpdateInlineBotCallbackQuery
|
||||
|
||||
readonly _users: Record<number, tl.TypeUser>
|
||||
readonly _users: UsersIndex
|
||||
|
||||
constructor(
|
||||
client: TelegramClient,
|
||||
raw: tl.RawUpdateBotCallbackQuery | tl.RawUpdateInlineBotCallbackQuery,
|
||||
users: Record<number, tl.TypeUser>
|
||||
users: UsersIndex
|
||||
) {
|
||||
this.client = client
|
||||
this.raw = raw
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { makeInspectable } from '@mtcute/client/src/types/utils'
|
||||
import { tl } from '@mtcute/tl'
|
||||
import { PeerType, User } from '../peers'
|
||||
import { PeerType, User, UsersIndex } from '../peers'
|
||||
import { TelegramClient } from '../../client'
|
||||
import { Location } from '../media'
|
||||
import { InputInlineResult } from './input'
|
||||
|
@ -18,12 +18,12 @@ export class InlineQuery {
|
|||
readonly raw: tl.RawUpdateBotInlineQuery
|
||||
|
||||
/** Map of users in this message. Mainly for internal use */
|
||||
readonly _users: Record<number, tl.TypeUser>
|
||||
readonly _users: UsersIndex
|
||||
|
||||
constructor(
|
||||
client: TelegramClient,
|
||||
raw: tl.RawUpdateBotInlineQuery,
|
||||
users: Record<number, tl.TypeUser>
|
||||
users: UsersIndex
|
||||
) {
|
||||
this.client = client
|
||||
this.raw = raw
|
||||
|
|
|
@ -3,6 +3,7 @@ import { tl } from '@mtcute/tl'
|
|||
import { TelegramClient } from '../../client'
|
||||
import { MessageEntity } from '../messages'
|
||||
import bigInt from 'big-integer'
|
||||
import { UsersIndex } from '../peers'
|
||||
|
||||
export namespace Poll {
|
||||
export interface PollAnswer {
|
||||
|
@ -41,12 +42,12 @@ export class Poll {
|
|||
readonly raw: tl.TypePoll
|
||||
readonly results?: tl.TypePollResults
|
||||
|
||||
readonly _users: Record<number, tl.TypeUser>
|
||||
readonly _users: UsersIndex
|
||||
|
||||
constructor(
|
||||
client: TelegramClient,
|
||||
raw: tl.TypePoll,
|
||||
users: Record<number, tl.TypeUser>,
|
||||
users: UsersIndex,
|
||||
results?: tl.TypePollResults
|
||||
) {
|
||||
this.client = client
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { TelegramClient } from '../../client'
|
||||
import { tl } from '@mtcute/tl'
|
||||
import { Chat } from '../peers'
|
||||
import { Chat, ChatsIndex, UsersIndex } from '../peers'
|
||||
import { Message } from './message'
|
||||
import { DraftMessage } from './draft-message'
|
||||
import { makeInspectable } from '../utils'
|
||||
|
@ -18,10 +18,10 @@ export class Dialog {
|
|||
readonly raw: tl.RawDialog
|
||||
|
||||
/** 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 */
|
||||
readonly _chats: Record<number, tl.TypeChat>
|
||||
readonly _chats: ChatsIndex
|
||||
|
||||
/** Map of messages in this object. Mainly for internal use */
|
||||
readonly _messages: Record<number, tl.TypeMessage>
|
||||
|
@ -29,8 +29,8 @@ export class Dialog {
|
|||
constructor(
|
||||
client: TelegramClient,
|
||||
raw: tl.RawDialog,
|
||||
users: Record<number, tl.TypeUser>,
|
||||
chats: Record<number, tl.TypeChat>,
|
||||
users: UsersIndex,
|
||||
chats: ChatsIndex,
|
||||
messages: Record<number, tl.TypeMessage>
|
||||
) {
|
||||
this.client = client
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { User, Chat, InputPeerLike } from '../peers'
|
||||
import { User, Chat, InputPeerLike, UsersIndex, ChatsIndex } from '../peers'
|
||||
import { tl } from '@mtcute/tl'
|
||||
import { BotKeyboard, ReplyMarkup } from '../bots'
|
||||
import { MAX_CHANNEL_ID } from '@mtcute/core'
|
||||
|
@ -90,17 +90,17 @@ export class Message {
|
|||
readonly raw: tl.RawMessage | tl.RawMessageService
|
||||
|
||||
/** 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 */
|
||||
readonly _chats: Record<number, tl.TypeChat>
|
||||
readonly _chats: ChatsIndex
|
||||
|
||||
private _emptyError?: MtCuteEmptyError
|
||||
|
||||
constructor(
|
||||
client: TelegramClient,
|
||||
raw: tl.TypeMessage,
|
||||
users: Record<number, tl.TypeUser>,
|
||||
chats: Record<number, tl.TypeChat>,
|
||||
users: UsersIndex,
|
||||
chats: ChatsIndex,
|
||||
isScheduled = false
|
||||
) {
|
||||
this.client = client
|
||||
|
|
|
@ -8,6 +8,7 @@ import { Message } from '../messages'
|
|||
import { ChatPermissions } from './chat-permissions'
|
||||
import { ChatLocation } from './chat-location'
|
||||
import { ChatInviteLink } from './chat-invite-link'
|
||||
import { ChatsIndex, UsersIndex } from './index'
|
||||
|
||||
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) */
|
||||
|
@ -496,14 +497,14 @@ export class ChatEvent {
|
|||
readonly client: TelegramClient
|
||||
readonly raw: tl.TypeChannelAdminLogEvent
|
||||
|
||||
readonly _users: Record<number, tl.TypeUser>
|
||||
readonly _chats: Record<number, tl.TypeChat>
|
||||
readonly _users: UsersIndex
|
||||
readonly _chats: ChatsIndex
|
||||
|
||||
constructor(
|
||||
client: TelegramClient,
|
||||
raw: tl.TypeChannelAdminLogEvent,
|
||||
users: Record<number, tl.TypeUser>,
|
||||
chats: Record<number, tl.TypeChat>
|
||||
users: UsersIndex,
|
||||
chats: ChatsIndex
|
||||
) {
|
||||
this.client = client
|
||||
this.raw = raw
|
||||
|
|
|
@ -2,6 +2,7 @@ import { makeInspectable } from '../utils'
|
|||
import { TelegramClient } from '../../client'
|
||||
import { tl } from '@mtcute/tl'
|
||||
import { User } from './user'
|
||||
import { UsersIndex } from './index'
|
||||
|
||||
export namespace ChatInviteLink {
|
||||
export interface JoinedMember {
|
||||
|
@ -17,9 +18,9 @@ export class ChatInviteLink {
|
|||
readonly client: TelegramClient
|
||||
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.raw = raw
|
||||
this._users = users
|
||||
|
|
|
@ -4,6 +4,7 @@ import { tl } from '@mtcute/tl'
|
|||
import { User } from './user'
|
||||
import { assertTypeIs } from '../../utils/type-assertion'
|
||||
import { ChatPermissions } from './chat-permissions'
|
||||
import { UsersIndex } from './index'
|
||||
|
||||
export namespace ChatMember {
|
||||
/**
|
||||
|
@ -32,12 +33,12 @@ export class ChatMember {
|
|||
readonly raw: tl.TypeChatParticipant | tl.TypeChannelParticipant
|
||||
|
||||
/** Map of users in this object. Mainly for internal use */
|
||||
readonly _users: Record<number, tl.TypeUser>
|
||||
readonly _users: UsersIndex
|
||||
|
||||
constructor(
|
||||
client: TelegramClient,
|
||||
raw: tl.TypeChatParticipant | tl.TypeChannelParticipant,
|
||||
users: Record<number, tl.TypeUser>,
|
||||
users: UsersIndex,
|
||||
) {
|
||||
this.client = client
|
||||
this.raw = raw
|
||||
|
|
|
@ -5,7 +5,7 @@ import { TelegramClient } from '../../client'
|
|||
import { getMarkedPeerId, MaybeArray } from '@mtcute/core'
|
||||
import { MtCuteArgumentError, MtCuteTypeAssertionError } from '../errors'
|
||||
import { makeInspectable } from '../utils'
|
||||
import { InputPeerLike, User } from './index'
|
||||
import { ChatsIndex, InputPeerLike, User, UsersIndex } from './index'
|
||||
import { ChatLocation } from './chat-location'
|
||||
|
||||
export namespace Chat {
|
||||
|
@ -454,8 +454,8 @@ export class Chat {
|
|||
static _parseFromMessage(
|
||||
client: TelegramClient,
|
||||
message: tl.RawMessage | tl.RawMessageService,
|
||||
users: Record<number, tl.TypeUser>,
|
||||
chats: Record<number, tl.TypeChat>
|
||||
users: UsersIndex,
|
||||
chats: ChatsIndex
|
||||
): Chat {
|
||||
return Chat._parseFromPeer(client, message.peerId, users, chats)
|
||||
}
|
||||
|
@ -464,8 +464,8 @@ export class Chat {
|
|||
static _parseFromPeer(
|
||||
client: TelegramClient,
|
||||
peer: tl.TypePeer,
|
||||
users: Record<number, tl.TypeUser>,
|
||||
chats: Record<number, tl.TypeChat>
|
||||
users: UsersIndex,
|
||||
chats: ChatsIndex
|
||||
): Chat {
|
||||
if (peer._ === 'peerUser') {
|
||||
return new Chat(client, users[peer.userId])
|
||||
|
|
|
@ -35,3 +35,6 @@ export type InputPeerLike =
|
|||
| tl.TypeInputPeer
|
||||
| tl.TypeInputUser
|
||||
| tl.TypeInputChannel
|
||||
|
||||
export type UsersIndex = Record<number, tl.TypeUser>
|
||||
export type ChatsIndex = Record<number, tl.TypeChat>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { tl } from '@mtcute/tl'
|
||||
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
|
||||
|
||||
|
@ -103,11 +104,11 @@ export function createUsersChatsIndex(
|
|||
chats?: tl.TypeChat[]
|
||||
}
|
||||
): {
|
||||
users: Record<number, tl.TypeUser>
|
||||
chats: Record<number, tl.TypeChat>
|
||||
users: UsersIndex
|
||||
chats: ChatsIndex
|
||||
} {
|
||||
const users: Record<number, tl.TypeUser> = {}
|
||||
const chats: Record<number, tl.TypeChat> = {}
|
||||
const users: UsersIndex = {}
|
||||
const chats: ChatsIndex = {}
|
||||
obj.users?.forEach((e) => (users[e.id] = e))
|
||||
obj.chats?.forEach((e) => (chats[e.id] = e))
|
||||
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import {
|
||||
CallbackQuery,
|
||||
ChatsIndex,
|
||||
InlineQuery,
|
||||
Message,
|
||||
MtCuteArgumentError,
|
||||
TelegramClient,
|
||||
UsersIndex,
|
||||
} from '@mtcute/client'
|
||||
import { tl } from '@mtcute/tl'
|
||||
import {
|
||||
|
@ -42,8 +44,8 @@ const noop = () => {}
|
|||
type ParserFunction = (
|
||||
client: TelegramClient,
|
||||
upd: tl.TypeUpdate | tl.TypeMessage,
|
||||
users: Record<number, tl.TypeUser>,
|
||||
chats: Record<number, tl.TypeChat>
|
||||
users: UsersIndex,
|
||||
chats: ChatsIndex
|
||||
) => any
|
||||
type UpdateParser = [Exclude<UpdateHandler['type'], 'raw'>, ParserFunction]
|
||||
|
||||
|
@ -73,7 +75,7 @@ const callbackQueryParser: UpdateParser = [
|
|||
]
|
||||
const userTypingParser: UpdateParser = [
|
||||
'user_typing',
|
||||
(client, upd) => new UserTypingUpdate(client, upd as any)
|
||||
(client, upd) => new UserTypingUpdate(client, upd as any),
|
||||
]
|
||||
|
||||
const PARSERS: Partial<
|
||||
|
@ -182,8 +184,8 @@ export class Dispatcher {
|
|||
*/
|
||||
dispatchUpdate(
|
||||
update: tl.TypeUpdate | tl.TypeMessage,
|
||||
users: Record<number, tl.TypeUser>,
|
||||
chats: Record<number, tl.TypeChat>
|
||||
users: UsersIndex,
|
||||
chats: ChatsIndex
|
||||
): void {
|
||||
if (!this._client) return
|
||||
|
||||
|
@ -208,8 +210,8 @@ export class Dispatcher {
|
|||
*/
|
||||
async dispatchUpdateNow(
|
||||
update: tl.TypeUpdate | tl.TypeMessage,
|
||||
users: Record<number, tl.TypeUser>,
|
||||
chats: Record<number, tl.TypeChat>
|
||||
users: UsersIndex,
|
||||
chats: ChatsIndex
|
||||
): Promise<void> {
|
||||
if (!this._client) return
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@ import {
|
|||
TelegramClient,
|
||||
InlineQuery,
|
||||
CallbackQuery,
|
||||
UsersIndex,
|
||||
ChatsIndex,
|
||||
} from '@mtcute/client'
|
||||
import { tl } from '@mtcute/tl'
|
||||
import { PropagationSymbol } from './propagation'
|
||||
|
@ -35,14 +37,14 @@ export type RawUpdateHandler = BaseUpdateHandler<
|
|||
(
|
||||
client: TelegramClient,
|
||||
update: tl.TypeUpdate,
|
||||
users: Record<number, tl.TypeUser>,
|
||||
chats: Record<number, tl.TypeChat>
|
||||
users: UsersIndex,
|
||||
chats: ChatsIndex
|
||||
) => MaybeAsync<void | PropagationSymbol>,
|
||||
(
|
||||
client: TelegramClient,
|
||||
update: tl.TypeUpdate,
|
||||
users: Record<number, tl.TypeUser>,
|
||||
chats: Record<number, tl.TypeChat>
|
||||
users: UsersIndex,
|
||||
chats: ChatsIndex
|
||||
) => MaybeAsync<boolean>
|
||||
>
|
||||
|
||||
|
|
|
@ -3,8 +3,10 @@ import {
|
|||
Chat,
|
||||
ChatInviteLink,
|
||||
ChatMember,
|
||||
ChatsIndex,
|
||||
TelegramClient,
|
||||
User,
|
||||
UsersIndex,
|
||||
} from '@mtcute/client'
|
||||
import { makeInspectable } from '@mtcute/client/src/types/utils'
|
||||
|
||||
|
@ -49,15 +51,15 @@ export class ChatMemberUpdate {
|
|||
readonly raw: tl.RawUpdateChatParticipant | tl.RawUpdateChannelParticipant
|
||||
|
||||
/** 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 */
|
||||
readonly _chats: Record<number, tl.TypeChat>
|
||||
readonly _chats: ChatsIndex
|
||||
|
||||
constructor(
|
||||
client: TelegramClient,
|
||||
raw: tl.RawUpdateChatParticipant | tl.RawUpdateChannelParticipant,
|
||||
users: Record<number, tl.TypeUser>,
|
||||
chats: Record<number, tl.TypeChat>
|
||||
users: UsersIndex,
|
||||
chats: ChatsIndex
|
||||
) {
|
||||
this.client = client
|
||||
this.raw = raw
|
||||
|
|
|
@ -4,7 +4,7 @@ import {
|
|||
TelegramClient,
|
||||
User,
|
||||
Location,
|
||||
MtCuteArgumentError,
|
||||
MtCuteArgumentError, UsersIndex,
|
||||
} from '@mtcute/client'
|
||||
import { encodeInlineMessageId } from '@mtcute/client/src/utils/inline-utils'
|
||||
|
||||
|
@ -18,12 +18,12 @@ export class ChosenInlineResult {
|
|||
readonly client: TelegramClient
|
||||
readonly raw: tl.RawUpdateBotInlineSend
|
||||
|
||||
readonly _users: Record<number, tl.TypeUser>
|
||||
readonly _users: UsersIndex
|
||||
|
||||
constructor(
|
||||
client: TelegramClient,
|
||||
raw: tl.RawUpdateBotInlineSend,
|
||||
users: Record<number, tl.TypeUser>
|
||||
users: UsersIndex
|
||||
) {
|
||||
this.client = client
|
||||
this.raw = raw
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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'
|
||||
|
||||
/**
|
||||
|
@ -13,9 +13,13 @@ export class PollUpdate {
|
|||
readonly client: TelegramClient
|
||||
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.raw = raw
|
||||
this._users = users
|
||||
|
@ -55,15 +59,21 @@ export class PollUpdate {
|
|||
_: 'poll',
|
||||
id: this.raw.pollId,
|
||||
question: '',
|
||||
answers: this.raw.results.results?.map((res) => ({
|
||||
answers:
|
||||
this.raw.results.results?.map((res) => ({
|
||||
_: 'pollAnswer',
|
||||
text: '',
|
||||
option: res.option
|
||||
})) ?? []
|
||||
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
|
||||
|
|
|
@ -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 { makeInspectable } from '@mtcute/client/src/types/utils'
|
||||
|
||||
|
@ -12,9 +17,13 @@ export class PollVoteUpdate {
|
|||
readonly client: TelegramClient
|
||||
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.raw = raw
|
||||
this._users = users
|
||||
|
|
Loading…
Reference in a new issue