From 56ddaaee6f9986aad05ae5df5abc2c957a65d1c1 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sat, 16 Jun 2018 17:35:24 +0200 Subject: [PATCH] Make non-fwded messages sent to yourself outgoing --- telethon/events/newmessage.py | 8 ++++++++ telethon/tl/custom/message.py | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/telethon/events/newmessage.py b/telethon/events/newmessage.py index 8e2872ab..1b7e7b09 100644 --- a/telethon/events/newmessage.py +++ b/telethon/events/newmessage.py @@ -91,6 +91,14 @@ class NewMessage(EventBuilder): return event._entities = update._entities + + # Make messages sent to ourselves outgoing unless they're forwarded. + # This makes it consistent with official client's appearance. + ori = event.message + if isinstance(ori.to_id, types.PeerUser): + if ori.from_id == ori.to_id.user_id and not ori.fwd_from: + event.message.out = True + return self._message_filter_event(event) def _message_filter_event(self, event): diff --git a/telethon/tl/custom/message.py b/telethon/tl/custom/message.py index 352bf5d1..4fc7a753 100644 --- a/telethon/tl/custom/message.py +++ b/telethon/tl/custom/message.py @@ -401,6 +401,12 @@ class Message: """ Whether the message is outgoing (i.e. you sent it from another session) or incoming (i.e. someone else sent it). + + Note that messages in your own chat are always incoming, + but this property will be ``True`` if you send a message + to your own chat. Messages you forward to your chat are + *not* considered outgoing, just like official clients + display them. """ return self.original_message.out