mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-07 15:34:52 +00:00
Merge branch 'develop' into asyncio
This commit is contained in:
commit
3f22d1b844
4 changed files with 47 additions and 39 deletions
|
|
@ -929,3 +929,12 @@ async def parse_chat_full(
|
||||||
parsed_chat.invite_link = full_chat.exported_invite.link
|
parsed_chat.invite_link = full_chat.exported_invite.link
|
||||||
|
|
||||||
return parsed_chat
|
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
|
# TODO docstrings
|
||||||
|
|
||||||
def get_dialogs(self,
|
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_date = 0
|
||||||
offset_id = 0
|
|
||||||
offset_peer = types.InputPeerEmpty()
|
|
||||||
|
|
||||||
if last_chunk:
|
if last_chunk:
|
||||||
for dialog in reversed(last_chunk.dialogs):
|
for dialog in reversed(last_chunk.dialogs):
|
||||||
|
|
@ -39,16 +41,14 @@ class GetDialogs(BaseClient):
|
||||||
message_date = top_message.date
|
message_date = top_message.date
|
||||||
|
|
||||||
if message_date:
|
if message_date:
|
||||||
offset_id = top_message.message_id
|
|
||||||
offset_date = message_date
|
offset_date = message_date
|
||||||
offset_peer = self.resolve_peer(dialog.id)
|
|
||||||
break
|
break
|
||||||
|
|
||||||
r = self.send(
|
r = self.send(
|
||||||
functions.messages.GetDialogs(
|
functions.messages.GetDialogs(
|
||||||
offset_date=offset_date,
|
offset_date=offset_date,
|
||||||
offset_id=offset_id,
|
offset_id=0,
|
||||||
offset_peer=offset_peer,
|
offset_peer=types.InputPeerEmpty(),
|
||||||
limit=limit,
|
limit=limit,
|
||||||
hash=0,
|
hash=0,
|
||||||
exclude_pinned=True
|
exclude_pinned=True
|
||||||
|
|
@ -60,20 +60,19 @@ class GetDialogs(BaseClient):
|
||||||
messages = {}
|
messages = {}
|
||||||
|
|
||||||
for message in r.messages:
|
for message in r.messages:
|
||||||
if isinstance(message, (types.Message, types.MessageService)):
|
to_id = message.to_id
|
||||||
chat_id = message.to_id
|
|
||||||
|
|
||||||
if isinstance(chat_id, types.PeerUser):
|
if isinstance(to_id, types.PeerUser):
|
||||||
chat_id = chat_id.user_id
|
if message.out:
|
||||||
elif isinstance(chat_id, types.PeerChat):
|
chat_id = to_id.user_id
|
||||||
chat_id = -chat_id.chat_id
|
|
||||||
else:
|
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(
|
messages[chat_id] = utils.parse_messages(self, message, users, chats)
|
||||||
self, message,
|
|
||||||
users, chats
|
|
||||||
)
|
|
||||||
|
|
||||||
dialogs = []
|
dialogs = []
|
||||||
|
|
||||||
|
|
@ -89,7 +88,7 @@ class GetDialogs(BaseClient):
|
||||||
|
|
||||||
dialogs.append(
|
dialogs.append(
|
||||||
pyrogram.Dialog(
|
pyrogram.Dialog(
|
||||||
id=chat_id,
|
chat=utils.parse_dialog_chat(dialog.peer, users, chats),
|
||||||
top_message=messages.get(chat_id),
|
top_message=messages.get(chat_id),
|
||||||
unread_messages_count=dialog.unread_count,
|
unread_messages_count=dialog.unread_count,
|
||||||
unread_mentions_count=dialog.unread_mentions_count,
|
unread_mentions_count=dialog.unread_mentions_count,
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ class GetMessages(BaseClient):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
On success and in case *message_ids* was a list, the returned value will be a list of the requested
|
On success and in case *message_ids* was a list, the returned value will be a list of the requested
|
||||||
:obj:`Messages <pyrogram.Message>` even if a list contains just one element, otherwise if
|
:obj:`Messages <pyrogram.Messages>` even if a list contains just one element, otherwise if
|
||||||
*message_ids* was an integer, the single requested :obj:`Message <pyrogram.Message>`
|
*message_ids* was an integer, the single requested :obj:`Message <pyrogram.Message>`
|
||||||
is returned.
|
is returned.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,13 +23,13 @@ class Dialog(Object):
|
||||||
ID = 0xb0700028
|
ID = 0xb0700028
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
id: int,
|
chat,
|
||||||
top_message,
|
top_message,
|
||||||
unread_messages_count: int,
|
unread_messages_count: int,
|
||||||
unread_mentions_count: int,
|
unread_mentions_count: int,
|
||||||
unread_mark: bool):
|
unread_mark: bool):
|
||||||
# TODO docstrings
|
# TODO docstrings
|
||||||
self.id = id
|
self.chat = chat
|
||||||
self.top_message = top_message
|
self.top_message = top_message
|
||||||
self.unread_messages_count = unread_messages_count
|
self.unread_messages_count = unread_messages_count
|
||||||
self.unread_mentions_count = unread_mentions_count
|
self.unread_mentions_count = unread_mentions_count
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue