2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-30 13:57:54 +00:00

Add get_history method

This commit is contained in:
Dan
2018-05-07 21:56:15 +02:00
parent f5521370bb
commit 5782fb4224

View File

@@ -3830,3 +3830,53 @@ class Client:
r = self.send(functions.messages.GetFullChat(peer.chat_id))
return utils.parse_chat_full(self, r)
def get_history(self,
chat_id: int or str,
offset: int,
limit: int,
offset_id: int = 0,
offset_date: int = 0,
max_id: int = 0,
min_id: int = 0):
# TODO: Documentation
r = self.send(
functions.messages.GetHistory(
peer=self.resolve_peer(chat_id),
offset_id=offset_id,
offset_date=offset_date,
add_offset=offset,
limit=limit,
max_id=max_id,
min_id=min_id,
hash=0
)
)
users = {i.id: i for i in r.users}
chats = {i.id: i for i in r.chats}
messages = []
for i in r.messages:
if isinstance(i, types.Message):
messages.append(
utils.parse_message(
self, i, users, chats
)
)
elif isinstance(i, types.MessageService):
messages.append(
utils.parse_message_service(
self, i, users, chats
)
)
else:
messages.append(
utils.parse_message_empty(
self, i
)
)
return messages