fix(client): sendMediaGroup returns all sent messages

This commit is contained in:
teidesu 2021-05-16 14:43:23 +03:00
parent e6e28399b0
commit 9bee00e584
2 changed files with 26 additions and 4 deletions

View file

@ -989,7 +989,6 @@ 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[]>
/** /**
@ -2295,7 +2294,7 @@ export interface TelegramClient extends BaseTelegramClient {
*/ */
clearDraft?: boolean clearDraft?: boolean
} }
): Promise<Message> ): Promise<Message[]>
/** /**
* Send a single media (a photo or a document-based media) * Send a single media (a photo or a document-based media)
* *

View file

@ -8,6 +8,8 @@ import {
} from '../../types' } from '../../types'
import { normalizeDate, randomUlong } from '../../utils/misc-utils' import { normalizeDate, randomUlong } from '../../utils/misc-utils'
import { tl } from '@mtcute/tl' import { tl } from '@mtcute/tl'
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
import { createUsersChatsIndex } from '../../utils/peer-utils'
/** /**
* Send a group of media. * Send a group of media.
@ -75,7 +77,7 @@ export async function sendMediaGroup(
*/ */
clearDraft?: boolean clearDraft?: boolean
} }
): Promise<Message> { ): Promise<Message[]> {
if (!params) params = {} if (!params) params = {}
const peer = await this.resolvePeer(chatId) const peer = await this.resolvePeer(chatId)
@ -123,5 +125,26 @@ export async function sendMediaGroup(
clearDraft: params.clearDraft, clearDraft: params.clearDraft,
}) })
return this._findMessageInUpdate(res) assertIsUpdatesGroup('_findMessageInUpdate', res)
this._handleUpdate(res, true)
const { users, chats } = createUsersChatsIndex(res)
return res.updates
.filter(
(u) =>
u._ === 'updateNewMessage' ||
u._ === 'updateNewChannelMessage' ||
u._ === 'updateNewScheduledMessage'
)
.map(
(u) =>
new Message(
this,
(u as any).message,
users,
chats,
u._ === 'updateNewScheduledMessage'
)
)
} }