From 4b198c7d5f964607eb95c24ad944e181869f29ac Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Tue, 8 Aug 2023 12:48:51 -0600 Subject: [PATCH] stickers: passthrough webm and tgs files I got the mime type of tgs files from here: https://github.com/tulir/Telethon/blob/main/telethon/utils.py#L54 Signed-off-by: Sumner Evans --- mautrix_telegram/portal.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mautrix_telegram/portal.py b/mautrix_telegram/portal.py index 78d0c9c9..68f7d7ff 100644 --- a/mautrix_telegram/portal.py +++ b/mautrix_telegram/portal.py @@ -99,6 +99,7 @@ DocumentAttributeAudio, DocumentAttributeFilename, DocumentAttributeImageSize, + DocumentAttributeSticker, DocumentAttributeVideo, GeoPoint, InputChannel, @@ -110,6 +111,7 @@ InputPeerChat, InputPeerPhotoFileLocation, InputPeerUser, + InputStickerSetEmpty, InputUser, MessageActionChannelCreate, MessageActionChatAddUser, @@ -1841,6 +1843,7 @@ async def _handle_matrix_file( max_image_size = self.config["bridge.image_as_file_size"] * 1000**2 max_image_pixels = self.config["bridge.image_as_file_pixels"] + attributes = [] if self.config["bridge.parallel_file_transfer"] and content.url: file_handle, file_size = await util.parallel_transfer_to_telegram( client, self.main_intent, content.url, sender_id @@ -1860,7 +1863,10 @@ async def _handle_matrix_file( file = await self.main_intent.download_media(content.url) if content.msgtype == MessageType.STICKER: - if mime != "image/gif": + attributes.append( + DocumentAttributeSticker(alt=content.body, stickerset=InputStickerSetEmpty()) + ) + if mime not in ("image/webm", "image/gif", "application/x-tgsticker"): mime, file, w, h = util.convert_image( file, source_mime=mime, target_type="webp" ) @@ -1873,8 +1879,8 @@ async def _handle_matrix_file( file_handle.name = file_name force_document = file_size >= max_image_size + attributes.append(DocumentAttributeFilename(file_name=file_name)) - attributes = [DocumentAttributeFilename(file_name=file_name)] if content.msgtype == MessageType.VIDEO: attributes.append( DocumentAttributeVideo(