From 95fad313c5b68d232648e971c9cbc4c4c0f0057e Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 18 Feb 2018 12:37:47 +0200 Subject: [PATCH] Deduplicate outgoing avatar/title changes --- mautrix_telegram/portal.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/mautrix_telegram/portal.py b/mautrix_telegram/portal.py index 75077dd7..2f515c25 100644 --- a/mautrix_telegram/portal.py +++ b/mautrix_telegram/portal.py @@ -603,10 +603,11 @@ class Portal: return if self.peer_type == "chat": - await sender.client(EditChatTitleRequest(chat_id=self.tgid, title=title)) + response = await sender.client(EditChatTitleRequest(chat_id=self.tgid, title=title)) else: channel = await self.get_input_entity(sender) - await sender.client(EditTitleRequest(channel=channel, title=title)) + response = await sender.client(EditTitleRequest(channel=channel, title=title)) + self._register_outgoing_actions_for_dedup(response) self.title = title self.save() @@ -622,11 +623,12 @@ class Portal: photo = InputChatUploadedPhoto(file=uploaded) if self.peer_type == "chat": - updates = await sender.client(EditChatPhotoRequest(chat_id=self.tgid, photo=photo)) + response = await sender.client(EditChatPhotoRequest(chat_id=self.tgid, photo=photo)) else: channel = await self.get_input_entity(sender) - updates = await sender.client(EditPhotoRequest(channel=channel, photo=photo)) - for update in updates.updates: + response = await sender.client(EditPhotoRequest(channel=channel, photo=photo)) + self._register_outgoing_actions_for_dedup(response) + for update in response.updates: is_photo_update = (isinstance(update, UpdateNewMessage) and isinstance(update.message, MessageService) and isinstance(update.message.action, MessageActionChatEditPhoto)) @@ -636,6 +638,13 @@ class Portal: self.save() break + def _register_outgoing_actions_for_dedup(self, response): + for update in response.updates: + check_dedup = (isinstance(update, (UpdateNewMessage, UpdateNewChannelMessage)) + and isinstance(update.message, MessageService)) + if check_dedup: + self.is_duplicate_action(update) + # endregion # region Telegram chat info updating