Fix minified peers being erroneously stored because of server changes

This commit is contained in:
Dan 2019-09-14 19:37:28 +02:00
parent 840a9d1cc7
commit 6d0e2f7312

View File

@ -1162,41 +1162,24 @@ class Client(Methods, BaseClient):
self.parse_mode = parse_mode self.parse_mode = parse_mode
def fetch_peers( def fetch_peers(self, peers: List[Union[types.User, types.Chat, types.Channel]]) -> bool:
self,
peers: List[
Union[
types.User,
types.Chat, types.ChatForbidden,
types.Channel, types.ChannelForbidden
]
]
) -> bool:
is_min = False is_min = False
parsed_peers = [] parsed_peers = []
for peer in peers: for peer in peers:
if getattr(peer, "min", False):
is_min = True
continue
username = None username = None
phone_number = None phone_number = None
if isinstance(peer, types.User): if isinstance(peer, types.User):
peer_id = peer.id peer_id = peer.id
access_hash = peer.access_hash access_hash = peer.access_hash
username = (peer.username or "").lower() or None
username = peer.username
phone_number = peer.phone phone_number = peer.phone
peer_type = "bot" if peer.bot else "user"
if peer.bot:
peer_type = "bot"
else:
peer_type = "user"
if access_hash is None:
is_min = True
continue
if username is not None:
username = username.lower()
elif isinstance(peer, (types.Chat, types.ChatForbidden)): elif isinstance(peer, (types.Chat, types.ChatForbidden)):
peer_id = -peer.id peer_id = -peer.id
access_hash = 0 access_hash = 0
@ -1204,20 +1187,8 @@ class Client(Methods, BaseClient):
elif isinstance(peer, (types.Channel, types.ChannelForbidden)): elif isinstance(peer, (types.Channel, types.ChannelForbidden)):
peer_id = utils.get_channel_id(peer.id) peer_id = utils.get_channel_id(peer.id)
access_hash = peer.access_hash access_hash = peer.access_hash
username = (getattr(peer, "username", None) or "").lower() or None
username = getattr(peer, "username", None) peer_type = "channel" if peer.broadcast else "supergroup"
if peer.broadcast:
peer_type = "channel"
else:
peer_type = "supergroup"
if access_hash is None:
is_min = True
continue
if username is not None:
username = username.lower()
else: else:
continue continue