Cache if channels are a megagroup or not

This commit is contained in:
YouTwitFace 2019-10-11 12:02:59 -04:00
parent a9437db80c
commit d06f403a62
2 changed files with 9 additions and 2 deletions

View File

@ -877,8 +877,12 @@ class ChatMethods:
# would get a RIGHT_FORBIDDEN. However, it makes sense
# that an admin can post messages, so we want to avoid the error
if post_messages or edit_messages:
# TODO get rid of this once sessions cache this information
if entity.channel_id not in self._megagroup_cache:
full_entity = await self.get_entity(entity)
if full_entity.megagroup:
self._megagroup_cache[entity.channel_id] = full_entity.megagroup
if self._megagroup_cache[entity.channel_id]:
post_messages = None
edit_messages = None

View File

@ -340,6 +340,9 @@ class TelegramBaseClient(abc.ABC):
self._self_input_peer = None
self._bot = None
# A place to store if channels are a megagroup or not (see `edit_admin`)
self._megagroup_cache = {}
# endregion
# region Properties