From 1a1d9d346c542ed193658c6cdf17ab0d123ef375 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Fri, 22 Jun 2018 10:21:32 +0200 Subject: [PATCH] Fix most private messages being outgoing since 56ddaae 56ddaae checked to_id and from_id to compare if they were equal, and if they were, mark the event as outgoing for convenience in your private chat (saved messages). However when reconstructing the Message from UpdateShortMessage to_id didn't mimic 100% Telegram's behaviour (the chat to which the message is sent is "different" depending on who sent the messages). This bug is what actually caused most messages to be outgoing, even though 56ddaae's logic is correct. --- telethon/events/newmessage.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/telethon/events/newmessage.py b/telethon/events/newmessage.py index 30b4ef30..a43febd5 100644 --- a/telethon/events/newmessage.py +++ b/telethon/events/newmessage.py @@ -88,7 +88,11 @@ class NewMessage(EventBuilder): media_unread=update.media_unread, silent=update.silent, id=update.id, - to_id=types.PeerUser(update.user_id), + # Note that to_id/from_id complement each other in private + # messages, depending on whether the message was outgoing. + to_id=types.PeerUser( + update.user_id if update.out else self._self_id + ), from_id=self._self_id if update.out else update.user_id, message=update.message, date=update.date,