mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 17:36:34 +03:00
Fix get_message_history ignoring chats and enhance find_user_or_chat
This commit is contained in:
parent
96d8ca94cf
commit
fc915b2284
|
@ -440,20 +440,17 @@ class TelegramClient(TelegramBareClient):
|
|||
min_id=min_id,
|
||||
add_offset=add_offset))
|
||||
|
||||
# The result may be a messages slice (not all messages were retrieved) or
|
||||
# simply a messages TLObject. In the later case, no "count" attribute is specified:
|
||||
# the total messages count is retrieved by counting all the retrieved messages
|
||||
# The result may be a messages slice (not all messages were retrieved)
|
||||
# or simply a messages TLObject. In the later case, no "count"
|
||||
# attribute is specified, so the total messages count is simply
|
||||
# the count of retrieved messages
|
||||
total_messages = getattr(result, 'count', len(result.messages))
|
||||
|
||||
# Iterate over all the messages and find the sender User
|
||||
users = []
|
||||
for msg in result.messages:
|
||||
for usr in result.users:
|
||||
if msg.from_id == usr.id:
|
||||
users.append(usr)
|
||||
break
|
||||
entities = [find_user_or_chat(msg.from_id, result.users, result.chats)
|
||||
for msg in result.messages]
|
||||
|
||||
return total_messages, result.messages, users
|
||||
return total_messages, result.messages, entities
|
||||
|
||||
def send_read_acknowledge(self, entity, messages=None, max_id=None):
|
||||
"""Sends a "read acknowledge" (i.e., notifying the given peer that we've
|
||||
|
|
|
@ -67,19 +67,22 @@ def find_user_or_chat(peer, users, chats):
|
|||
Returns None if it was not found"""
|
||||
try:
|
||||
if isinstance(peer, PeerUser):
|
||||
user = next(u for u in users if u.id == peer.user_id)
|
||||
return user
|
||||
return next(u for u in users if u.id == peer.user_id)
|
||||
|
||||
elif isinstance(peer, PeerChat):
|
||||
chat = next(c for c in chats if c.id == peer.chat_id)
|
||||
return chat
|
||||
return next(c for c in chats if c.id == peer.chat_id)
|
||||
|
||||
elif isinstance(peer, PeerChannel):
|
||||
channel = next(c for c in chats if c.id == peer.channel_id)
|
||||
return channel
|
||||
return next(c for c in chats if c.id == peer.channel_id)
|
||||
|
||||
except StopIteration:
|
||||
return None
|
||||
except StopIteration: return
|
||||
|
||||
if isinstance(peer, int):
|
||||
try: return next(u for u in users if u.id == peer)
|
||||
except StopIteration: pass
|
||||
|
||||
try: return next(c for c in chats if c.id == peer)
|
||||
except StopIteration: pass
|
||||
|
||||
|
||||
def get_appropriated_part_size(file_size):
|
||||
|
|
Loading…
Reference in New Issue
Block a user