2022-08-17 09:13:00 +00:00
|
|
|
diff --git a/mautrix_telegram/portal.py b/mautrix_telegram/portal.py
|
2022-08-18 10:07:23 +00:00
|
|
|
index 3b6a81e..c6277a7 100644
|
2022-08-17 09:13:00 +00:00
|
|
|
--- a/mautrix_telegram/portal.py
|
|
|
|
+++ b/mautrix_telegram/portal.py
|
2022-08-18 10:07:23 +00:00
|
|
|
@@ -1626,6 +1626,36 @@ class Portal(DBPortal, BasePortal):
|
2022-08-17 09:13:00 +00:00
|
|
|
msgtype=content.msgtype,
|
|
|
|
)
|
|
|
|
|
|
|
|
+ async def _find_telegram_sticker(
|
|
|
|
+ self,
|
|
|
|
+ client,
|
|
|
|
+ metadata
|
|
|
|
+ ):
|
2022-08-18 10:07:23 +00:00
|
|
|
+ sticker_set_id = int(metadata["pack"]["id"])
|
2022-08-17 09:13:00 +00:00
|
|
|
+ from telethon.tl.functions.messages import GetAllStickersRequest
|
|
|
|
+ sticker_sets = await client(GetAllStickersRequest(0))
|
|
|
|
+ from telethon.tl.functions.messages import GetStickerSetRequest
|
|
|
|
+ from telethon.tl.types import InputStickerSetID
|
|
|
|
+ found_sticker_set = None
|
|
|
|
+ for sticker_set in sticker_sets.sets:
|
2022-08-18 10:07:23 +00:00
|
|
|
+ if sticker_set.id == sticker_set_id:
|
2022-08-17 09:13:00 +00:00
|
|
|
+ found_sticker_set = sticker_set
|
|
|
|
+ break
|
|
|
|
+ if not found_sticker_set:
|
|
|
|
+ return None
|
|
|
|
+
|
|
|
|
+ stickers = await client(GetStickerSetRequest(
|
2022-08-18 10:07:23 +00:00
|
|
|
+ hash = 0,
|
2022-08-17 09:13:00 +00:00
|
|
|
+ stickerset=InputStickerSetID(
|
|
|
|
+ id=found_sticker_set.id, access_hash=found_sticker_set.access_hash
|
|
|
|
+ )
|
|
|
|
+ ))
|
|
|
|
+
|
|
|
|
+ for sticker in stickers.documents:
|
2022-08-18 10:07:23 +00:00
|
|
|
+ if sticker.id == int(metadata["id"]):
|
2022-08-17 09:13:00 +00:00
|
|
|
+ return sticker
|
|
|
|
+
|
|
|
|
+
|
|
|
|
async def _handle_matrix_file(
|
|
|
|
self,
|
|
|
|
sender: u.User,
|
2022-08-18 10:07:23 +00:00
|
|
|
@@ -1646,6 +1676,7 @@ class Portal(DBPortal, BasePortal):
|
2022-08-17 09:13:00 +00:00
|
|
|
w = h = None
|
|
|
|
max_image_size = self.config["bridge.image_as_file_size"] * 1000**2
|
|
|
|
max_image_pixels = self.config["bridge.image_as_file_pixels"]
|
|
|
|
+ media = None
|
|
|
|
|
|
|
|
if self.config["bridge.parallel_file_transfer"] and content.url:
|
|
|
|
file_handle, file_size = await util.parallel_transfer_to_telegram(
|
2022-08-18 10:07:23 +00:00
|
|
|
@@ -1666,7 +1697,14 @@ class Portal(DBPortal, BasePortal):
|
2022-08-17 09:13:00 +00:00
|
|
|
file = await self.main_intent.download_media(content.url)
|
|
|
|
|
|
|
|
if content.msgtype == MessageType.STICKER:
|
|
|
|
- if mime != "image/gif":
|
|
|
|
+ tg_sticker = None
|
|
|
|
+
|
|
|
|
+ if "net.maunium.telegram.sticker" in content.info:
|
|
|
|
+ tg_sticker = await self._find_telegram_sticker(client, content.info["net.maunium.telegram.sticker"])
|
|
|
|
+
|
|
|
|
+ if tg_sticker is not None:
|
|
|
|
+ media = tg_sticker
|
|
|
|
+ elif mime != "image/gif":
|
|
|
|
mime, file, w, h = util.convert_image(
|
|
|
|
file, source_mime=mime, target_type="webp"
|
|
|
|
)
|
2022-08-18 10:07:23 +00:00
|
|
|
@@ -1708,7 +1746,9 @@ class Portal(DBPortal, BasePortal):
|
2022-08-17 09:13:00 +00:00
|
|
|
if "fi.mau.telegram.force_document" in content:
|
|
|
|
force_document = bool(content["fi.mau.telegram.force_document"])
|
|
|
|
|
2022-08-18 10:07:23 +00:00
|
|
|
- if (mime == "image/png" or mime == "image/jpeg") and not force_document:
|
2022-08-17 09:13:00 +00:00
|
|
|
+ if media is not None:
|
|
|
|
+ pass
|
2022-08-18 10:07:23 +00:00
|
|
|
+ elif (mime == "image/png" or mime == "image/jpeg") and not force_document:
|
2022-08-17 09:13:00 +00:00
|
|
|
media = InputMediaUploadedPhoto(file_handle)
|
|
|
|
else:
|
2022-08-18 10:07:23 +00:00
|
|
|
media = InputMediaUploadedDocument(
|