Update Telethon and fix handling disappearing media

This commit is contained in:
Tulir Asokan
2023-10-16 12:53:59 +03:00
parent 22f91d51a3
commit ec298b2b90
3 changed files with 18 additions and 4 deletions
+3 -1
View File
@@ -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))
@@ -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
+1 -1
View File
@@ -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