Refactor get_history method
This commit is contained in:
parent
7b90a0e7c5
commit
603bc88aa3
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram.api import functions
|
from pyrogram.api import functions
|
||||||
from ...ext import BaseClient, utils
|
from ...ext import BaseClient
|
||||||
|
|
||||||
|
|
||||||
class GetHistory(BaseClient):
|
class GetHistory(BaseClient):
|
||||||
@ -59,52 +59,18 @@ class GetHistory(BaseClient):
|
|||||||
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
|
:class:`Error <pyrogram.Error>` in case of a Telegram RPC error.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
r = self.send(
|
return pyrogram.Messages.parse(
|
||||||
functions.messages.GetHistory(
|
self,
|
||||||
peer=self.resolve_peer(chat_id),
|
self.send(
|
||||||
offset_id=offset_id,
|
functions.messages.GetHistory(
|
||||||
offset_date=offset_date,
|
peer=self.resolve_peer(chat_id),
|
||||||
add_offset=offset,
|
offset_id=offset_id,
|
||||||
limit=limit,
|
offset_date=offset_date,
|
||||||
max_id=0,
|
add_offset=offset,
|
||||||
min_id=0,
|
limit=limit,
|
||||||
hash=0
|
max_id=0,
|
||||||
|
min_id=0,
|
||||||
|
hash=0
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
users = {i.id: i for i in r.users}
|
|
||||||
chats = {i.id: i for i in r.chats}
|
|
||||||
|
|
||||||
reply_to_messages = {
|
|
||||||
i.reply_to_msg_id: None
|
|
||||||
for i in r.messages
|
|
||||||
if i.reply_to_msg_id
|
|
||||||
}
|
|
||||||
|
|
||||||
if reply_to_messages:
|
|
||||||
temp = self.get_messages(
|
|
||||||
chat_id, reply_to_messages,
|
|
||||||
replies=0
|
|
||||||
)
|
|
||||||
|
|
||||||
assert len(temp) == len(reply_to_messages)
|
|
||||||
|
|
||||||
for i in range(len(temp)):
|
|
||||||
reply_to_messages[temp[i].message_id] = temp[i]
|
|
||||||
|
|
||||||
messages = utils.parse_messages(
|
|
||||||
self, r.messages,
|
|
||||||
users, chats,
|
|
||||||
replies=0
|
|
||||||
)
|
|
||||||
|
|
||||||
assert len(messages) == len(r.messages)
|
|
||||||
|
|
||||||
for i in range(len(messages)):
|
|
||||||
if r.messages[i].reply_to_msg_id:
|
|
||||||
messages[i].reply_to_message = reply_to_messages[r.messages[i].reply_to_msg_id]
|
|
||||||
|
|
||||||
return pyrogram.Messages(
|
|
||||||
total_count=getattr(r, "count", len(r.messages)),
|
|
||||||
messages=messages
|
|
||||||
)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user