3131
3232
3333async def get_session (client : "pyrogram.Client" , dc_id : int ) -> Session :
34- if dc_id == await client .storage .dc_id () :
34+ if dc_id == client .session .dc_id :
3535 return client .session
3636
37- async with client .media_sessions_lock :
38- if client .media_sessions .get (dc_id ):
39- return client .media_sessions [dc_id ]
37+ async with client .sessions_lock :
38+ if client .sessions .get (dc_id ):
39+ return client .sessions [dc_id ]
4040
41- session = client .media_sessions [dc_id ] = Session (
41+ session = client .sessions [dc_id ] = Session (
4242 client ,
4343 dc_id ,
4444 await Auth (client , dc_id , await client .storage .test_mode ()).create (),
@@ -66,20 +66,8 @@ async def recreate(self):
6666 )
6767 )
6868
69- if isinstance (self .r , raw .types .auth .LoginTokenMigrateTo ):
70- await self .client .storage .dc_id (self .r .dc_id )
71- self .client .session = await get_session (self .client , self .r .dc_id )
72- self .r = await self .client .invoke (
73- raw .functions .auth .ImportLoginToken (token = self .r .token )
74- )
75-
76- return self .r
77-
7869 async def wait (self , timeout : float = None ) -> Optional ["types.User" ]:
7970 if timeout is None :
80- if not self .r :
81- raise asyncio .TimeoutError
82-
8371 timeout = self .r .expires - int (datetime .datetime .now ().timestamp ())
8472
8573 event = asyncio .Event ()
@@ -102,17 +90,31 @@ async def raw_handler(client, update, users, chats):
10290 self .client .remove_handler (* handler )
10391 await self .client .dispatcher .stop (clear = False )
10492
105- await self .recreate ()
93+ r = await self .client .invoke (
94+ raw .functions .auth .ExportLoginToken (
95+ api_id = self .client .api_id ,
96+ api_hash = self .client .api_hash ,
97+ except_ids = self .except_ids ,
98+ )
99+ )
100+
101+ if isinstance (r , raw .types .auth .LoginTokenMigrateTo ):
102+ await self .client .storage .dc_id (r .dc_id )
103+ self .client .session = await get_session (self .client , r .dc_id )
104+
105+ r = await self .client .invoke (
106+ raw .functions .auth .ImportLoginToken (token = r .token )
107+ )
106108
107- if isinstance (self . r , raw .types .auth .LoginTokenSuccess ):
108- user = types .User ._parse (self .client , self . r .authorization .user )
109+ if isinstance (r , raw .types .auth .LoginTokenSuccess ):
110+ user = types .User ._parse (self .client , r .authorization .user )
109111
110112 await self .client .storage .user_id (user .id )
111113 await self .client .storage .is_bot (False )
112114
113115 return user
114116
115- raise TypeError ("Unexpected login token response: {}" .format (self . r ))
117+ raise TypeError ("Unexpected login token response: {}" .format (r ))
116118
117119 @property
118120 def url (self ) -> str :
0 commit comments