diff --git a/telethon/events/common.py b/telethon/events/common.py index 1eec6555..eeb24c0c 100644 --- a/telethon/events/common.py +++ b/telethon/events/common.py @@ -133,7 +133,7 @@ class EventCommon(ChatGetter, abc.ABC): """ _event_name = 'Event' - def __init__(self, chat_peer=None, msg_id=None, broadcast=False): + def __init__(self, chat_peer=None, msg_id=None, broadcast=None): super().__init__(chat_peer, broadcast=broadcast) self._entities = {} self._client = None diff --git a/telethon/tl/custom/chatgetter.py b/telethon/tl/custom/chatgetter.py index 82d07a0a..e919e17b 100644 --- a/telethon/tl/custom/chatgetter.py +++ b/telethon/tl/custom/chatgetter.py @@ -108,23 +108,39 @@ class ChatGetter(abc.ABC): @property def is_private(self): - """True if the message was sent as a private message.""" - return isinstance(self._chat_peer, types.PeerUser) + """ + ``True`` if the message was sent as a private message. + + Returns ``None`` if there isn't enough information + (e.g. on `events.MessageDeleted `). + """ + return isinstance(self._chat_peer, types.PeerUser) if self._chat_peer else None @property def is_group(self): - """True if the message was sent on a group or megagroup.""" - if self._broadcast is None and self.chat: - self._broadcast = getattr(self.chat, 'broadcast', None) + """ + True if the message was sent on a group or megagroup. - return ( - isinstance(self._chat_peer, (types.PeerChat, types.PeerChannel)) - and not self._broadcast - ) + Returns ``None`` if there isn't enough information + (e.g. on `events.MessageDeleted `). + """ + # TODO Cache could tell us more in the future + if self._broadcast is None and hasattr(self.chat, 'broadcast'): + self._broadcast = bool(self.chat.broadcast) + + if isinstance(self._chat_peer, types.PeerChannel): + if self._broadcast is None: + return None + else: + return not self._broadcast + + return isinstance(self._chat_peer, types.PeerChat) @property def is_channel(self): - """True if the message was sent on a megagroup or channel.""" + """``True`` if the message was sent on a megagroup or channel.""" + # The only case where chat peer could be none is in MessageDeleted, + # however those always have the peer in channels. return isinstance(self._chat_peer, types.PeerChannel) async def _refetch_chat(self):