mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-06-20 12:06:37 +00: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,
|
min_id=min_id,
|
||||||
add_offset=add_offset))
|
add_offset=add_offset))
|
||||||
|
|
||||||
# The result may be a messages slice (not all messages were retrieved) or
|
# The result may be a messages slice (not all messages were retrieved)
|
||||||
# simply a messages TLObject. In the later case, no "count" attribute is specified:
|
# or simply a messages TLObject. In the later case, no "count"
|
||||||
# the total messages count is retrieved by counting all the retrieved messages
|
# attribute is specified, so the total messages count is simply
|
||||||
|
# the count of retrieved messages
|
||||||
total_messages = getattr(result, 'count', len(result.messages))
|
total_messages = getattr(result, 'count', len(result.messages))
|
||||||
|
|
||||||
# Iterate over all the messages and find the sender User
|
# Iterate over all the messages and find the sender User
|
||||||
users = []
|
entities = [find_user_or_chat(msg.from_id, result.users, result.chats)
|
||||||
for msg in result.messages:
|
for msg in result.messages]
|
||||||
for usr in result.users:
|
|
||||||
if msg.from_id == usr.id:
|
|
||||||
users.append(usr)
|
|
||||||
break
|
|
||||||
|
|
||||||
return total_messages, result.messages, users
|
return total_messages, result.messages, entities
|
||||||
|
|
||||||
def send_read_acknowledge(self, entity, messages=None, max_id=None):
|
def send_read_acknowledge(self, entity, messages=None, max_id=None):
|
||||||
"""Sends a "read acknowledge" (i.e., notifying the given peer that we've
|
"""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"""
|
Returns None if it was not found"""
|
||||||
try:
|
try:
|
||||||
if isinstance(peer, PeerUser):
|
if isinstance(peer, PeerUser):
|
||||||
user = next(u for u in users if u.id == peer.user_id)
|
return next(u for u in users if u.id == peer.user_id)
|
||||||
return user
|
|
||||||
|
|
||||||
elif isinstance(peer, PeerChat):
|
elif isinstance(peer, PeerChat):
|
||||||
chat = next(c for c in chats if c.id == peer.chat_id)
|
return next(c for c in chats if c.id == peer.chat_id)
|
||||||
return chat
|
|
||||||
|
|
||||||
elif isinstance(peer, PeerChannel):
|
elif isinstance(peer, PeerChannel):
|
||||||
channel = next(c for c in chats if c.id == peer.channel_id)
|
return next(c for c in chats if c.id == peer.channel_id)
|
||||||
return channel
|
|
||||||
|
|
||||||
except StopIteration:
|
except StopIteration: return
|
||||||
return None
|
|
||||||
|
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):
|
def get_appropriated_part_size(file_size):
|
||||||
|
Loading…
Reference in New Issue
Block a user