mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 21:07:59 +00:00
Update get_dialogs
This commit is contained in:
parent
8b43ad8a63
commit
2b6c30d0e1
@ -917,3 +917,12 @@ def parse_chat_full(
|
||||
parsed_chat.invite_link = full_chat.exported_invite.link
|
||||
|
||||
return parsed_chat
|
||||
|
||||
|
||||
def parse_dialog_chat(peer, users: dict, chats: dict):
|
||||
if isinstance(peer, types.PeerUser):
|
||||
return parse_user_chat(users[peer.user_id])
|
||||
elif isinstance(peer, types.PeerChat):
|
||||
return parse_chat_chat(chats[peer.chat_id])
|
||||
else:
|
||||
return parse_channel_chat(chats[peer.channel_id])
|
||||
|
@ -25,11 +25,13 @@ class GetDialogs(BaseClient):
|
||||
# TODO docstrings
|
||||
|
||||
def get_dialogs(self,
|
||||
last_chunk=None,
|
||||
limit: int = 100):
|
||||
limit: int = 100,
|
||||
pinned_only: bool = False,
|
||||
last_chunk=None):
|
||||
if pinned_only:
|
||||
r = self.send(functions.messages.GetPinnedDialogs())
|
||||
else:
|
||||
offset_date = 0
|
||||
offset_id = 0
|
||||
offset_peer = types.InputPeerEmpty()
|
||||
|
||||
if last_chunk:
|
||||
for dialog in reversed(last_chunk.dialogs):
|
||||
@ -39,16 +41,14 @@ class GetDialogs(BaseClient):
|
||||
message_date = top_message.date
|
||||
|
||||
if message_date:
|
||||
offset_id = top_message.message_id
|
||||
offset_date = message_date
|
||||
offset_peer = self.resolve_peer(dialog.id)
|
||||
break
|
||||
|
||||
r = self.send(
|
||||
functions.messages.GetDialogs(
|
||||
offset_date=offset_date,
|
||||
offset_id=offset_id,
|
||||
offset_peer=offset_peer,
|
||||
offset_id=0,
|
||||
offset_peer=types.InputPeerEmpty(),
|
||||
limit=limit,
|
||||
hash=0,
|
||||
exclude_pinned=True
|
||||
@ -60,20 +60,19 @@ class GetDialogs(BaseClient):
|
||||
messages = {}
|
||||
|
||||
for message in r.messages:
|
||||
if isinstance(message, (types.Message, types.MessageService)):
|
||||
chat_id = message.to_id
|
||||
to_id = message.to_id
|
||||
|
||||
if isinstance(chat_id, types.PeerUser):
|
||||
chat_id = chat_id.user_id
|
||||
elif isinstance(chat_id, types.PeerChat):
|
||||
chat_id = -chat_id.chat_id
|
||||
if isinstance(to_id, types.PeerUser):
|
||||
if message.out:
|
||||
chat_id = to_id.user_id
|
||||
else:
|
||||
chat_id = int("-100" + str(chat_id.channel_id))
|
||||
chat_id = message.from_id
|
||||
elif isinstance(to_id, types.PeerChat):
|
||||
chat_id = -to_id.chat_id
|
||||
else:
|
||||
chat_id = int("-100" + str(to_id.channel_id))
|
||||
|
||||
messages[chat_id] = utils.parse_messages(
|
||||
self, message,
|
||||
users, chats
|
||||
)
|
||||
messages[chat_id] = utils.parse_messages(self, message, users, chats)
|
||||
|
||||
dialogs = []
|
||||
|
||||
@ -89,7 +88,7 @@ class GetDialogs(BaseClient):
|
||||
|
||||
dialogs.append(
|
||||
pyrogram.Dialog(
|
||||
id=chat_id,
|
||||
chat=utils.parse_dialog_chat(dialog.peer, users, chats),
|
||||
top_message=messages.get(chat_id),
|
||||
unread_messages_count=dialog.unread_count,
|
||||
unread_mentions_count=dialog.unread_mentions_count,
|
||||
|
@ -23,13 +23,13 @@ class Dialog(Object):
|
||||
ID = 0xb0700028
|
||||
|
||||
def __init__(self,
|
||||
id: int,
|
||||
chat,
|
||||
top_message,
|
||||
unread_messages_count: int,
|
||||
unread_mentions_count: int,
|
||||
unread_mark: bool):
|
||||
# TODO docstrings
|
||||
self.id = id
|
||||
self.chat = chat
|
||||
self.top_message = top_message
|
||||
self.unread_messages_count = unread_messages_count
|
||||
self.unread_mentions_count = unread_mentions_count
|
||||
|
Loading…
x
Reference in New Issue
Block a user