GramJS: Fix media repair in private chats (#6241)

This commit is contained in:
zubiden 2025-09-19 14:34:50 +02:00 committed by Alexander Zinchuk
parent 2f548efc10
commit f97dd09216

View File

@ -339,10 +339,15 @@ export async function downloadMedia(
onProgress?: ApiOnProgress, onProgress?: ApiOnProgress,
) { ) {
try { try {
return (await downloadMediaWithClient(args, client, onProgress)); const result = await downloadMediaWithClient(args, client, onProgress);
return result;
} catch (err: unknown) { } catch (err: unknown) {
if (err instanceof RPCError) { if (err instanceof RPCError) {
if (err.errorMessage.startsWith('FILE_REFERENCE')) { if (err.errorMessage.startsWith('FILE_REFERENCE')) {
if (DEBUG) {
// eslint-disable-next-line no-console
console.warn('Trying to repair file reference', args.url);
}
const isFileReferenceRepaired = await repairFileReference({ url: args.url }); const isFileReferenceRepaired = await repairFileReference({ url: args.url });
if (isFileReferenceRepaired) { if (isFileReferenceRepaired) {
return downloadMediaWithClient(args, client, onProgress); return downloadMediaWithClient(args, client, onProgress);
@ -525,20 +530,25 @@ export async function repairFileReference({
async function repairMessageMedia(peerId: string, messageId: number) { async function repairMessageMedia(peerId: string, messageId: number) {
const type = getEntityTypeById(peerId); const type = getEntityTypeById(peerId);
const inputChannel = buildInputChannelFromLocalDb(peerId); const inputChannel = buildInputChannelFromLocalDb(peerId);
if (!inputChannel) return false; let result;
const result = await invokeRequest(
type === 'channel' if (type === 'channel' && inputChannel) {
? new GramJs.channels.GetMessages({ result = await invokeRequest(new GramJs.channels.GetMessages({
channel: inputChannel, channel: inputChannel,
id: [new GramJs.InputMessageID({ id: messageId })], id: [new GramJs.InputMessageID({ id: messageId })],
}) }), {
: new GramJs.messages.GetMessages({ shouldIgnoreErrors: true,
});
} else {
result = await invokeRequest(
new GramJs.messages.GetMessages({
id: [new GramJs.InputMessageID({ id: messageId })], id: [new GramJs.InputMessageID({ id: messageId })],
}), }),
{ {
shouldIgnoreErrors: true, shouldIgnoreErrors: true,
}, },
); );
}
if (!result || result instanceof GramJs.messages.MessagesNotModified) return false; if (!result || result instanceof GramJs.messages.MessagesNotModified) return false;