mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-28 12:57:52 +00:00
Add read_history method
This commit is contained in:
parent
806e0d79ec
commit
a425e00a96
@ -67,6 +67,7 @@ Messages
|
||||
- :meth:`~Client.get_messages`
|
||||
- :meth:`~Client.get_history`
|
||||
- :meth:`~Client.get_history_count`
|
||||
- :meth:`~Client.read_history`
|
||||
- :meth:`~Client.iter_history`
|
||||
- :meth:`~Client.send_poll`
|
||||
- :meth:`~Client.vote_poll`
|
||||
@ -200,6 +201,7 @@ Details
|
||||
.. automethod:: Client.get_messages()
|
||||
.. automethod:: Client.get_history()
|
||||
.. automethod:: Client.get_history_count()
|
||||
.. automethod:: Client.read_history()
|
||||
.. automethod:: Client.iter_history()
|
||||
.. automethod:: Client.send_poll()
|
||||
.. automethod:: Client.vote_poll()
|
||||
|
@ -27,6 +27,7 @@ from .get_history import GetHistory
|
||||
from .get_history_count import GetHistoryCount
|
||||
from .get_messages import GetMessages
|
||||
from .iter_history import IterHistory
|
||||
from .read_history import ReadHistory
|
||||
from .retract_vote import RetractVote
|
||||
from .send_animated_sticker import SendAnimatedSticker
|
||||
from .send_animation import SendAnimation
|
||||
@ -80,6 +81,7 @@ class Messages(
|
||||
IterHistory,
|
||||
SendCachedMedia,
|
||||
GetHistoryCount,
|
||||
SendAnimatedSticker
|
||||
SendAnimatedSticker,
|
||||
ReadHistory
|
||||
):
|
||||
pass
|
||||
|
65
pyrogram/client/methods/messages/read_history.py
Normal file
65
pyrogram/client/methods/messages/read_history.py
Normal file
@ -0,0 +1,65 @@
|
||||
# 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 Union
|
||||
|
||||
from pyrogram.api import functions, types
|
||||
from ...ext import BaseClient
|
||||
|
||||
|
||||
class ReadHistory(BaseClient):
|
||||
def read_history(
|
||||
self,
|
||||
chat_id: Union[int, str],
|
||||
max_id: int = 0
|
||||
) -> bool:
|
||||
"""Mark a chat's message history as read.
|
||||
|
||||
Parameters:
|
||||
chat_id (``int`` | ``str``):
|
||||
Unique identifier (int) or username (str) of the target chat.
|
||||
For your personal cloud (Saved Messages) you can simply use "me" or "self".
|
||||
For a contact that exists in your Telegram address book you can use his phone number (str).
|
||||
|
||||
max_id (``int``, *optional*):
|
||||
The id of the last message you want to mark as read; all the messages before this one will be marked as
|
||||
read as well. Defaults to 0 (mark every unread message as read).
|
||||
|
||||
Returns:
|
||||
``bool`` - On success, True is returned.
|
||||
|
||||
Raises:
|
||||
RPCError: In case of a Telegram RPC error.
|
||||
"""
|
||||
|
||||
peer = self.resolve_peer(chat_id)
|
||||
|
||||
if isinstance(peer, types.InputPeerChannel):
|
||||
q = functions.channels.ReadHistory(
|
||||
channel=peer,
|
||||
max_id=max_id
|
||||
)
|
||||
else:
|
||||
q = functions.messages.ReadHistory(
|
||||
peer=peer,
|
||||
max_id=max_id
|
||||
)
|
||||
|
||||
self.send(q)
|
||||
|
||||
return True
|
Loading…
x
Reference in New Issue
Block a user