|
| 1 | +# Pyrogram - Telegram MTProto API Client Library for Python |
| 2 | +# Copyright (C) 2017-2019 Dan Tès <https://github.com/delivrance> |
| 3 | +# |
| 4 | +# This file is part of Pyrogram. |
| 5 | +# |
| 6 | +# Pyrogram is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU Lesser General Public License as published |
| 8 | +# by the Free Software Foundation, either version 3 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# Pyrogram is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU Lesser General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU Lesser General Public License |
| 17 | +# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +from typing import Union |
| 20 | + |
| 21 | +import pyrogram |
| 22 | +from pyrogram.api import functions, types |
| 23 | +from ...ext import BaseClient |
| 24 | + |
| 25 | + |
| 26 | +class GetCommonChats(BaseClient): |
| 27 | + def get_common_chats(self, user_id: Union[int, str]) -> list: |
| 28 | + """Get the common chats you have with a user. |
| 29 | +
|
| 30 | + Parameters: |
| 31 | + user_id (``int`` | ``str``): |
| 32 | + Unique identifier (int) or username (str) of the target chat. |
| 33 | + For your personal cloud (Saved Messages) you can simply use "me" or "self". |
| 34 | + For a contact that exists in your Telegram address book you can use his phone number (str). |
| 35 | +
|
| 36 | + Returns: |
| 37 | + List of :obj:`Chat`: On success, a list of the common chats is returned. |
| 38 | + |
| 39 | + Raises: |
| 40 | + ValueError: If the user_id doesn't belong to a user. |
| 41 | +
|
| 42 | + Example: |
| 43 | + .. code-block:: python |
| 44 | +
|
| 45 | + common = app.get_common_chats("haskell") |
| 46 | + print(common) |
| 47 | + """ |
| 48 | + |
| 49 | + peer = self.resolve_peer(user_id) |
| 50 | + |
| 51 | + if isinstance(peer, types.InputPeerUser): |
| 52 | + r = self.send( |
| 53 | + functions.messages.GetCommonChats( |
| 54 | + user_id=peer, |
| 55 | + max_id=0, |
| 56 | + limit=100, |
| 57 | + ) |
| 58 | + ) |
| 59 | + |
| 60 | + return pyrogram.List([pyrogram.Chat._parse_chat(self, x) for x in r.chats]) |
| 61 | + |
| 62 | + raise ValueError('The user_id "{}" doesn\'t belong to a user'.format(user_id)) |
0 commit comments