This repository was archived by the owner on Dec 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add method to set the History TTL #681
Open
ColinShark
wants to merge
6
commits into
pyrogram:master
Choose a base branch
from
ColinShark:history-ttl
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
31c5b91
Add method to set the History TTL
ColinShark bf58825
Addressing requested changes
ColinShark 6bc0329
Add bound method Chat.set_history_ttl()
ColinShark 583ffc7
Update set_chat_history_ttl.py
delivrance 8e64135
Update message.py
delivrance 72e656e
Update chat.py
delivrance File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Pyrogram - Telegram MTProto API Client Library for Python | ||
# Copyright (C) 2017-2021 Dan <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, Optional | ||
|
||
from pyrogram import raw | ||
from pyrogram import types | ||
from pyrogram.scaffold import Scaffold | ||
|
||
|
||
class SetChatHistoryTTL(Scaffold): | ||
async def set_chat_history_ttl( | ||
self, chat_id: Union[int, str], period: int | ||
) -> "types.Message": | ||
"""Set the time-to-live for the chat history. | ||
|
||
Parameters: | ||
chat_id (``int`` | ``str``): | ||
Unique identifier (int) or username (str) of the target chat. | ||
|
||
period (``int``): | ||
The time-to-live for the chat history. | ||
Either 86000 for 1 day, 604800 for 1 week or 0 (zero) to disable it. | ||
|
||
Returns: | ||
:obj:`~pyrogram.types.Message`: On success, the generated Service Message is returned. | ||
|
||
Example: | ||
.. code-block:: python | ||
|
||
# One Day | ||
app.set_chat_history_ttl(chat_id, 86400) | ||
|
||
# A Week | ||
app.set_chat_history_ttl(chat_id, 604800) | ||
|
||
# Disabling | ||
app.set_chat_history_ttl(chat_id, 0) | ||
""" | ||
|
||
r = await self.send( | ||
raw.functions.messages.SetHistoryTTL( | ||
peer=await self.resolve_peer(chat_id), | ||
period=period, | ||
) | ||
) | ||
|
||
for i in r.updates: | ||
if isinstance(i, (raw.types.UpdateNewMessage, | ||
raw.types.UpdateNewChannelMessage)): | ||
return await types.Message._parse( | ||
self, | ||
i.message, | ||
{i.id: i for i in r.users}, | ||
{i.id: i for i in r.chats}, | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading this made me think that maybe we should rename the whole thing to
set_chat_messages_ttl
or justset_chat_ttl
since the feature applies to new messages not to the whole history (or can be seen as a global chat setting regardless of messages or history). What do you think? There's also attl_period
field for messages (see the raw Message object) which I guess it will be set for all new messages when ttl is enabled.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So,
set_chat_ttl()
,Chat.set_ttl()
,Message.chat_ttl_period
.