Skip to content

Commit a425e00

Browse files
committed
Add read_history method
1 parent 806e0d7 commit a425e00

3 files changed

Lines changed: 70 additions & 1 deletion

File tree

docs/source/api/methods.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Messages
6767
- :meth:`~Client.get_messages`
6868
- :meth:`~Client.get_history`
6969
- :meth:`~Client.get_history_count`
70+
- :meth:`~Client.read_history`
7071
- :meth:`~Client.iter_history`
7172
- :meth:`~Client.send_poll`
7273
- :meth:`~Client.vote_poll`
@@ -200,6 +201,7 @@ Details
200201
.. automethod:: Client.get_messages()
201202
.. automethod:: Client.get_history()
202203
.. automethod:: Client.get_history_count()
204+
.. automethod:: Client.read_history()
203205
.. automethod:: Client.iter_history()
204206
.. automethod:: Client.send_poll()
205207
.. automethod:: Client.vote_poll()

pyrogram/client/methods/messages/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from .get_history_count import GetHistoryCount
2828
from .get_messages import GetMessages
2929
from .iter_history import IterHistory
30+
from .read_history import ReadHistory
3031
from .retract_vote import RetractVote
3132
from .send_animated_sticker import SendAnimatedSticker
3233
from .send_animation import SendAnimation
@@ -80,6 +81,7 @@ class Messages(
8081
IterHistory,
8182
SendCachedMedia,
8283
GetHistoryCount,
83-
SendAnimatedSticker
84+
SendAnimatedSticker,
85+
ReadHistory
8486
):
8587
pass
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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
20+
21+
from pyrogram.api import functions, types
22+
from ...ext import BaseClient
23+
24+
25+
class ReadHistory(BaseClient):
26+
def read_history(
27+
self,
28+
chat_id: Union[int, str],
29+
max_id: int = 0
30+
) -> bool:
31+
"""Mark a chat's message history as read.
32+
33+
Parameters:
34+
chat_id (``int`` | ``str``):
35+
Unique identifier (int) or username (str) of the target chat.
36+
For your personal cloud (Saved Messages) you can simply use "me" or "self".
37+
For a contact that exists in your Telegram address book you can use his phone number (str).
38+
39+
max_id (``int``, *optional*):
40+
The id of the last message you want to mark as read; all the messages before this one will be marked as
41+
read as well. Defaults to 0 (mark every unread message as read).
42+
43+
Returns:
44+
``bool`` - On success, True is returned.
45+
46+
Raises:
47+
RPCError: In case of a Telegram RPC error.
48+
"""
49+
50+
peer = self.resolve_peer(chat_id)
51+
52+
if isinstance(peer, types.InputPeerChannel):
53+
q = functions.channels.ReadHistory(
54+
channel=peer,
55+
max_id=max_id
56+
)
57+
else:
58+
q = functions.messages.ReadHistory(
59+
peer=peer,
60+
max_id=max_id
61+
)
62+
63+
self.send(q)
64+
65+
return True

0 commit comments

Comments
 (0)