From 1fb8a7a0a50a6cb9c8de2d6dee829c7df9aec076 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 | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/mautrix_telegram/portal.py b/mautrix_telegram/portal.py index 78d0c9c9..701b3eb9 100644 --- a/mautrix_telegram/portal.py +++ b/mautrix_telegram/portal.py @@ -99,6 +99,7 @@ from telethon.tl.types import ( DocumentAttributeAudio, DocumentAttributeFilename, DocumentAttributeImageSize, + DocumentAttributeSticker, DocumentAttributeVideo, GeoPoint, InputChannel, @@ -110,6 +111,7 @@ from telethon.tl.types import ( InputPeerChat, InputPeerPhotoFileLocation, InputPeerUser, + InputStickerSetEmpty, InputUser, MessageActionChannelCreate, MessageActionChatAddUser, @@ -1841,6 +1843,7 @@ class Portal(DBPortal, BasePortal): 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,21 +1863,27 @@ class Portal(DBPortal, BasePortal): file = await self.main_intent.download_media(content.url) if content.msgtype == MessageType.STICKER: - if mime != "image/gif": - mime, file, w, h = util.convert_image( - file, source_mime=mime, target_type="webp" - ) - else: + if mime == "image/gif": # Remove sticker description file_name = "sticker.gif" + else: + if mime not in ("video/webm", "application/x-tgsticker"): + mime, file, w, h = util.convert_image( + file, source_mime=mime, target_type="webp" + ) + attributes.append( + DocumentAttributeSticker( + alt=content.body, stickerset=InputStickerSetEmpty() + ) + ) file_handle = await client.upload_file(file) file_size = len(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(