Skip to content

Commit f8811d8

Browse files
Add some direct messages methods
- delete_direct_messages_chat_topic_history - set_direct_messages_chat_topic_is_marked_as_unread
1 parent 8dbd6c7 commit f8811d8

4 files changed

Lines changed: 146 additions & 0 deletions

File tree

compiler/docs/compiler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ def get_title_list(s: str) -> list:
283283
get_discussion_replies_count
284284
get_custom_emoji_stickers
285285
get_direct_messages_chat_topic_history
286+
delete_direct_messages_chat_topic_history
287+
set_direct_messages_chat_topic_is_marked_as_unread
286288
send_web_page
287289
start_bot
288290
delete_chat_history

pyrogram/methods/messages/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from .copy_media_group import CopyMediaGroup
2121
from .copy_message import CopyMessage
2222
from .delete_chat_history import DeleteChatHistory
23+
from .delete_direct_messages_chat_topic_history import DeleteDirectMessagesChatTopicHistory
2324
from .delete_messages import DeleteMessages
2425
from .download_media import DownloadMedia
2526
from .edit_inline_caption import EditInlineCaption
@@ -76,6 +77,7 @@
7677
from .send_video_note import SendVideoNote
7778
from .send_voice import SendVoice
7879
from .send_web_page import SendWebPage
80+
from .set_direct_messages_chat_topic_is_marked_as_unread import SetDirectMessagesChatTopicIsMarkedAsUnread
7981
from .start_bot import StartBot
8082
from .stop_poll import StopPoll
8183
from .stream_media import StreamMedia
@@ -118,6 +120,7 @@ class Messages(
118120
SendVoice,
119121
SendPoll,
120122
SendWebPage,
123+
SetDirectMessagesChatTopicIsMarkedAsUnread,
121124
ViewMessages,
122125
VotePoll,
123126
StartBot,
@@ -139,6 +142,7 @@ class Messages(
139142
SearchGlobal,
140143
CopyMessage,
141144
DeleteChatHistory,
145+
DeleteDirectMessagesChatTopicHistory,
142146
CopyMediaGroup,
143147
SearchMessagesCount,
144148
SearchPosts,
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-present Dan <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 datetime import datetime
20+
from typing import Union
21+
22+
import pyrogram
23+
from pyrogram import raw, utils
24+
25+
26+
class DeleteDirectMessagesChatTopicHistory:
27+
async def delete_direct_messages_chat_topic_history(
28+
self: "pyrogram.Client",
29+
chat_id: Union[int, str],
30+
topic_id: int = None,
31+
max_id: int = 0,
32+
min_date: datetime = None,
33+
max_date: datetime = None,
34+
) -> int:
35+
"""Delete messages in the topic in a channel direct messages chat administered by the current user.
36+
37+
.. include:: /_includes/usable-by/users.rst
38+
39+
Parameters:
40+
chat_id (``int`` | ``str``):
41+
Unique identifier (int) or username (str) of the target chat.
42+
43+
topic_id (``int``):
44+
Identifier of the topic which messages will be fetched.
45+
46+
max_id (``int``, *optional*):
47+
Maximum ID of message to delete.
48+
49+
min_date (:py:obj:`~datetime.datetime`, *optional*):
50+
Delete all messages newer than this time.
51+
52+
max_date (:py:obj:`~datetime.datetime`, *optional*):
53+
Delete all messages older than this time.
54+
55+
Returns:
56+
``int``: Amount of affected messages
57+
58+
Example:
59+
.. code-block:: python
60+
61+
# Delete all messages in topic
62+
await app.delete_direct_messages_chat_topic_history(chat_id, topic_id)
63+
"""
64+
r = await self.invoke(
65+
raw.functions.messages.DeleteSavedHistory(
66+
parent_peer=await self.resolve_peer(chat_id),
67+
peer=await self.resolve_peer(topic_id),
68+
max_id=max_id,
69+
min_date=utils.datetime_to_timestamp(min_date),
70+
max_date=utils.datetime_to_timestamp(max_date)
71+
)
72+
)
73+
74+
return r.pts_count
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-present Dan <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 datetime import datetime
20+
from typing import Union
21+
22+
import pyrogram
23+
from pyrogram import raw
24+
25+
26+
class SetDirectMessagesChatTopicIsMarkedAsUnread:
27+
async def set_direct_messages_chat_topic_is_marked_as_unread(
28+
self: "pyrogram.Client",
29+
chat_id: Union[int, str],
30+
topic_id: int = None,
31+
is_marked_as_unread: bool = True
32+
) -> int:
33+
"""Change the marked as unread state of the topic in a channel direct messages chat administered by the current user.
34+
35+
.. include:: /_includes/usable-by/users.rst
36+
37+
Parameters:
38+
chat_id (``int`` | ``str``):
39+
Unique identifier (int) or username (str) of the target chat.
40+
41+
topic_id (``int``):
42+
Identifier of the topic which messages will be fetched.
43+
44+
is_marked_as_unread (``bool``, *optional*):
45+
Pass True to mark the topic as unread.
46+
Pass False to mark the topic as read.
47+
Defaults to True.
48+
49+
Returns:
50+
``bool``: True on success
51+
52+
Example:
53+
.. code-block:: python
54+
55+
# Delete all messages in topic
56+
await app.set_direct_messages_chat_topic_is_marked_as_unread(chat_id, topic_id)
57+
"""
58+
r = await self.invoke(
59+
raw.functions.messages.MarkDialogUnread(
60+
parent_peer=await self.resolve_peer(chat_id),
61+
peer=await self.resolve_peer(topic_id),
62+
unread=is_marked_as_unread
63+
)
64+
)
65+
66+
return r

0 commit comments

Comments
 (0)