fix(client): correct sending of newly uploaded files in media groups

This commit is contained in:
teidesu 2021-07-10 01:09:49 +03:00
parent b38f2cd6ae
commit a33548e790
3 changed files with 10 additions and 2 deletions

View file

@ -1587,6 +1587,7 @@ export interface TelegramClient extends BaseTelegramClient {
params: { params: {
parseMode?: string | null parseMode?: string | null
progressCallback?: (uploaded: number, total: number) => void progressCallback?: (uploaded: number, total: number) => void
uploadPeer?: tl.TypeInputPeer
}, },
uploadMedia?: boolean uploadMedia?: boolean
): Promise<tl.TypeInputMedia> ): Promise<tl.TypeInputMedia>

View file

@ -29,6 +29,7 @@ export async function _normalizeInputMedia(
params: { params: {
parseMode?: string | null parseMode?: string | null
progressCallback?: (uploaded: number, total: number) => void progressCallback?: (uploaded: number, total: number) => void
uploadPeer?: tl.TypeInputPeer
}, },
uploadMedia = false uploadMedia = false
): Promise<tl.TypeInputMedia> { ): Promise<tl.TypeInputMedia> {
@ -216,6 +217,8 @@ export async function _normalizeInputMedia(
mime = uploaded.mime mime = uploaded.mime
} }
const uploadPeer = params.uploadPeer ?? { _: 'inputPeerSelf' }
const uploadMediaIfNeeded = async ( const uploadMediaIfNeeded = async (
inputMedia: tl.TypeInputMedia, inputMedia: tl.TypeInputMedia,
photo: boolean photo: boolean
@ -224,7 +227,7 @@ export async function _normalizeInputMedia(
const res = await this.call({ const res = await this.call({
_: 'messages.uploadMedia', _: 'messages.uploadMedia',
peer: { _: 'inputPeerSelf' }, peer: uploadPeer,
media: inputMedia, media: inputMedia,
}) })

View file

@ -148,7 +148,11 @@ export async function sendMediaGroup(
const inputMedia = await this._normalizeInputMedia(media, { const inputMedia = await this._normalizeInputMedia(media, {
progressCallback: params.progressCallback?.bind(null, i), progressCallback: params.progressCallback?.bind(null, i),
}) // i have no fucking clue why we should upload it manually,
// but otherwise Telegram throws MEDIA_INVALID
// fuck my life
uploadPeer: peer
}, true)
const [message, entities] = await this._parseEntities( const [message, entities] = await this._parseEntities(
// some types dont have `caption` field, and ts warns us, // some types dont have `caption` field, and ts warns us,