mirror of
				https://github.com/LonamiWebs/Telethon.git
				synced 2025-10-30 23:47:33 +03:00 
			
		
		
		
	Expose MtProtoSender.is_connected() and use it on .connect()
This commit is contained in:
		
							parent
							
								
									05a8723d36
								
							
						
					
					
						commit
						58fe39f060
					
				|  | @ -103,15 +103,8 @@ class TelegramBareClient: | ||||||
|            If 'exported_auth' is not None, it will be used instead to |            If 'exported_auth' is not None, it will be used instead to | ||||||
|            determine the authorization key for the current session. |            determine the authorization key for the current session. | ||||||
|         """ |         """ | ||||||
|         if self._sender and self._sender.is_connected(): |         if self.is_connected(): | ||||||
|             # Try sending a ping to make sure we're connected already |             return True | ||||||
|             # TODO Maybe there's a better way to check this |  | ||||||
|             try: |  | ||||||
|                 self(PingRequest(utils.generate_random_long())) |  | ||||||
|                 return True |  | ||||||
|             except: |  | ||||||
|                 # If ping failed, ensure we're disconnected first |  | ||||||
|                 self.disconnect() |  | ||||||
| 
 | 
 | ||||||
|         connection = Connection( |         connection = Connection( | ||||||
|             self.session.server_address, self.session.port, |             self.session.server_address, self.session.port, | ||||||
|  | @ -168,6 +161,9 @@ class TelegramBareClient: | ||||||
|             ) |             ) | ||||||
|             return False |             return False | ||||||
| 
 | 
 | ||||||
|  |     def is_connected(self): | ||||||
|  |         return self._sender is not None and self._sender.is_connected() | ||||||
|  | 
 | ||||||
|     def _init_connection(self, query=None): |     def _init_connection(self, query=None): | ||||||
|         result = self(InvokeWithLayerRequest(LAYER, InitConnectionRequest( |         result = self(InvokeWithLayerRequest(LAYER, InitConnectionRequest( | ||||||
|             api_id=self.api_id, |             api_id=self.api_id, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user