fix(client): updateShortSentMessage handling
oops
This commit is contained in:
parent
e335a6cf10
commit
389b3cfae0
3 changed files with 30 additions and 35 deletions
|
@ -1,5 +1,12 @@
|
|||
import { MtArgumentError, tl } from '@mtcute/core'
|
||||
import { BaseTelegramClient, MtArgumentError, tl } from '@mtcute/core'
|
||||
|
||||
import {
|
||||
isInputPeerChannel,
|
||||
isInputPeerChat,
|
||||
isInputPeerUser,
|
||||
toInputChannel,
|
||||
toInputUser,
|
||||
} from '../../utils/peer-utils.js'
|
||||
import { batchedQuery } from '../../utils/query-batcher.js'
|
||||
import { getAuthState } from '../auth/_state.js'
|
||||
|
||||
|
@ -120,3 +127,19 @@ export const _getChannelsBatched = batchedQuery<tl.TypeInputChannel, tl.RawChann
|
|||
}
|
||||
},
|
||||
})
|
||||
|
||||
/** @internal */
|
||||
export function _getRawPeerBatched(
|
||||
client: BaseTelegramClient,
|
||||
peer: tl.TypeInputPeer,
|
||||
): Promise<tl.TypeUser | tl.TypeChat | null> {
|
||||
if (isInputPeerUser(peer)) {
|
||||
return _getUsersBatched(client, toInputUser(peer))
|
||||
} else if (isInputPeerChannel(peer)) {
|
||||
return _getChannelsBatched(client, toInputChannel(peer))
|
||||
} else if (isInputPeerChat(peer)) {
|
||||
return _getChatsBatched(client, peer.chatId)
|
||||
}
|
||||
|
||||
throw new MtArgumentError('Invalid peer')
|
||||
}
|
||||
|
|
|
@ -1,16 +1,9 @@
|
|||
import { BaseTelegramClient, MtArgumentError, tl } from '@mtcute/core'
|
||||
import { BaseTelegramClient, MtArgumentError } from '@mtcute/core'
|
||||
|
||||
import { Chat, InputPeerLike, MtPeerNotFoundError } from '../../types/index.js'
|
||||
import {
|
||||
INVITE_LINK_REGEX,
|
||||
isInputPeerChannel,
|
||||
isInputPeerChat,
|
||||
isInputPeerUser,
|
||||
toInputChannel,
|
||||
toInputUser,
|
||||
} from '../../utils/peer-utils.js'
|
||||
import { INVITE_LINK_REGEX } from '../../utils/peer-utils.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
import { _getChannelsBatched, _getChatsBatched, _getUsersBatched } from './batched-queries.js'
|
||||
import { _getRawPeerBatched } from './batched-queries.js'
|
||||
|
||||
// @available=both
|
||||
/**
|
||||
|
@ -41,14 +34,7 @@ export async function getChat(client: BaseTelegramClient, chatId: InputPeerLike)
|
|||
|
||||
const peer = await resolvePeer(client, chatId)
|
||||
|
||||
let res: tl.TypeChat | tl.TypeUser | null
|
||||
if (isInputPeerChannel(peer)) {
|
||||
res = await _getChannelsBatched(client, toInputChannel(peer))
|
||||
} else if (isInputPeerUser(peer)) {
|
||||
res = await _getUsersBatched(client, toInputUser(peer))
|
||||
} else if (isInputPeerChat(peer)) {
|
||||
res = await _getChatsBatched(client, peer.chatId)
|
||||
} else throw new Error('should not happen')
|
||||
const res = await _getRawPeerBatched(client, peer)
|
||||
|
||||
if (!res) throw new MtPeerNotFoundError(`Chat ${JSON.stringify(chatId)} was not found`)
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import { normalizeDate } from '../../utils/misc-utils.js'
|
|||
import { inputPeerToPeer } from '../../utils/peer-utils.js'
|
||||
import { createDummyUpdate } from '../../utils/updates-utils.js'
|
||||
import { getAuthState } from '../auth/_state.js'
|
||||
import { _getRawPeerBatched } from '../chats/batched-queries.js'
|
||||
import { _normalizeInputText } from '../misc/normalize-text.js'
|
||||
import { resolvePeer } from '../users/resolve-peer.js'
|
||||
import { _findMessageInUpdate } from './find-in-update.js'
|
||||
|
@ -97,22 +98,7 @@ export async function sendText(
|
|||
let cached = await client.storage.getFullPeerById(id)
|
||||
|
||||
if (!cached) {
|
||||
switch (peer._) {
|
||||
case 'inputPeerChat':
|
||||
case 'peerChat':
|
||||
// resolvePeer does not fetch the chat.
|
||||
// we need to do it manually
|
||||
cached = await client
|
||||
.call({
|
||||
_: 'messages.getChats',
|
||||
id: [peer.chatId],
|
||||
})
|
||||
.then((res) => res.chats[0])
|
||||
break
|
||||
default:
|
||||
await resolvePeer(client, peer)
|
||||
cached = await client.storage.getFullPeerById(id)
|
||||
}
|
||||
cached = await _getRawPeerBatched(client, await resolvePeer(client, peer))
|
||||
}
|
||||
|
||||
if (!cached) {
|
||||
|
|
Loading…
Reference in a new issue