From 03734a6745a5333405c070aaf6eb37586b2971ce Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 21 Feb 2018 17:11:47 +0200 Subject: [PATCH 1/2] Fix Telegram -> Matrix image bridging --- mautrix_telegram/db.py | 2 +- mautrix_telegram/util/file_transfer.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mautrix_telegram/db.py b/mautrix_telegram/db.py index 81829c7a..4f48412c 100644 --- a/mautrix_telegram/db.py +++ b/mautrix_telegram/db.py @@ -112,7 +112,7 @@ class TelegramFile(Base): mxc = Column(String) mime_type = Column(String) was_converted = Column(Boolean) - timestamp = Column(BigInteger, primary_key=True) + timestamp = Column(BigInteger) def init(db_session): diff --git a/mautrix_telegram/util/file_transfer.py b/mautrix_telegram/util/file_transfer.py index 698cb874..76e113b3 100644 --- a/mautrix_telegram/util/file_transfer.py +++ b/mautrix_telegram/util/file_transfer.py @@ -44,7 +44,7 @@ def _convert_webp(file, to="png"): async def transfer_file_to_matrix(db, client, intent, location): if isinstance(location, (Document, InputDocumentFileLocation)): id = f"{location.id}-{location.version}" - elif not isinstance(location, (FileLocation, InputFileLocation)): + elif isinstance(location, (FileLocation, InputFileLocation)): id = f"{location.volume_id}-{location.local_id}" else: return None From 2d13c30a262a80abb6d30612ee1aff50d264f246 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 21 Feb 2018 23:35:59 +0200 Subject: [PATCH 2/2] Fix possible errors --- mautrix_telegram/bot.py | 6 ++++++ mautrix_telegram/portal.py | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/mautrix_telegram/bot.py b/mautrix_telegram/bot.py index 0a6e71a4..5e29a5b2 100644 --- a/mautrix_telegram/bot.py +++ b/mautrix_telegram/bot.py @@ -65,6 +65,12 @@ class Bot(AbstractUser): except (ChannelPrivateError, ChannelInvalidError): self.remove_chat(id.channel_id) + def register_portal(self, portal): + self.add_chat(portal.tgid, portal.peer_type) + + def unregister_portal(self, portal): + self.remove_chat(portal.tgid) + def add_chat(self, id, type): if id not in self.chats: self.chats[id] = type diff --git a/mautrix_telegram/portal.py b/mautrix_telegram/portal.py index 858c3a9a..22e5e519 100644 --- a/mautrix_telegram/portal.py +++ b/mautrix_telegram/portal.py @@ -491,8 +491,11 @@ class Portal: if self.peer_type == "user": await self.main_intent.leave_room(self.mxid) self.delete() - del self.by_tgid[self.tgid_full] - del self.by_mxid[self.mxid] + try: + del self.by_tgid[self.tgid_full] + del self.by_mxid[self.mxid] + except KeyError: + pass elif source and source.tgid != user.tgid: if self.peer_type == "chat": await source.client(DeleteChatUserRequest(chat_id=self.tgid, user_id=user.tgid))