|
| 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