diff --git a/mautrix_telegram/portal.py b/mautrix_telegram/portal.py index cc40cc7a..00a79d5b 100644 --- a/mautrix_telegram/portal.py +++ b/mautrix_telegram/portal.py @@ -3628,7 +3628,9 @@ class Portal(DBPortal, BasePortal): async def _mark_disappearing( self, event_id: EventID, seconds: int, expires_at: int | None ) -> None: - dm = DisappearingMessage(self.mxid, event_id, seconds, expiration_ts=expires_at * 1000) + dm = DisappearingMessage( + self.mxid, event_id, seconds, expiration_ts=expires_at * 1000 if expires_at else None + ) await dm.insert() if expires_at: background_task.create(self._disappear_event(dm)) diff --git a/mautrix_telegram/portal_util/message_convert.py b/mautrix_telegram/portal_util/message_convert.py index a195a2a0..6494df7e 100644 --- a/mautrix_telegram/portal_util/message_convert.py +++ b/mautrix_telegram/portal_util/message_convert.py @@ -439,9 +439,21 @@ class TelegramMessageConverter: return ConvertedMessage( content=content, caption=caption_content, - disappear_seconds=media.ttl_seconds, + disappear_seconds=self._adjust_ttl(media.ttl_seconds), ) + @staticmethod + def _adjust_ttl(ttl: int | None) -> int | None: + if not ttl: + return None + elif ttl == 2147483647: + # View-once media, set low TTL + return 15 + else: + # Increase media TTL because it's supposed to be counted from opening the media, + # but we can only count it from read receipt. + return ttl * 5 + async def _convert_document( self, source: au.AbstractUser, @@ -548,7 +560,7 @@ class TelegramMessageConverter: type=event_type, content=content, caption=caption_content, - disappear_seconds=evt.media.ttl_seconds, + disappear_seconds=self._adjust_ttl(evt.media.ttl_seconds), ) @staticmethod diff --git a/requirements.txt b/requirements.txt index 838adb8e..c2e85b9a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ commonmark>=0.8,<0.10 aiohttp>=3,<4 yarl>=1,<2 mautrix>=0.20.2,<0.21 -tulir-telethon==1.30.0a2 +tulir-telethon==1.32.0a1 asyncpg>=0.20,<0.29 mako>=1,<2 setuptools