1616# You should have received a copy of the GNU Lesser General Public License
1717# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818
19- from typing import Union
19+ from typing import Union , List
2020
2121import pyrogram
2222from pyrogram .api import types
2323from .chat_permissions import ChatPermissions
2424from .chat_photo import ChatPhoto
25+ from .restriction import Restriction
2526from ..object import Object
2627from ...ext import utils
2728
@@ -87,8 +88,8 @@ class Chat(Object):
8788 members_count (``int``, *optional*):
8889 Chat members count, for groups, supergroups and channels only.
8990
90- restriction_reason (``str` `, *optional*):
91- The reason why this chat might be unavailable to some users.
91+ restrictions (List of :obj:`Restriction `, *optional*):
92+ The list of reasons why this chat might be unavailable to some users.
9293 This field is available only in case *is_restricted* is True.
9394
9495 permissions (:obj:`ChatPermissions` *optional*):
@@ -120,7 +121,7 @@ def __init__(
120121 sticker_set_name : str = None ,
121122 can_set_sticker_set : bool = None ,
122123 members_count : int = None ,
123- restriction_reason : str = None ,
124+ restrictions : List [ Restriction ] = None ,
124125 permissions : "pyrogram.ChatPermissions" = None ,
125126 distance : int = None
126127 ):
@@ -143,7 +144,7 @@ def __init__(
143144 self .sticker_set_name = sticker_set_name
144145 self .can_set_sticker_set = can_set_sticker_set
145146 self .members_count = members_count
146- self .restriction_reason = restriction_reason
147+ self .restrictions = restrictions
147148 self .permissions = permissions
148149 self .distance = distance
149150
@@ -162,7 +163,7 @@ def _parse_user_chat(client, user: types.User) -> "Chat":
162163 first_name = user .first_name ,
163164 last_name = user .last_name ,
164165 photo = ChatPhoto ._parse (client , user .photo , peer_id ),
165- restriction_reason = user .restriction_reason ,
166+ restrictions = pyrogram . List ([ Restriction . _parse ( r ) for r in user .restriction_reason ]) or None ,
166167 client = client
167168 )
168169
@@ -183,6 +184,7 @@ def _parse_chat_chat(client, chat: types.Chat) -> "Chat":
183184 @staticmethod
184185 def _parse_channel_chat (client , channel : types .Channel ) -> "Chat" :
185186 peer_id = utils .get_channel_id (channel .id )
187+ restriction_reason = getattr (channel , "restriction_reason" , [])
186188
187189 return Chat (
188190 id = peer_id ,
@@ -193,7 +195,7 @@ def _parse_channel_chat(client, channel: types.Channel) -> "Chat":
193195 title = channel .title ,
194196 username = getattr (channel , "username" , None ),
195197 photo = ChatPhoto ._parse (client , getattr (channel , "photo" , None ), peer_id ),
196- restriction_reason = getattr ( channel , " restriction_reason" , None ) ,
198+ restrictions = pyrogram . List ([ Restriction . _parse ( r ) for r in restriction_reason ]) or None ,
197199 permissions = ChatPermissions ._parse (getattr (channel , "default_banned_rights" , None )),
198200 members_count = getattr (channel , "participants_count" , None ),
199201 client = client
0 commit comments