diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 07809c63..2e8b0421 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -230,6 +230,9 @@ def pyrogram_api(): set_administrator_title set_chat_photo delete_chat_photo + delete_folder + export_folder_link + update_folder set_chat_title set_chat_description set_chat_permissions @@ -242,6 +245,7 @@ def pyrogram_api(): get_chat_members_count get_dialogs get_dialogs_count + get_folders get_forum_topics get_forum_topics_by_id set_chat_username @@ -273,6 +277,7 @@ def pyrogram_api(): reopen_general_topic unhide_general_topic update_color + update_folder """, users=""" Users @@ -455,6 +460,7 @@ def pyrogram_api(): ChatJoinedByRequest ChatJoiner Dialog + Folder Restriction EmojiStatus ForumTopic diff --git a/docs/source/api/enums/index.rst b/docs/source/api/enums/index.rst index 03a61bfd..7eb92c3b 100644 --- a/docs/source/api/enums/index.rst +++ b/docs/source/api/enums/index.rst @@ -19,6 +19,7 @@ to apply only a valid value among the expected ones. ChatMemberStatus ChatMembersFilter ChatType + FolderColor ListenerTypes MessageEntityType MessageMediaType @@ -41,6 +42,7 @@ to apply only a valid value among the expected ones. ChatMemberStatus ChatMembersFilter ChatType + FolderColor ListenerTypes MessageEntityType MessageMediaType diff --git a/pyrogram/enums/__init__.py b/pyrogram/enums/__init__.py index d066a0d0..6b149413 100644 --- a/pyrogram/enums/__init__.py +++ b/pyrogram/enums/__init__.py @@ -24,6 +24,7 @@ from .chat_member_status import ChatMemberStatus from .chat_members_filter import ChatMembersFilter from .chat_type import ChatType from .client_platform import ClientPlatform +from .folder_color import FolderColor from .listerner_types import ListenerTypes from .message_entity_type import MessageEntityType from .message_media_type import MessageMediaType @@ -47,7 +48,8 @@ __all__ = [ 'ChatMemberStatus', 'ChatMembersFilter', 'ChatType', - 'ClientPlatform', + 'ClientPlatform', + 'FolderColor', 'ListenerTypes', 'MessageEntityType', 'MessageMediaType', diff --git a/pyrogram/enums/folder_color.py b/pyrogram/enums/folder_color.py new file mode 100644 index 00000000..980c4a3b --- /dev/null +++ b/pyrogram/enums/folder_color.py @@ -0,0 +1,47 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# 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 . + +from .auto_name import AutoName + + +class FolderColor(AutoName): + """Folder color enumeration used in :obj:`~pyrogram.types.Folder`.""" + + NO_COLOR = None + "No color." + + RED = 0 + "Red color." + + ORANGE = 1 + "Orange color." + + VIOLET = 2 + "Violet color." + + GREEN = 3 + "Green color." + + CYAN = 4 + "Cyan color." + + BLUE = 5 + "Blue color." + + PINK = 6 + "Pink color." diff --git a/pyrogram/methods/chats/__init__.py b/pyrogram/methods/chats/__init__.py index a0619862..8788aea9 100644 --- a/pyrogram/methods/chats/__init__.py +++ b/pyrogram/methods/chats/__init__.py @@ -28,11 +28,13 @@ from .close_forum_topic import CloseForumTopic from .close_general_topic import CloseGeneralTopic from .delete_channel import DeleteChannel from .delete_chat_photo import DeleteChatPhoto +from .delete_folder import DeleteFolder from .delete_forum_topic import DeleteForumTopic from .delete_supergroup import DeleteSupergroup from .delete_user_history import DeleteUserHistory from .edit_forum_topic import EditForumTopic from .edit_general_topic import EditGeneralTopic +from .export_folder_link import ExportFolderLink from .reopen_forum_topic import ReopenForumTopic from .reopen_general_topic import ReopenGeneralTopic from .hide_general_topic import HideGeneralTopic @@ -45,6 +47,7 @@ from .get_chat_members_count import GetChatMembersCount from .get_chat_online_count import GetChatOnlineCount from .get_dialogs import GetDialogs from .get_dialogs_count import GetDialogsCount +from .get_folders import GetFolders from .get_forum_topics import GetForumTopics from .get_forum_topics_by_id import GetForumTopicsByID from .get_nearby_chats import GetNearbyChats @@ -69,6 +72,7 @@ from .unban_chat_member import UnbanChatMember from .unpin_all_chat_messages import UnpinAllChatMessages from .unpin_chat_message import UnpinChatMessage from .update_color import UpdateColor +from .update_folder import UpdateFolder class Chats( @@ -92,6 +96,7 @@ class Chats( SetChatUsername, SetChatPermissions, GetDialogsCount, + GetFolders, GetForumTopics, GetForumTopicsByID, ArchiveChats, @@ -104,10 +109,12 @@ class Chats( CloseGeneralTopic, AddChatMembers, DeleteChannel, + DeleteFolder, DeleteForumTopic, DeleteSupergroup, EditForumTopic, EditGeneralTopic, + ExportFolderLink, ReopenForumTopic, ReopenGeneralTopic, HideGeneralTopic, @@ -123,6 +130,7 @@ class Chats( GetSendAsChats, SetSendAsChat, SetChatProtectedContent, - UpdateColor + UpdateColor, + UpdateFolder ): pass diff --git a/pyrogram/methods/chats/delete_folder.py b/pyrogram/methods/chats/delete_folder.py new file mode 100644 index 00000000..1f08e3c3 --- /dev/null +++ b/pyrogram/methods/chats/delete_folder.py @@ -0,0 +1,52 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# Copyright (C) 2022-present Mayuri-Chan +# +# This file is part of Pyrofork. +# +# Pyrofork 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. +# +# Pyrofork 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 Pyrofork. If not, see . + +import pyrogram +from pyrogram import raw + + +class DeleteFolder: + async def delete_folder( + self: "pyrogram.Client", + folder_id: int + ) -> bool: + """Delete a user's folder. + + .. include:: /_includes/usable-by/users.rst + + Parameters: + folder_id (``int``): + Unique identifier (int) of the target folder. + + Returns: + ``bool``: True, on success. + + Example: + .. code-block:: python + + # Delete folder + app.delete_folder(folder_id) + """ + r = await self.invoke( + raw.functions.messages.UpdateDialogFilter( + id=folder_id + ) + ) + + return r diff --git a/pyrogram/methods/chats/export_folder_link.py b/pyrogram/methods/chats/export_folder_link.py new file mode 100644 index 00000000..17141734 --- /dev/null +++ b/pyrogram/methods/chats/export_folder_link.py @@ -0,0 +1,70 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# Copyright (C) 2022-present Mayuri-Chan +# +# This file is part of Pyrofork. +# +# Pyrofork 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. +# +# Pyrofork 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 Pyrofork. If not, see . + +import pyrogram +from pyrogram import raw + + +class ExportFolderLink: + async def export_folder_link( + self: "pyrogram.Client", + folder_id: int + ) -> str: + """Export link to a user's folder. + + .. include:: /_includes/usable-by/users.rst + + Parameters: + folder_id (``int``): + Unique identifier (int) of the target folder. + + Returns: + ``str``: On success, a link to the folder as string is returned. + + Example: + .. code-block:: python + + # Export folder link + app.export_folder_link(folder_id) + """ + folder = await self.get_folders(folder_id) + + if not folder: + return + + peers = [] + + if folder.included_chats: + peers.extend(iter(folder.included_chats)) + + if folder.excluded_chats: + peers.extend(iter(folder.included_chats)) + + if folder.pinned_chats: + peers.extend(iter(folder.included_chats)) + + r = await self.invoke( + raw.functions.chatlists.ExportChatlistInvite( + chatlist=raw.types.InputChatlistDialogFilter(filter_id=folder_id), + title=folder.title, + peers=[await self.resolve_peer(i.id) for i in peers], + ) + ) + + return r.invite.url diff --git a/pyrogram/methods/chats/get_folders.py b/pyrogram/methods/chats/get_folders.py new file mode 100644 index 00000000..cadfec50 --- /dev/null +++ b/pyrogram/methods/chats/get_folders.py @@ -0,0 +1,98 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# Copyright (C) 2022-present Mayuri-Chan +# +# This file is part of Pyrofork. +# +# Pyrofork 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. +# +# Pyrofork 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 Pyrofork. If not, see . + +from typing import Union, List, Iterable + +import pyrogram +from pyrogram import types, raw, utils + + +class GetFolders: + async def get_folders( + self: "pyrogram.Client", + folder_ids: Union[int, Iterable[int]] = None + ) -> Union["types.Folder", List["types.Folder"]]: + """Get one or more folders by using folder identifiers. + + .. include:: /_includes/usable-by/users.rst + + Parameters: + folder_ids (``int`` | Iterable of ``int``, *optional*): + Pass a single folder identifier or an iterable of folder ids (as integers) to get the content of the + folders themselves. + By default all folders are returned. + + Returns: + :obj:`~pyrogram.types.Folder` | List of :obj:`~pyrogram.types.Folder`: In case *folder_ids* was not + a list, a single folder is returned, otherwise a list of folders is returned. + + Example: + .. code-block:: python + + # Get one folder + await app.get_folders(12345) + + # Get more than one folders (list of folders) + await app.get_folders([12345, 12346]) + + # Get all folders + await app.get_folders() + """ + is_iterable = hasattr(folder_ids, "__iter__") + ids = set(folder_ids) if is_iterable else {folder_ids} + + dialog_filters = await self.invoke(raw.functions.messages.GetDialogFilters()) + + raw_folders = [ + folder for folder in dialog_filters.filters + if not isinstance(folder, raw.types.DialogFilterDefault) and (is_iterable and folder.id in ids or not is_iterable) + ] + + raw_peers = {} + for folder in raw_folders: + for peer in folder.pinned_peers + folder.include_peers + getattr(folder, "exclude_peers", []): + raw_peers[utils.get_peer_id(peer)] = peer + + users = {} + chats = {} + for i in range(0, len(raw_peers), 100): + chunk = list(raw_peers.values())[i:i + 100] + r = await self.invoke( + raw.functions.messages.GetPeerDialogs( + peers=[raw.types.InputDialogPeer(peer=peer) for peer in chunk] + ) + ) + users.update({i.id: i for i in r.users}) + chats.update({i.id: i for i in r.chats}) + + folders = types.List(types.Folder._parse(self, folder, users, chats) for folder in raw_folders) + + if not folders: + return None + + if folder_ids: + if is_iterable: + return folders + else: + for folder in folders: + if folder.id == folder_ids: + return folder + return None + + return folders diff --git a/pyrogram/methods/chats/update_folder.py b/pyrogram/methods/chats/update_folder.py new file mode 100644 index 00000000..a641fb99 --- /dev/null +++ b/pyrogram/methods/chats/update_folder.py @@ -0,0 +1,149 @@ +# Pyrofork - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# Copyright (C) 2022-present Mayuri-Chan +# +# This file is part of Pyrofork. +# +# Pyrofork 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. +# +# Pyrofork 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 Pyrofork. If not, see . + +from typing import List, Union + +import pyrogram +from pyrogram import raw +from pyrogram import enums + + +class UpdateFolder: + async def update_folder( + self: "pyrogram.Client", + folder_id: int, + title: str, + included_chats: Union[Union[int, str], List[Union[int, str]]] = None, + excluded_chats: Union[Union[int, str], List[Union[int, str]]] = None, + pinned_chats: Union[Union[int, str], List[Union[int, str]]] = None, + contacts: bool = None, + non_contacts: bool = None, + groups: bool = None, + channels: bool = None, + bots: bool = None, + exclude_muted: bool = None, + exclude_read: bool = None, + exclude_archived: bool = None, + color: "enums.FolderColor" = None, + emoji: str = None + ) -> bool: + """Create or update a user's folder. + + .. include:: /_includes/usable-by/users.rst + + Parameters: + folder_id (``int``): + Unique folder identifier. + + title (``str``): + Folder title. + + included_chats (``int`` | ``str`` | List of ``int`` or ``str``, *optional*): + Users or chats that should added in the folder + You can pass an ID (int), username (str) or phone number (str). + Multiple users can be added by passing a list of IDs, usernames or phone numbers. + + excluded_chats (``int`` | ``str`` | List of ``int`` or ``str``, *optional*): + Users or chats that should excluded from the folder + You can pass an ID (int), username (str) or phone number (str). + Multiple users can be added by passing a list of IDs, usernames or phone numbers. + + pinned_chats (``int`` | ``str`` | List of ``int`` or ``str``, *optional*): + Users or chats that should pinned in the folder + You can pass an ID (int), username (str) or phone number (str). + Multiple users can be added by passing a list of IDs, usernames or phone numbers. + + contacts (``bool``, *optional*): + Pass True if folder should contain contacts. + + non_contacts (``bool``, *optional*): + Pass True if folder should contain non contacts. + + groups (``bool``, *optional*): + Pass True if folder should contain groups. + + channels (``bool``, *optional*): + Pass True if folder should contain channels. + + bots (``bool``, *optional*): + Pass True if folder should contain bots. + + exclude_muted (``bool``, *optional*): + Pass True if folder should exclude muted users. + + exclude_archived (``bool``, *optional*): + Pass True if folder should exclude archived users. + + emoji (``str``, *optional*): + Folder emoji. + Pass None to leave the folder icon as default. + + color (:obj:`~pyrogram.enums.FolderColor`, *optional*): + Color type. + Pass :obj:`~pyrogram.enums.FolderColor` to set folder color. + + Returns: + ``bool``: True, on success. + + Example: + .. code-block:: python + + # Create or update folder + app.update_folder(folder_id, title="New folder", included_chats="me") + """ + if not isinstance(included_chats, list): + included_chats = [included_chats] if included_chats else [] + if not isinstance(excluded_chats, list): + excluded_chats = [excluded_chats] if excluded_chats else [] + if not isinstance(pinned_chats, list): + pinned_chats = [pinned_chats] if pinned_chats else [] + + r = await self.invoke( + raw.functions.messages.UpdateDialogFilter( + id=folder_id, + filter=raw.types.DialogFilter( + id=folder_id, + title=title, + pinned_peers=[ + await self.resolve_peer(user_id) + for user_id in pinned_chats + ], + include_peers=[ + await self.resolve_peer(user_id) + for user_id in included_chats + ], + exclude_peers=[ + await self.resolve_peer(user_id) + for user_id in excluded_chats + ], + contacts=contacts, + non_contacts=non_contacts, + groups=groups, + broadcasts=channels, + bots=bots, + exclude_muted=exclude_muted, + exclude_read=exclude_read, + exclude_archived=exclude_archived, + emoticon=emoji, + color=color.value if color else None + ) + ) + ) + + return r diff --git a/pyrogram/types/user_and_chats/folder.py b/pyrogram/types/user_and_chats/folder.py new file mode 100644 index 00000000..85f9bec6 --- /dev/null +++ b/pyrogram/types/user_and_chats/folder.py @@ -0,0 +1,490 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# Copyright (C) 2022-present Mayuri-Chan +# +# 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 . + +from typing import List, Union + +import pyrogram +from pyrogram import enums +from pyrogram import raw +from pyrogram import types +from pyrogram import utils +from ..object import Object + + +class Folder(Object): + """A user's folder. + + Parameters: + id (``int``): + The folder id. + + title (``str``): + The folder title. + + included_chats (List of :obj:`~pyrogram.types.Chat`, *optional*): + A list of included chats in folder. + + excluded_chats (List of :obj:`~pyrogram.types.Chat`, *optional*): + A list of excluded chats in folder. + + pinned_chats (List of :obj:`~pyrogram.types.Chat`, *optional*): + A list of pinned chats in folder. + + contacts (``bool``, *optional*): + True, if the folder includes contacts. + + non_contacts (``bool``, *optional*): + True, if the folder includes non contacts. + + groups (``bool``, *optional*): + True, if the folder includes groups. + + channels (``bool``, *optional*): + True, if the folder includes channels. + + bots (``bool``, *optional*): + True, if the folder includes bots. + + exclude_muted (``bool``, *optional*): + True, if the folder exclude muted. + + exclude_read (``bool``, *optional*): + True, if the folder exclude read. + + exclude_archived (``bool``, *optional*): + True, if the folder exclude archived. + + emoji (``str``, *optional*): + Folder emoji. + + color (:obj:`~pyrogram.enums.FolderColor`, *optional*) + Chat reply color. + """ + + def __init__( + self, + *, + client: "pyrogram.Client" = None, + id: int, + title: str, + included_chats: List["types.Chat"] = None, + excluded_chats: List["types.Chat"] = None, + pinned_chats: List["types.Chat"] = None, + contacts: bool = None, + non_contacts: bool = None, + groups: bool = None, + channels: bool = None, + bots: bool = None, + exclude_muted: bool = None, + exclude_read: bool = None, + exclude_archived: bool = None, + emoji: str = None, + color: "enums.FolderColor" = None, + has_my_invites: bool = None + ): + super().__init__(client) + + self.id = id + self.title = title + self.included_chats = included_chats + self.excluded_chats = excluded_chats + self.pinned_chats = pinned_chats + self.contacts = contacts + self.non_contacts = non_contacts + self.groups = groups + self.channels = channels + self.bots = bots + self.exclude_muted = exclude_muted + self.exclude_read = exclude_read + self.exclude_archived = exclude_archived + self.emoji = emoji + self.color = color + self.has_my_invites = has_my_invites + + @staticmethod + def _parse(client, folder: "raw.types.DialogFilter", users, chats) -> "Folder": + included_chats = [] + excluded_chats = [] + pinned_chats = [] + + for peer in folder.include_peers: + try: + included_chats.append(types.Chat._parse_dialog(client, peer, users, chats)) + except KeyError: + pass + + if getattr(folder, "exclude_peers", None): + for peer in folder.exclude_peers: + try: + excluded_chats.append(types.Chat._parse_dialog(client, peer, users, chats)) + except KeyError: + pass + + for peer in folder.pinned_peers: + try: + pinned_chats.append(types.Chat._parse_dialog(client, peer, users, chats)) + except KeyError: + pass + + return Folder( + id=folder.id, + title=folder.title, + included_chats=types.List(included_chats) or None, + excluded_chats=types.List(excluded_chats) or None, + pinned_chats=types.List(pinned_chats) or None, + contacts=getattr(folder, "contacts", None), + non_contacts=getattr(folder, "non_contacts", None), + groups=getattr(folder, "groups", None), + channels=getattr(folder, "broadcasts", None), + bots=getattr(folder, "bots", None), + exclude_muted=getattr(folder, "exclude_muted", None), + exclude_read=getattr(folder, "exclude_read", None), + exclude_archived=getattr(folder, "exclude_archived", None), + emoji=folder.emoticon or None, + color=enums.FolderColor(getattr(folder, "color", None)), + has_my_invites=getattr(folder, "has_my_invites", None), + client=client + ) + + async def delete(self): + """Bound method *delete* of :obj:`~pyrogram.types.Folder`. + + Use as a shortcut for: + + .. code-block:: python + + await client.delete_folder(123456789) + + Example: + .. code-block:: python + + await folder.delete() + + Returns: + True on success. + """ + + return await self._client.delete_folder(self.id) + + async def update( + self, + included_chats: List[Union[int, str]] = None, + excluded_chats: List[Union[int, str]] = None, + pinned_chats: List[Union[int, str]] = None, + title: str = None, + contacts: bool = None, + non_contacts: bool = None, + groups: bool = None, + channels: bool = None, + bots: bool = None, + exclude_muted: bool = None, + exclude_read: bool = None, + exclude_archived: bool = None, + emoji: str = None, + color: "enums.FolderColor" = None + ): + """Bound method *update_peers* of :obj:`~pyrogram.types.Folder`. + + Use as a shortcut for: + + .. code-block:: python + + await client.update_folder( + folder_id, + title="New folder", + included_chats=["me"] + ) + + Example: + .. code-block:: python + + await folder.update(included_chats=["me"]) + + Parameters: + included_chats (``int`` | ``str`` | List of ``int`` or ``str``, *optional*): + Users or chats that should added in the folder + You can pass an ID (int), username (str) or phone number (str). + Multiple users can be added by passing a list of IDs, usernames or phone numbers. + + excluded_chats (``int`` | ``str`` | List of ``int`` or ``str``, *optional*): + Users or chats that should excluded from the folder + You can pass an ID (int), username (str) or phone number (str). + Multiple users can be added by passing a list of IDs, usernames or phone numbers. + + pinned_chats (``int`` | ``str`` | List of ``int`` or ``str``, *optional*): + Users or chats that should pinned in the folder + You can pass an ID (int), username (str) or phone number (str). + Multiple users can be added by passing a list of IDs, usernames or phone numbers. + + title (``str``, *optional*): + A folder title was changed to this value. + + contacts (``bool``, *optional*): + Pass True if folder should contain contacts. + + non_contacts (``bool``, *optional*): + Pass True if folder should contain non contacts. + + groups (``bool``, *optional*): + Pass True if folder should contain groups. + + channels (``bool``, *optional*): + Pass True if folder should contain channels. + + bots (``bool``, *optional*): + Pass True if folder should contain bots. + + exclude_muted (``bool``, *optional*): + Pass True if folder should exclude muted users. + + exclude_archived (``bool``, *optional*): + Pass True if folder should exclude archived users. + + emoji (``str``, *optional*): + Folder emoji. + Pass None to leave the folder icon as default. + + color (:obj:`~pyrogram.enums.FolderColor`, *optional*): + Color type. + Pass :obj:`~pyrogram.enums.FolderColor` to set folder color. + + Returns: + True on success. + """ + if not included_chats: + included_chats = [i.id for i in self.included_chats or []] + + if not included_chats: + excluded_chats = [i.id for i in self.excluded_chats or []] + + if not included_chats: + pinned_chats = [i.id for i in self.pinned_chats or []] + + return await self._client.update_folder( + folder_id=self.id, + title=title or self.title, + included_chats=included_chats, + excluded_chats=excluded_chats, + pinned_chats=pinned_chats, + contacts=contacts or self.contacts, + non_contacts=non_contacts or self.non_contacts, + groups=groups or self.groups, + channels=channels or self.channels, + bots=bots or self.bots, + exclude_muted=exclude_muted or self.exclude_muted, + exclude_read=exclude_read or self.exclude_read, + exclude_archived=exclude_archived or self.exclude_archived, + emoji=emoji or self.emoji, + color=color or self.color + ) + + async def include_chat(self, chat_id: Union[int, str]): + """Bound method *include_chat* of :obj:`~pyrogram.types.Folder`. + + Use as a shortcut for: + + .. code-block:: python + + await client.update_folder( + folder_id=123456789, + included_chats=[chat_id], + excluded_chats=[...], + pinned_chats=[...] + ) + + Example: + .. code-block:: python + + await folder.include_chat(chat_id) + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier for the target chat or username of the target user/channel/supergroup + (in the format @username). + + Returns: + True on success. + """ + + return await self.update( + included_chats=[i.id for i in self.included_chats or []] + [chat_id], + excluded_chats=[i.id for i in self.excluded_chats or []], + pinned_chats=[i.id for i in self.pinned_chats or []] + ) + + async def exclude_chat(self, chat_id: Union[int, str]): + """Bound method *exclude_chat* of :obj:`~pyrogram.types.Folder`. + + Use as a shortcut for: + + .. code-block:: python + + await client.update_folder( + folder_id=123456789, + included_chats=[...], + excluded_chats=[chat_id], + pinned_chats=[...] + ) + + Example: + .. code-block:: python + + await folder.exclude_chat(chat_id) + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier for the target chat or username of the target user/channel/supergroup + (in the format @username). + + Returns: + True on success. + """ + + return await self.update( + included_chats=[i.id for i in self.included_chats or []], + excluded_chats=[i.id for i in self.excluded_chats or []] + [chat_id], + pinned_chats=[i.id for i in self.pinned_chats or []], + ) + + async def update_color(self, color: "enums.FolderColor"): + """Bound method *update_color* of :obj:`~pyrogram.types.Folder`. + + Use as a shortcut for: + + .. code-block:: python + + await client.update_folder( + folder_id=123456789, + included_chats=[chat_id], + excluded_chats=[chat_id], + pinned_chats=[...], + color=color + ) + + Example: + .. code-block:: python + + await folder.update_color(enums.FolderColor.RED) + + Parameters: + color (:obj:`~pyrogram.enums.FolderColor`, *optional*): + Color type. + Pass :obj:`~pyrogram.enums.FolderColor` to set folder color. + + Returns: + True on success. + """ + + return await self.update( + color=color + ) + + async def pin_chat(self, chat_id: Union[int, str]): + """Bound method *pin_chat* of :obj:`~pyrogram.types.Folder`. + + Use as a shortcut for: + + .. code-block:: python + + await client.update_folder( + folder_id=123456789, + included_chats=[chat_id], + excluded_chats=[chat_id], + pinned_chats=[...] + ) + + Example: + .. code-block:: python + + await folder.pin_chat(chat_id) + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier for the target chat or username of the target user/channel/supergroup + (in the format @username). + + Returns: + True on success. + """ + + return await self.update( + included_chats=[i.id for i in self.included_chats or []] + [chat_id], + excluded_chats=[i.id for i in self.excluded_chats or []], + pinned_chats=[i.id for i in self.pinned_chats or []] + [chat_id] + ) + + async def remove_chat(self, chat_id: Union[int, str]): + """Bound method *remove_chat* of :obj:`~pyrogram.types.Folder`. + + Remove chat from included, excluded and pinned chats. + + Use as a shortcut for: + + .. code-block:: python + + await client.update_folder( + folder_id=123456789, + included_chats=[...], + excluded_chats=[...], + pinned_chats=[...] + ) + + Example: + .. code-block:: python + + await folder.remove_chat(chat_id) + + Parameters: + chat_id (``int`` | ``str``): + Unique identifier for the target chat or username of the target user/channel/supergroup + (in the format @username). + + Returns: + True on success. + """ + peer = await self._client.resolve_peer(chat_id) + peer_id = utils.get_peer_id(peer) + + return await self.update( + included_chats=[i.id for i in self.included_chats or [] if peer_id != i.id], + excluded_chats=[i.id for i in self.excluded_chats or [] if peer_id != i.id], + pinned_chats=[i.id for i in self.pinned_chats or [] if peer_id != i.id] + ) + + async def export_link(self): + """Bound method *export_link* of :obj:`~pyrogram.types.Folder`. + + Use as a shortcut for: + + .. code-block:: python + + await client.export_folder_link(123456789) + + Example: + .. code-block:: python + + await folder.export_link() + + Returns: + ``str``: On success, a link to the folder as string is returned. + """ + + return await self._client.export_folder_link( + folder_id=self.id + )