Ignore channel-only permissions in megagroups (#1292)

This commit is contained in:
YouTwitFace 2019-10-11 12:04:41 -04:00 committed by Lonami
parent 09f27f0dd7
commit b862f215c5
2 changed files with 16 additions and 0 deletions

View File

@ -873,6 +873,19 @@ class ChatMethods:
)
if isinstance(entity, types.InputPeerChannel):
# If we try to set these permissions in a megagroup, we
# 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)
self._megagroup_cache[entity.channel_id] = full_entity.megagroup
if self._megagroup_cache[entity.channel_id]:
post_messages = None
edit_messages = None
perms = locals()
return await self(functions.channels.EditAdminRequest(entity, user, types.ChatAdminRights(**{
# A permission is its explicit (not-None) value or `is_admin`.

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