mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 13:27:47 +00:00
Remove Dialogs type
This commit is contained in:
parent
2db2ca3283
commit
c8fd446cb6
@ -32,7 +32,6 @@ Users & Chats
|
|||||||
- :class:`ChatMember`
|
- :class:`ChatMember`
|
||||||
- :class:`ChatPermissions`
|
- :class:`ChatPermissions`
|
||||||
- :class:`Dialog`
|
- :class:`Dialog`
|
||||||
- :class:`Dialogs`
|
|
||||||
|
|
||||||
Messages & Media
|
Messages & Media
|
||||||
^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^
|
||||||
@ -124,7 +123,6 @@ Details
|
|||||||
.. autoclass:: ChatMember()
|
.. autoclass:: ChatMember()
|
||||||
.. autoclass:: ChatPermissions()
|
.. autoclass:: ChatPermissions()
|
||||||
.. autoclass:: Dialog()
|
.. autoclass:: Dialog()
|
||||||
.. autoclass:: Dialogs()
|
|
||||||
|
|
||||||
.. Messages & Media
|
.. Messages & Media
|
||||||
.. autoclass:: Message()
|
.. autoclass:: Message()
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
from typing import List
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram.api import functions, types
|
from pyrogram.api import functions, types
|
||||||
@ -33,7 +34,7 @@ class GetDialogs(BaseClient):
|
|||||||
offset_date: int = 0,
|
offset_date: int = 0,
|
||||||
limit: int = 100,
|
limit: int = 100,
|
||||||
pinned_only: bool = False
|
pinned_only: bool = False
|
||||||
) -> "pyrogram.Dialogs":
|
) -> List["pyrogram.Dialog"]:
|
||||||
"""Get a chunk of the user's dialogs.
|
"""Get a chunk of the user's dialogs.
|
||||||
|
|
||||||
You can get up to 100 dialogs at once.
|
You can get up to 100 dialogs at once.
|
||||||
@ -53,7 +54,7 @@ class GetDialogs(BaseClient):
|
|||||||
Defaults to False.
|
Defaults to False.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
:obj:`Dialogs`: On success, an object containing a list of dialogs is returned.
|
List of :obj:`Dialog`: On success, a list of dialogs is returned.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
RPCError: In case of a Telegram RPC error.
|
RPCError: In case of a Telegram RPC error.
|
||||||
@ -80,4 +81,32 @@ class GetDialogs(BaseClient):
|
|||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
return pyrogram.Dialogs._parse(self, r)
|
users = {i.id: i for i in r.users}
|
||||||
|
chats = {i.id: i for i in r.chats}
|
||||||
|
|
||||||
|
messages = {}
|
||||||
|
|
||||||
|
for message in r.messages:
|
||||||
|
to_id = message.to_id
|
||||||
|
|
||||||
|
if isinstance(to_id, types.PeerUser):
|
||||||
|
if message.out:
|
||||||
|
chat_id = to_id.user_id
|
||||||
|
else:
|
||||||
|
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] = pyrogram.Message._parse(self, message, users, chats)
|
||||||
|
|
||||||
|
parsed_dialogs = []
|
||||||
|
|
||||||
|
for dialog in r.dialogs:
|
||||||
|
if not isinstance(dialog, types.Dialog):
|
||||||
|
continue
|
||||||
|
|
||||||
|
parsed_dialogs.append(pyrogram.Dialog._parse(self, dialog, messages, users, chats))
|
||||||
|
|
||||||
|
return pyrogram.List(parsed_dialogs)
|
||||||
|
@ -55,7 +55,7 @@ class IterDialogs(BaseClient):
|
|||||||
|
|
||||||
pinned_dialogs = self.get_dialogs(
|
pinned_dialogs = self.get_dialogs(
|
||||||
pinned_only=True
|
pinned_only=True
|
||||||
).dialogs
|
)
|
||||||
|
|
||||||
for dialog in pinned_dialogs:
|
for dialog in pinned_dialogs:
|
||||||
yield dialog
|
yield dialog
|
||||||
@ -69,7 +69,7 @@ class IterDialogs(BaseClient):
|
|||||||
dialogs = self.get_dialogs(
|
dialogs = self.get_dialogs(
|
||||||
offset_date=offset_date,
|
offset_date=offset_date,
|
||||||
limit=limit
|
limit=limit
|
||||||
).dialogs
|
)
|
||||||
|
|
||||||
if not dialogs:
|
if not dialogs:
|
||||||
return
|
return
|
||||||
|
@ -22,10 +22,9 @@ from .chat_permissions import ChatPermissions
|
|||||||
from .chat_photo import ChatPhoto
|
from .chat_photo import ChatPhoto
|
||||||
from .chat_preview import ChatPreview
|
from .chat_preview import ChatPreview
|
||||||
from .dialog import Dialog
|
from .dialog import Dialog
|
||||||
from .dialogs import Dialogs
|
|
||||||
from .user import User
|
from .user import User
|
||||||
from .user_status import UserStatus
|
from .user_status import UserStatus
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"Chat", "ChatMember", "ChatPermissions", "ChatPhoto", "ChatPreview", "Dialog", "Dialogs", "User", "UserStatus"
|
"Chat", "ChatMember", "ChatPermissions", "ChatPhoto", "ChatPreview", "Dialog", "User", "UserStatus"
|
||||||
]
|
]
|
||||||
|
@ -1,87 +0,0 @@
|
|||||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
|
||||||
# Copyright (C) 2017-2019 Dan Tès <https://github.com/delivrance>
|
|
||||||
#
|
|
||||||
# This file is part of Pyrogram.
|
|
||||||
#
|
|
||||||
# Pyrogram is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Lesser General Public License as published
|
|
||||||
# by the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Pyrogram is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU Lesser General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU Lesser General Public License
|
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
from typing import List
|
|
||||||
|
|
||||||
import pyrogram
|
|
||||||
from pyrogram.api import types
|
|
||||||
from .dialog import Dialog
|
|
||||||
from ..messages_and_media import Message
|
|
||||||
from ..object import Object
|
|
||||||
|
|
||||||
|
|
||||||
class Dialogs(Object):
|
|
||||||
"""Contains a user's dialogs chunk.
|
|
||||||
|
|
||||||
Parameters:
|
|
||||||
total_count (``int``):
|
|
||||||
Total number of dialogs the user has.
|
|
||||||
|
|
||||||
dialogs (List of :obj:`Dialog`):
|
|
||||||
Requested dialogs.
|
|
||||||
"""
|
|
||||||
|
|
||||||
__slots__ = ["total_count", "dialogs"]
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
*,
|
|
||||||
client: "pyrogram.BaseClient" = None,
|
|
||||||
total_count: int,
|
|
||||||
dialogs: List[Dialog]
|
|
||||||
):
|
|
||||||
super().__init__(client)
|
|
||||||
|
|
||||||
self.total_count = total_count
|
|
||||||
self.dialogs = dialogs
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _parse(client, dialogs: types.messages.Dialogs) -> "Dialogs":
|
|
||||||
users = {i.id: i for i in dialogs.users}
|
|
||||||
chats = {i.id: i for i in dialogs.chats}
|
|
||||||
|
|
||||||
messages = {}
|
|
||||||
|
|
||||||
for message in dialogs.messages:
|
|
||||||
to_id = message.to_id
|
|
||||||
|
|
||||||
if isinstance(to_id, types.PeerUser):
|
|
||||||
if message.out:
|
|
||||||
chat_id = to_id.user_id
|
|
||||||
else:
|
|
||||||
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] = Message._parse(client, message, users, chats)
|
|
||||||
|
|
||||||
parsed_dialogs = []
|
|
||||||
|
|
||||||
for dialog in dialogs.dialogs:
|
|
||||||
if not isinstance(dialog, types.Dialog):
|
|
||||||
continue
|
|
||||||
|
|
||||||
parsed_dialogs.append(Dialog._parse(client, dialog, messages, users, chats))
|
|
||||||
|
|
||||||
return Dialogs(
|
|
||||||
total_count=getattr(dialogs, "count", len(dialogs.dialogs)),
|
|
||||||
dialogs=parsed_dialogs,
|
|
||||||
client=client
|
|
||||||
)
|
|
Loading…
x
Reference in New Issue
Block a user