Esempio n. 1
0
    def archive_chats(
        self,
        chat_ids: Union[int, str, List[Union[int, str]]],
    ) -> bool:
        """Archive one or more chats.

        Parameters:
            chat_ids (``int`` | ``str`` | List[``int``, ``str``]):
                Unique identifier (int) or username (str) of the target chat.
                You can also pass a list of ids (int) or usernames (str).

        Returns:
            ``bool``: On success, True is returned.

        Example:
            .. code-block:: python

                # Archive chat
                app.archive_chats(chat_id)

                # Archive multiple chats at once
                app.archive_chats([chat_id1, chat_id2, chat_id3])
        """

        if not isinstance(chat_ids, list):
            chat_ids = [chat_ids]

        self.send(
            functions.folders.EditPeerFolders(folder_peers=[
                types.InputFolderPeer(peer=self.resolve_peer(chat),
                                      folder_id=1) for chat in chat_ids
            ]))

        return True
Esempio n. 2
0
    def unarchive_chats(
        self,
        chat_ids: Union[int, str, List[Union[int, str]]],
    ) -> bool:
        """Unarchive one or more chats.

        Parameters:
            chat_ids (``int`` | ``str`` | List[``int``, ``str``]):
                Unique identifier (int) or username (str) of the target chat.
                You can also pass a list of ids (int) or usernames (str).

        Returns:
            ``bool``: On success, True is returned.

        Raises:
            RPCError: In case of a Telegram RPC error.
        """

        if not isinstance(chat_ids, list):
            chat_ids = [chat_ids]

        self.send(
            functions.folders.EditPeerFolders(
                folder_peers=[
                    types.InputFolderPeer(
                        peer=self.resolve_peer(chat),
                        folder_id=0
                    ) for chat in chat_ids
                ]
            )
        )

        return True