Add friendly methods for archiving dialogs

This commit is contained in:
Lonami Exo
2019-05-10 18:10:56 +02:00
parent 1828dca0b9
commit 313caf440e
5 changed files with 117 additions and 0 deletions

View File

@@ -17,6 +17,12 @@ class Dialog:
pinned (`bool`):
Whether this dialog is pinned to the top or not.
folder_id (`folder_id`):
The folder ID that this dialog belongs to.
archived (`bool`):
Whether this dialog is archived or not (``folder_id is None``).
message (`Message <telethon.tl.custom.message.Message>`):
The last message sent on this dialog. Note that this member
will not be updated when new messages arrive, it's only set
@@ -68,6 +74,8 @@ class Dialog:
self._client = client
self.dialog = dialog
self.pinned = bool(dialog.pinned)
self.folder_id = dialog.folder_id
self.archived = dialog.folder_id is not None
self.message = messages.get(dialog.top_message, None)
self.date = getattr(self.message, 'date', None)
@@ -111,6 +119,33 @@ class Dialog:
await self._client(functions.messages.DeleteHistoryRequest(
self.input_entity, 0))
async def archive(self, folder=1):
"""
Archives (or un-archives) this dialog.
Args:
folder (`int`, optional):
The folder to which the dialog should be archived to.
If you want to "un-archive" it, use ``folder=0``.
Returns:
The :tl:`Updates` object that the request produces.
Example:
.. code-block:: python
# Archiving
dialog.archive()
# Un-archiving
dialog.archive(0)
"""
return await self._client(functions.folders.EditPeerFoldersRequest([
types.InputFolderPeer(self.input_entity, folder_id=folder)
]))
def to_dict(self):
return {
'_': 'Dialog',