Skip to content

Commit

Permalink
stickers: passthrough webm and tgs files
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
sumnerevans committed Aug 8, 2023
1 parent f79ab28 commit 4b198c7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions mautrix_telegram/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
DocumentAttributeAudio,
DocumentAttributeFilename,
DocumentAttributeImageSize,
DocumentAttributeSticker,
DocumentAttributeVideo,
GeoPoint,
InputChannel,
Expand All @@ -110,6 +111,7 @@
InputPeerChat,
InputPeerPhotoFileLocation,
InputPeerUser,
InputStickerSetEmpty,
InputUser,
MessageActionChannelCreate,
MessageActionChatAddUser,
Expand Down Expand Up @@ -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
Expand All @@ -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"
)
Expand All @@ -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(
Expand Down

0 comments on commit 4b198c7

Please sign in to comment.