From cb36800c75db699c2dac58cad51aa27217b43f99 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 28 Feb 2021 14:13:07 +0200 Subject: [PATCH] Maybe fix parallel transfer. Fixes #587 --- mautrix_telegram/example-config.yaml | 1 + mautrix_telegram/util/parallel_file_transfer.py | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/mautrix_telegram/example-config.yaml b/mautrix_telegram/example-config.yaml index 28a2da51..101e22a9 100644 --- a/mautrix_telegram/example-config.yaml +++ b/mautrix_telegram/example-config.yaml @@ -207,6 +207,7 @@ bridge: # Enable experimental parallel file transfer, which makes uploads/downloads much faster by # streaming from/to Matrix and using many connections for Telegram. # Note that generating HQ thumbnails for videos is not possible with streamed transfers. + # This option uses internal Telethon implementation details and may break with minor updates. parallel_file_transfer: false # Whether or not created rooms should have federation enabled. # If false, created portal rooms will never be federated. diff --git a/mautrix_telegram/util/parallel_file_transfer.py b/mautrix_telegram/util/parallel_file_transfer.py index 21de18e4..f8444083 100644 --- a/mautrix_telegram/util/parallel_file_transfer.py +++ b/mautrix_telegram/util/parallel_file_transfer.py @@ -27,8 +27,10 @@ from telethon.tl.types import (Document, InputFileLocation, InputDocumentFileLoc InputPhotoFileLocation, InputPeerPhotoFileLocation, TypeInputFile, InputFileBig, InputFile) from telethon.tl.functions.auth import ExportAuthorizationRequest, ImportAuthorizationRequest +from telethon.tl.functions import InvokeWithLayerRequest from telethon.tl.functions.upload import (GetFileRequest, SaveFilePartRequest, SaveBigFilePartRequest) +from telethon.tl.alltlobjects import LAYER from telethon.network import MTProtoSender from telethon.crypto import AuthKey from telethon import utils, helpers @@ -193,9 +195,9 @@ class ParallelTransferrer: if not self.auth_key: log.debug(f"Exporting auth to DC {self.dc_id}") auth = await self.client(ExportAuthorizationRequest(self.dc_id)) - req = self.client._init_with(ImportAuthorizationRequest( - id=auth.id, bytes=auth.bytes - )) + self.client._init_request.query = ImportAuthorizationRequest(id=auth.id, + bytes=auth.bytes) + req = InvokeWithLayerRequest(LAYER, self.client._init_request) await sender.send(req) self.auth_key = sender.auth_key return sender