Skip to content

Commit 4e77ead

Browse files
committed
Add get_dialogs_count method
1 parent e80eebc commit 4e77ead

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

docs/source/pyrogram/Client.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ Chats
101101
iter_chat_members
102102
get_dialogs
103103
iter_dialogs
104+
get_dialogs_count
104105
restrict_chat
105106
update_chat_username
106107

pyrogram/client/methods/chats/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from .unban_chat_member import UnbanChatMember
4040
from .unpin_chat_message import UnpinChatMessage
4141
from .update_chat_username import UpdateChatUsername
42+
from .get_dialogs_count import GetDialogsCount
4243

4344

4445
class Chats(
@@ -64,6 +65,7 @@ class Chats(
6465
IterDialogs,
6566
IterChatMembers,
6667
UpdateChatUsername,
67-
RestrictChat
68+
RestrictChat,
69+
GetDialogsCount
6870
):
6971
pass
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-2019 Dan Tès <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
from pyrogram.api import functions, types
20+
from ...ext import BaseClient
21+
22+
23+
class GetDialogsCount(BaseClient):
24+
def get_dialogs_count(self, pinned_only: bool = False) -> int:
25+
"""Use this method to get the total count of your dialogs.
26+
27+
pinned_only (``bool``, *optional*):
28+
Pass True if you want to count only pinned dialogs.
29+
Defaults to False.
30+
31+
Returns:
32+
On success, an integer is returned.
33+
34+
Raises:
35+
:class:`RPCError <pyrogram.RPCError>` in case of a Telegram RPC error.
36+
"""
37+
38+
if pinned_only:
39+
return len(self.send(functions.messages.GetPinnedDialogs()).dialogs)
40+
else:
41+
r = self.send(
42+
functions.messages.GetDialogs(
43+
offset_date=0,
44+
offset_id=0,
45+
offset_peer=types.InputPeerEmpty(),
46+
limit=1,
47+
hash=0
48+
)
49+
)
50+
51+
return r.count

0 commit comments

Comments
 (0)