mirror of
				https://github.com/LonamiWebs/Telethon.git
				synced 2025-10-30 23:47:33 +03:00 
			
		
		
		
	Fix saving of update state
This commit is contained in:
		
							parent
							
								
									0dff21a80f
								
							
						
					
					
						commit
						3c7f53802f
					
				|  | @ -198,7 +198,7 @@ class MessageBox: | ||||||
|         return dict( |         return dict( | ||||||
|             pts=self.map[ENTRY_ACCOUNT].pts if ENTRY_ACCOUNT in self.map else NO_SEQ, |             pts=self.map[ENTRY_ACCOUNT].pts if ENTRY_ACCOUNT in self.map else NO_SEQ, | ||||||
|             qts=self.map[ENTRY_SECRET].pts if ENTRY_SECRET in self.map else NO_SEQ, |             qts=self.map[ENTRY_SECRET].pts if ENTRY_SECRET in self.map else NO_SEQ, | ||||||
|             date=int(self.date.timestamp()), |             date=self.date, | ||||||
|             seq=self.seq, |             seq=self.seq, | ||||||
|         ), {id: state.pts for id, state in self.map.items() if isinstance(id, int)} |         ), {id: state.pts for id, state in self.map.items() if isinstance(id, int)} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -6,6 +6,7 @@ import logging | ||||||
| import platform | import platform | ||||||
| import time | import time | ||||||
| import typing | import typing | ||||||
|  | import datetime | ||||||
| 
 | 
 | ||||||
| from .. import version, helpers, __name__ as __base_name__ | from .. import version, helpers, __name__ as __base_name__ | ||||||
| from ..crypto import rsa | from ..crypto import rsa | ||||||
|  | @ -659,16 +660,17 @@ class TelegramBaseClient(abc.ABC): | ||||||
|             await asyncio.wait(self._event_handler_tasks) |             await asyncio.wait(self._event_handler_tasks) | ||||||
|             self._event_handler_tasks.clear() |             self._event_handler_tasks.clear() | ||||||
| 
 | 
 | ||||||
|         entities = self._entity_cache.get_all_entities() |         entities = self._mb_entity_cache.get_all_entities() | ||||||
| 
 | 
 | ||||||
|         # Piggy-back on an arbitrary TL type with users and chats so the session can understand to read the entities. |         # Piggy-back on an arbitrary TL type with users and chats so the session can understand to read the entities. | ||||||
|         # It doesn't matter if we put users in the list of chats. |         # It doesn't matter if we put users in the list of chats. | ||||||
|         await self.session.process_entities(types.contacts.ResolvedPeer(None, [e._as_input_peer() for e in entities], [])) |         await self.session.process_entities(types.contacts.ResolvedPeer(None, [e._as_input_peer() for e in entities], [])) | ||||||
| 
 | 
 | ||||||
|         session_state, channel_states = self._message_box.session_state() |         ss, cs = self._message_box.session_state() | ||||||
|         await self.session.set_update_state(0, types.updates.State(ss.pts, ss.qts, ss.date, ss.seq, unread_count=0)) |         await self.session.set_update_state(0, types.updates.State(**ss, unread_count=0)) | ||||||
|         for channel_id, pts in channel_states.items(): |         now = datetime.datetime.now()  # any datetime works; channels don't need it | ||||||
|             await self.session.set_update_state(channel_id, types.updates.State(pts, 0, None, 0, unread_count=0)) |         for channel_id, pts in cs.items(): | ||||||
|  |             await self.session.set_update_state(channel_id, types.updates.State(pts, 0, now, 0, unread_count=0)) | ||||||
| 
 | 
 | ||||||
|         await self.session.close() |         await self.session.close() | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user