From 6e1d497e66e02c6cf837b1948a1f4a822f29e4fe Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 20 Feb 2018 21:43:08 +0200 Subject: [PATCH] Fix edit handling/deduplication in channels. Fixes #74 --- mautrix_telegram/abstract_user.py | 6 ++++-- mautrix_telegram/portal.py | 7 +++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/mautrix_telegram/abstract_user.py b/mautrix_telegram/abstract_user.py index f93d1b92..7619c432 100644 --- a/mautrix_telegram/abstract_user.py +++ b/mautrix_telegram/abstract_user.py @@ -269,8 +269,10 @@ class AbstractUser: user = sender.tgid if sender else "admin" if isinstance(original_update, (UpdateEditMessage, UpdateEditChannelMessage)): - self.log.debug("Handling edit %s to %s by %s", update, portal.tgid_log, user) - return portal.handle_telegram_edit(self, sender, update) + if config["bridge.edits_as_replies"]: + self.log.debug("Handling edit %s to %s by %s", update, portal.tgid_log, user) + return portal.handle_telegram_edit(self, sender, update) + return self.log.debug("Handling message %s to %s by %s", update, portal.tgid_log, user) return portal.handle_telegram_message(self, sender, update) diff --git a/mautrix_telegram/portal.py b/mautrix_telegram/portal.py index 2bfe449b..858c3a9a 100644 --- a/mautrix_telegram/portal.py +++ b/mautrix_telegram/portal.py @@ -129,7 +129,6 @@ class Portal: }[type(event.media)](event.media) except KeyError: pass - return hashlib.md5("-" .join(str(a) for a in hash_content) .encode("utf-8") @@ -146,8 +145,8 @@ class Portal: self._dedup_action.popleft() return False - def is_duplicate(self, event, mxid=None): - hash = self._hash_event(event) if self.peer_type != "channel" else event.id + def is_duplicate(self, event, mxid=None, force_hash=False): + hash = self._hash_event(event) if self.peer_type != "channel" or force_hash else event.id if hash in self._dedup: return self._dedup_mxid[hash] @@ -850,7 +849,7 @@ class Portal: tg_space = self.tgid if self.peer_type == "channel" else source.tgid temporary_identifier = f"${random.randint(1000000000000,9999999999999)}TGBRIDGEDITEMP" - duplicate_found = self.is_duplicate(evt, (temporary_identifier, tg_space)) + duplicate_found = self.is_duplicate(evt, (temporary_identifier, tg_space), force_hash=True) if duplicate_found: mxid, other_tg_space = duplicate_found if tg_space != other_tg_space: