Skip to content

Commit 5f3b7b9

Browse files
committed
Add archive_chats and unarchive_chats methods
1 parent 0075534 commit 5f3b7b9

4 files changed

Lines changed: 125 additions & 1 deletion

File tree

docs/source/api/methods.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ Chats
104104
- :meth:`~Client.get_dialogs_count`
105105
- :meth:`~Client.restrict_chat`
106106
- :meth:`~Client.update_chat_username`
107+
- :meth:`~Client.archive_chats`
108+
- :meth:`~Client.unarchive_chats`
107109

108110
Users
109111
^^^^^
@@ -233,6 +235,8 @@ Details
233235
.. automethod:: Client.get_dialogs_count()
234236
.. automethod:: Client.restrict_chat()
235237
.. automethod:: Client.update_chat_username()
238+
.. automethod:: Client.archive_chats()
239+
.. automethod:: Client.unarchive_chats()
236240

237241
.. Users
238242
.. automethod:: Client.get_me()

pyrogram/client/methods/chats/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19+
from .archive_chats import ArchiveChats
1920
from .delete_chat_photo import DeleteChatPhoto
2021
from .export_chat_invite_link import ExportChatInviteLink
2122
from .get_chat import GetChat
@@ -36,6 +37,7 @@
3637
from .set_chat_description import SetChatDescription
3738
from .set_chat_photo import SetChatPhoto
3839
from .set_chat_title import SetChatTitle
40+
from .unarchive_chats import UnarchiveChats
3941
from .unban_chat_member import UnbanChatMember
4042
from .unpin_chat_message import UnpinChatMessage
4143
from .update_chat_username import UpdateChatUsername
@@ -64,6 +66,8 @@ class Chats(
6466
IterChatMembers,
6567
UpdateChatUsername,
6668
RestrictChat,
67-
GetDialogsCount
69+
GetDialogsCount,
70+
ArchiveChats,
71+
UnarchiveChats
6872
):
6973
pass
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 typing import Union, List
20+
21+
from pyrogram.api import functions, types
22+
from ...ext import BaseClient
23+
24+
25+
class ArchiveChats(BaseClient):
26+
def archive_chats(
27+
self,
28+
chat_ids: Union[int, str, List[Union[int, str]]],
29+
) -> bool:
30+
"""Archive one or more chats.
31+
32+
Parameters:
33+
chat_ids (``int`` | ``str`` | List[``int``, ``str``]):
34+
Unique identifier (int) or username (str) of the target chat.
35+
You can also pass a list of ids (int) or usernames (str).
36+
37+
Returns:
38+
``bool``: On success, True is returned.
39+
40+
Raises:
41+
RPCError: In case of a Telegram RPC error.
42+
"""
43+
44+
if not isinstance(chat_ids, list):
45+
chat_ids = [chat_ids]
46+
47+
self.send(
48+
functions.folders.EditPeerFolders(
49+
folder_peers=[
50+
types.InputFolderPeer(
51+
peer=self.resolve_peer(chat),
52+
folder_id=1
53+
) for chat in chat_ids
54+
]
55+
)
56+
)
57+
58+
return True
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 typing import Union, List
20+
21+
from pyrogram.api import functions, types
22+
from ...ext import BaseClient
23+
24+
25+
class UnarchiveChats(BaseClient):
26+
def unarchive_chats(
27+
self,
28+
chat_ids: Union[int, str, List[Union[int, str]]],
29+
) -> bool:
30+
"""Unarchive one or more chats.
31+
32+
Parameters:
33+
chat_ids (``int`` | ``str`` | List[``int``, ``str``]):
34+
Unique identifier (int) or username (str) of the target chat.
35+
You can also pass a list of ids (int) or usernames (str).
36+
37+
Returns:
38+
``bool``: On success, True is returned.
39+
40+
Raises:
41+
RPCError: In case of a Telegram RPC error.
42+
"""
43+
44+
if not isinstance(chat_ids, list):
45+
chat_ids = [chat_ids]
46+
47+
self.send(
48+
functions.folders.EditPeerFolders(
49+
folder_peers=[
50+
types.InputFolderPeer(
51+
peer=self.resolve_peer(chat),
52+
folder_id=0
53+
) for chat in chat_ids
54+
]
55+
)
56+
)
57+
58+
return True

0 commit comments

Comments
 (0)