mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-08 04:52:30 +00:00
Add friendly methods for archiving dialogs
This commit is contained in:
@@ -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',
|
||||
|
Reference in New Issue
Block a user